Commit a95b06fc authored by Damien George's avatar Damien George
Browse files

drivers/onewire: Fix ds18x20.read_temp so it works when no rom given.

parent 92d4b51a
......@@ -7,14 +7,13 @@ temperature sensors. It supports multiple devices on the same 1-wire bus.
The following example assumes the ground of your DS18x20 is connected to
Y11, vcc is connected to Y9 and the data pin is connected to Y10.
>>> gnd = Pin('Y11')
>>> gnd.init(Pin.OUT_PP)
>>> from pyb import Pin
>>> gnd = Pin('Y11', Pin.OUT_PP)
>>> gnd.low()
>>> vcc = Pin('Y9')
>>> vcc.init(Pin.OUT_PP)
>>> vcc = Pin('Y9', Pin.OUT_PP)
>>> vcc.high()
>>> from ds18x20 import DS18X20
>>> d = DS18X20(Pin('Y10'))
Call read_temps to read all sensors:
......@@ -47,27 +46,22 @@ class DS18X20(object):
# correct # first byte in their rom for a DS18x20 device.
self.roms = [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28]
def _select_rom(self, rom):
if rom:
def read_temp(self, rom=None):
Read and return the temperature of one DS18x20 device.
Pass the 8-byte bytes object with the ROM of the specific device you want to read.
If only one DS18x20 device is attached to the bus you may omit the rom parameter.
rom = rom or self.roms[0]
ow = self.ow
ow.write_byte(0x44) # Convert Temp
while True:
if ow.read_bit():
ow.write_byte(0xbe) # Read scratch
data = ow.read_bytes(9)
return self.convert_temp(rom[0], data)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment