Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pi pico reading ibuttons

Status
Not open for further replies.

whiz115

Member
hi

i would like to modify this micropython code so it can read the DS1920-F5 thermometer

Code:
import machine, onewire, ds18x20, time
 
ds_pin = machine.Pin(16)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
 
roms = ds_sensor.scan()
print('Found a ds18x20 device')
 
while True:
  ds_sensor.convert_temp()
  time.sleep_ms(750)
  for rom in roms:
    print(ds_sensor.read_temp(rom))
  time.sleep(2)

can you help me out?

here's the datasheet
 
The DS1920 has the same family code (0x10) as the DS1820 so it should work as is.

Mike.
 
The DS1920 has the same family code (0x10) as the DS1820 so it should work as is.

Mike.

great! but do you think it should be alright at 3.3V? and there's no need to be connected
to a 5V device?

also the wiring how it should be done? the above example code was about a DS18B20 which
uses 3 pins (VCC, GND, GPIO16) while the ibutton needs GND and DATA and it says something
about parasitic powering, is it enough connecting GND and GPIO16 to it?
 
Last edited:
The 1820 can also use parasitic power, try it and see. It's normal for one wire devices. It just needs a longer time between transmissions, check the library, see what it's doing. Post a link to it and I may be able to explain but I've never used python.

Mike.
 
Running the code with the ibutton connected only prints 'Found a ds18x20 device'

if i disconnect it it prints OneWireError: with the lines of code concerning the error message.
 
This library appears to support either 18x20 or 1920 devices, depending which option you enable in the header file.

Note that the device IDs / family codes are different; 18x20 is 0x28, 1920 is 0x10, so different settings would likely be needed for the two different devices - which explains the header options.
 
This library appears to support either 18x20 or 1920 devices, depending which option you enable in the header file.

Note that the device IDs / family codes are different; 18x20 is 0x28, 1920 is 0x10, so different settings would likely be needed for the two different devices - which explains the header options.

hi, thanks for the reply

problem is..this is OneWire library for arduino while i'm on pico and micropython.

what can i modify on the code i posted earlier so i can make it work with a DS1920-F5
thermometer? @Pommie said it should work, but i can only notice some short of
communication between the ibutton and the pico but there's no temperature output.
 
hi, thanks for the reply

problem is..this is OneWire library for arduino while i'm on pico and micropython.

what can i modify on the code i posted earlier so i can make it work with a DS1920-F5
thermometer? @Pommie said it should work, but i can only notice some short of
communication between the ibutton and the pico but there's no temperature output.

You need to port it over, it's usually far easier to port Arduino C++ to other languages, than to write your own from scratch - mostly because datasheets tend to be fairly vague, and often wrong.
 
Do you know if the code in post #1 actually works? Looking at the library, you need to call start_conversion(), wait (at least) 750mS and then read the scratchpad. The DS1920 has the same device ID (0x10) as a DS18S20. The library should just work as there's no way to know if a DS1920 or a DS18S20 is connected. I suspect the code in the first post is incomplete and a further search might be more successful.

Mike.
Edit, the code on this page looks more correct.
Edit, I see that is the same code as post #1. Check your hardware (4k7 pullup etc.) against that page.
 
Last edited:
i think it's alright! the pullup resistor solved the problem i'm using 3.2k resistor for the 3.3V which i
had spare, i'm reading the current temperature.. right? though 28c seems too high for room
temperature at this period,

how can i make it read and store temperatures so i can read them later?

1648664728658.png
 
You could store the 8 byte scratchpad readings (or just the two byte temperature) and interpret them as needed.
I suggest you read at least one scratchpad area and convert the temperature by hand to try and work out why it's wrong - unless it really is 28°C and you're sweating a lot!!!! Note, once converted, you can read the (unchanged) temperature as many times as you like without the 750mS delay.

I assume something like,
print(ds_sensor.read_temp(roms[0]))
will read the first sensor.
Note, first as in lowest rom number - not first in line.


Mike.
 
You could store the 8 byte scratchpad readings (or just the two byte temperature) and interpret them as needed.
I suggest you read at least one scratchpad area and convert the temperature by hand to try and work out why it's wrong - unless it really is 28°C and you're sweating a lot!!!! Note, once converted, you can read the (unchanged) temperature as many times as you like without the 750mS delay.

I assume something like,
print(ds_sensor.read_temp(roms[0]))
will read the first sensor.
Note, first as in lowest rom number - not first in line.


Mike.

i think the readings i'm getting it's from my hand touching the metal case,
do you think it could somehow conveniently work as a standalone device storing the values
without being permanently connected to the Pico?
 
do you think it could somehow conveniently work as a standalone device storing the values
without being permanently connected to the Pico?
They (or it) wont. However, they do contain 2 bytes of EEPROM to hold the alarm temperature. You could read the scratch pad, copy bytes 0 and 1 to bytes 2 and 3, write back the scratchpad and issue a Copy Scratchpad command to store it in the EEPROM. This would require some programming by you. You might find an example that writes the alarm values.

Mike.
 
They (or it) wont.

they should contain a battery inside to work autonomously.. something like a BR1225
although the datasheet says nothing about it.

i know the pico has already a thermometer built-in, but ibutton interests me if it can
go standalone.
 
To do what you want would need some kind of temperature logger. The OW devices are simple sensors that can only be commanded by a micro.

Mike.
 
To do what you want would need some kind of temperature logger. The OW devices are simple sensors that can only be commanded by a micro.

Mike.

I thought that scratchpad could log a value, which could transfered to internal memory and then retrieve them later.. Whats the point of these tiny devices in a metal case if they need to be constantly connected somewhere?


Features and Benefits:


• 1-wire serial interface
• Self-aligns with cup-shaped probes
• Can be affixed with self-adhesive backing, latched by it's flange and locked with a ring
• Password protection for memory and control functions
• Stores 8KB of data-log memory




if it has to be constantly wired,then there are the DS18x20 sensors that look like a transistor.. or some other OneWire types that look like a probe..

is it certain it should be wired all the time? so then pico is more suitable since it can log temperatures non stop to a file..
 
Last edited:
any opinion on this?

[edit]
reading again the datasheet i guess the above description incorrectly refers to the DS1920
which it isn't data logger as the DS1922L right??
 
Last edited:
The 1922L is indeed a data logger but has a different family code (0x41) to the others so the above library will need modifying.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top