• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Multi ds18x20

Q&A Forum › Category: ESP32 › Multi ds18x20
0 Vote Up Vote Down
self.raymond asked 11 months ago
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

5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 11 months ago

Hi Ray.
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?
Regards, Sara

0 Vote Up Vote Down
self.raymond answered 11 months ago

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
Ray
 

0 Vote Up Vote Down
Sara Santos Staff answered 11 months ago

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[0] 
temperature2 = temperatures[1]

I hope this helps.
Regards, Sara

0 Vote Up Vote Down
self.raymond answered 11 months ago

To simple..  Why was I thinking the bytearray was the key??  Wow thank you again for your help. 

0 Vote Up Vote Down
Sara Santos Staff answered 11 months ago

You’re welcome.
I’ll mark this question as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Download Build Web Servers with ESP32 and ESP8266 (2nd Edition) February 8, 2021
  • [eBook Released] Build Web Servers with ESP32 and ESP8266 (version 1.0) October 27, 2020

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2021 · RandomNerdTutorials.com · All Rights Reserved