robert-hh / Onewire_DS18X20

Classes for driving the DS18x20 sensor with the onewire protocol for Pycom MicroPython
12 stars 6 forks source link

Micropython Onewire VSCode error on constants CMD_SEARCHROM, CMD_MATCHROM and PULLUP_ON #17

Closed kpg141260 closed 1 year ago

kpg141260 commented 1 year ago

Hi,

after adding the Onewire library to my Micropython project on a Raspberry PICO I got error messages that the constants defined in the class OneWire cannot be resolved when used within the class: class OneWire: CMD_SEARCHROM = const(0xf0) CMD_READROM = const(0x33) CMD_MATCHROM = const(0x55) CMD_SKIPROM = const(0xcc) PULLUP_ON = const(1) ...

Possible solution to this is:

A) define the constants globally outside of the class: CMD_SEARCHROM = const(0xf0) CMD_READROM = const(0x33) CMD_MATCHROM = const(0x55) CMD_SKIPROM = const(0xcc) PULLUP_ON = const(1) class OneWire: ....

or B) when referencing the constants use: self.CMD_SEARCHROM and so on.

If that could be rectified in the source code on GitHub, that would potentially safe others some time.

Thanks, Pete

kpg141260 commented 1 year ago

Furthermore, in the OneWire lib you need to import const from Micropython, otherwise it will not know that type.

robert-hh commented 1 year ago

The file onewire.py is not needed for genuine MicroPython devices. I created it for being used with the Pycom variant of MicroPython. For genuine MicroPython the version in micropython-lib/micropython/drivers/bus/onewire is used, and that one shoud be installed by default on a RPi Pico. The same applies to the DS18X20 driver located at micropython-lib/micropython/drivers/sensor/ds18x20.