lsm303d problem connect to i2c adresses.

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

lsm303d problem connect to i2c adresses.

Post by prem111 » Tue Jul 21, 2020 12:26 pm

Hi, im trying use this driver to connect lsm303d:

https://github.com/kamikaze/pyboard-exa ... /lsm303.py

im have error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 68, in <module>
  File "<stdin>", line 31, in __init__
OSError: [Errno 19] ENODEV


i2c scan:

Code: Select all

>>> i2c.scan()
[29]

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: lsm303d problem connect to i2c adresses.

Post by pythoncoder » Wed Jul 22, 2020 9:09 am

Hopefully the author of the driver will respond because I can't square the driver's I2C addresses with the device datasheet.

Your scanned value of 29 is 0x1d which corresponds with the datasheet if the board has the SD0/SA0 pin set high. The driver's ADDRESS_MAG seems to assume that the pin is low. But the driver also has a different ADDRESS_ACCEL which doesn't seem to conform with the datasheet and isn't borne out by your scan. The datasheet and your scan both indicate that the chip has one I2C address only.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: lsm303d problem connect to i2c adresses.

Post by pythoncoder » Wed Jul 22, 2020 9:17 am

In the absence of a response from the author, you could try replacing lines 5 and 6 with

Code: Select all

    ADDRESS_ACCEL = 29
    ADDRESS_MAG = 29
and see what happens.
Peter Hinch
Index to my micropython libraries.

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: lsm303d problem connect to i2c adresses.

Post by prem111 » Thu Jul 23, 2020 9:02 am

Then it only sees the accelerometer data - the magnetometer does not.

Code: Select all

lsm303 = LSM303D(i2c)
print(lsm303.read())

((20, -204, 1069), (0, 0, 0))

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: lsm303d problem connect to i2c adresses.

Post by pythoncoder » Thu Jul 23, 2020 3:50 pm

In which case there may be other bugs in the driver. Lacking an lsm303d I can't debug this. To get a response from the author you might try raising an issue on GitHub.

Failing a response from the author, your options are to figure it out yourself from the datasheet or to use an IMU with a supported driver. I have written drivers for MPU6050, MPU6150, MPU6250 and BNO055 available here where you will also find drivers for BMX055 and LSM9DS0 (written by Sebastian Plamauer and @xix-xeaon respectively).
Peter Hinch
Index to my micropython libraries.

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: lsm303d problem connect to i2c adresses.

Post by prem111 » Thu Jul 23, 2020 5:48 pm

Thanks for reply.

Post Reply