mchobby / esp8266-upy

MicroPython Cross-platform Drivers - collection of code, wiring and sample for various breakout boards - Works with ESP8266, Pyboard, PYB405, Wemos, etc))
53 stars 30 forks source link

LSM303 library throws error on ESP8266 #5

Closed gregwa1953 closed 2 years ago

gregwa1953 commented 2 years ago

I'm using Thonny as my IDE. ESP8266 running MicroPython v1.18 on 2022-01-17; ESP module with ESP8266 Trying to run either of the three example programs all give the same result...

%Run -c $EDITOR_CONTENT Traceback (most recent call last): File "", line 20, in File "lsm303.py", line 250, in init File "lsm303.py", line 386, in _write_u8 OSError: [Errno 19] ENODEV

Any suggestions?

mchobby commented 2 years ago

How do you creates your I2C bus on the ESP8266 ? Is it defined accordingly to the wiring ?

What is the I2C address declared on by the board manufacturer ? The library do use 0x1D (29) as default address. You can try to make an i2c_instance.scan() to check for the I2C devices used on the bus.

gregwa1953 commented 2 years ago

The wiring of the esp8266 is scl=Pin(5), sda=Pin(4)

The I2C addresses of the board are 0x19 and 0x1e

I've also tried this library on a Raspberry Pi Pico (using Micropython 1.17) and is fails at the same place.

mchobby commented 2 years ago

Hi, Your board is certainly configured to use the 0x1E address instead of the default one (0x1D). I just uploaded a new version of the lib accepting the parameter address in the constructor (behind the i2c reference). Just write lsm= LSM303( i2c, address=0x1E ) instead of lsm = LSM303( i2c ) ... it should work better.

gregwa1953 commented 2 years ago

Thank you very much.

I'll give that a shot.