pycom / pycom-libraries

MicroPython libraries and examples that work out of the box on Pycom's IoT modules
330 stars 378 forks source link

OneWire empty rom list issue #94

Open DanielIbaseta opened 5 years ago

DanielIbaseta commented 5 years ago

I am using a series of DS18B20 with a Pycom GPy, using this library with MicroPython 1.10. I need to create a OneWire connection with each one of them for identification purpose, not being able to control which sensor is connected in which Pin. Anyhow, the problem I found is that when the DS18X20 object is created, it only makes one scan(). It is sufficient most of the times, but sometimes it just don't find the attached device. So I suggest to recursively look for the attached device, maybe with a timeout, in order to not make an "start_conversion()" or "read_temp_async()" with an empty rom list, which breaks the program as it tries to access roms[0].

I managed to solve it locally editing the DS18X20 constructor like this:

def __init__(self, onewire):
        self.ow = onewire
        self.roms = []
        self.fp = True

        while self.roms == []:
            print("scanning for roms...")
            self.roms = [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28]

        try:
            1/1
        except TypeError:
            self.fp = False # floatingpoint not supported