i am playing a bit with micropython and a ds18b20 i use the following short program:
Code: Select all
import time
import onewire, ds18x20
from machine import Pin
# the device is on B12
dat = Pin('B12')
# create the onewire object
ds = ds18x20.DS18X20(onewire.OneWire(dat))
roms = ds.scan()
print('found devices:', roms)
ds.convert_temp()
time.sleep_ms(750)
rom_code = roms[0]
print(ds.read_temp(rom_code), end=' ')
print()
print (rom_code)
for i in range(8):
print (hex(rom_code[i]) , end=' ')
The output of the program is:
found devices: [bytearray(b'(\x82\x9b\x94\x05\x00\x00\x87')]
19.0
bytearray(b'(\x82\x9b\x94\x05\x00\x00\x87')
0x28 0x82 0x9b 0x94 0x5 0x0 0x0 0x87
I am using MicroPython v1.14-82-gcdaec0dca on 2021-02-27; WeAct F411CE with STM32F411CE
Regards
Wim