import machine import onewire import ds18x20 import time ds_pin = machine.Pin(4) ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin)) roms = ds_sensor.scan() print('Found DS devices: ', roms) def read_ds_sensor(): roms = ds_sensor.scan() #print('Found DS devices: ', roms) print('Temperatures: ') ds_sensor.convert_temp() time.sleep(1) for rom in roms: temp = ds_sensor.read_temp(rom) if isinstance(temp, float): temp = temp * (9/5) + 32.0 print(temp, end=' ') print('Valid temperature')
I have been trying to add sensor to my project. bytearray(b'(l\x05V\x08\x00\x00\x86′) and bytearray(b'(e\xedU\x08\x00\x00|’). I have look in the Micropython esp32 and esp8266 pdf book. Any help would be greatly appreciate. Not a lot of information for multiple sensors that I can find for the Micropython. Thank You
That code gets the temperature for multiple sensors.
What exactly do you want to do? Do you want to get each sensor reading in a variable to use later?
Thank you Sara for your help. Being able to read each sensor and print the temp would be very helpful. Temp 1 print Temp 2 print Temp 3 print. This way I can compare the temp range and turn on a relay.
The pdf Micropython esp8266 and esp32 cover using one ds18b20 rather well but not using more that 1.
Again thank you for your help
Hi Ray. I think something like this should work:
temperatures =  ds_sensor.convert_temp() time.sleep_ms(750) for rom in roms: print(rom) print(ds_sensor.read_temp(rom)) temperatures.append(ds_sensor.read_temp(rom)) time.sleep(5) temperature1 = temperatures temperature2 = temperatures
I hope this helps.
To simple.. Why was I thinking the bytearray was the key?? Wow thank you again for your help.