I downloaded the latest version of CircuitPython on my Adafruit Grand Central board. (filename is adafruit-circuitpython-grandcentral_m4_express-en_US-4.0.0-alpha.5.uf2)
Followed the instruction (https://learn.adafruit.com/adafruit-lsm ... cuitpython) to connect the LSM9DS1 9-dof IMU to the board using I2C. Copied and pasted the example code for testing. The result was:
Traceback (most recent call last):
File "code.py", line 10, in <module>
ReloadException:
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 10, in <module>
File "adafruit_lsm9ds1.py", line 369, in __init__
File "adafruit_bus_device/i2c_device.py", line 78, in __init__
File "adafruit_bus_device/i2c_device.py", line 76, in __init__
ValueError: No I2C device at address: 1e
I tried to google but found nothing helpful. Could anyone help me solve this problem? Thanks!
Adafruit Grand Central & LSM9DS1 I2C problem
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- DimitriWu
- Posts: 2
- Joined: Fri Jan 04, 2019 4:43 pm
- jerryn
- Posts: 1890
- Joined: Sat Sep 14, 2013 9:05 am
Re: Adafruit Grand Central & LSM9DS1 I2C problem
FYI - I have reproduced this and opened an Issue in the CircuitPython Repository https://github.com/adafruit/circuitpython/issues/1456
- jerryn
- Posts: 1890
- Joined: Sat Sep 14, 2013 9:05 am
Re: Adafruit Grand Central & LSM9DS1 I2C problem
there appears to be some error in the CircuitPython pin mapping -- a workaround is to connect SCL to Pin D24 and SDA to Pin D25 (these are board.SCL1/board.SDA1 )
and modify the script to use SCL1/SDA1 as follows
and modify the script to use SCL1/SDA1 as follows
Code: Select all
# Simple demo of the LSM9DS1 accelerometer, magnetometer, gyroscope.
# Will print the acceleration, magnetometer, and gyroscope values every second.
import time
import board
import busio
import adafruit_lsm9ds1
# I2C connection:
i2c = busio.I2C(board.SCL1, board.SDA1)
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
#SPI connection:
# from digitalio import DigitalInOut, Direction
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# csag = DigitalInOut(board.D5)
# csag.direction = Direction.OUTPUT
# csag.value = True
# csm = DigitalInOut(board.D6)
# csm.direction = Direction.OUTPUT
# csm.value = True
# sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm)
# Main loop will read the acceleration, magnetometer, gyroscope, Temperature
# values every second and print them out.
while True:
# Read acceleration, magnetometer, gyroscope, temperature.
accel_x, accel_y, accel_z = sensor.acceleration
mag_x, mag_y, mag_z = sensor.magnetic
gyro_x, gyro_y, gyro_z = sensor.gyro
temp = sensor.temperature
# Print values.
print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(accel_x, accel_y, accel_z))
print('Magnetometer (gauss): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(mag_x, mag_y, mag_z))
print('Gyroscope (degrees/sec): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(gyro_x, gyro_y, gyro_z))
print('Temperature: {0:0.3f}C'.format(temp))
# Delay for a second.
time.sleep(1.0)
Code: Select all
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-alpha.5-120-g573c6d60b on 2019-01-11; Adafruit Grand Central M4 Express with samd51p20
>>>
>>> import lsm9ds1_simpletest
Acceleration (m/s^2): (-9.985,-0.147,0.961)
Magnetometer (gauss): (-0.247,0.245,0.139)
Gyroscope (degrees/sec): (-201.661,-193.629,225.899)
Temperature: 16.500C
Acceleration (m/s^2): (-10.138,-0.121,-0.377)
Magnetometer (gauss): (-0.245,0.241,0.148)
Gyroscope (degrees/sec): (2.354,-4.795,-0.857)
Temperature: 17.500C
Acceleration (m/s^2): (-10.114,0.001,-0.404)
Magnetometer (gauss): (-0.243,0.245,0.135)
Gyroscope (degrees/sec): (1.942,-4.445,-0.849)
Temperature: 17.500C
- DimitriWu
- Posts: 2
- Joined: Fri Jan 04, 2019 4:43 pm
Re: Adafruit Grand Central & LSM9DS1 I2C problem
jerryn wrote:there appears to be some error in the CircuitPython pin mapping -- a workaround is to connect SCL to Pin D24 and SDA to Pin D25 (these are board.SCL1/board.SDA1 )
and modify the script to use SCL1/SDA1 as followsCode: Select all
# Simple demo of the LSM9DS1 accelerometer, magnetometer, gyroscope. # Will print the acceleration, magnetometer, and gyroscope values every second. import time import board import busio import adafruit_lsm9ds1 # I2C connection: i2c = busio.I2C(board.SCL1, board.SDA1) sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c) #SPI connection: # from digitalio import DigitalInOut, Direction # spi = busio.SPI(board.SCK, board.MOSI, board.MISO) # csag = DigitalInOut(board.D5) # csag.direction = Direction.OUTPUT # csag.value = True # csm = DigitalInOut(board.D6) # csm.direction = Direction.OUTPUT # csm.value = True # sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm) # Main loop will read the acceleration, magnetometer, gyroscope, Temperature # values every second and print them out. while True: # Read acceleration, magnetometer, gyroscope, temperature. accel_x, accel_y, accel_z = sensor.acceleration mag_x, mag_y, mag_z = sensor.magnetic gyro_x, gyro_y, gyro_z = sensor.gyro temp = sensor.temperature # Print values. print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(accel_x, accel_y, accel_z)) print('Magnetometer (gauss): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(mag_x, mag_y, mag_z)) print('Gyroscope (degrees/sec): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(gyro_x, gyro_y, gyro_z)) print('Temperature: {0:0.3f}C'.format(temp)) # Delay for a second. time.sleep(1.0)
Code: Select all
Press any key to enter the REPL. Use CTRL-D to reload. Adafruit CircuitPython 4.0.0-alpha.5-120-g573c6d60b on 2019-01-11; Adafruit Grand Central M4 Express with samd51p20 >>> >>> import lsm9ds1_simpletest Acceleration (m/s^2): (-9.985,-0.147,0.961) Magnetometer (gauss): (-0.247,0.245,0.139) Gyroscope (degrees/sec): (-201.661,-193.629,225.899) Temperature: 16.500C Acceleration (m/s^2): (-10.138,-0.121,-0.377) Magnetometer (gauss): (-0.245,0.241,0.148) Gyroscope (degrees/sec): (2.354,-4.795,-0.857) Temperature: 17.500C Acceleration (m/s^2): (-10.114,0.001,-0.404) Magnetometer (gauss): (-0.243,0.245,0.135) Gyroscope (degrees/sec): (1.942,-4.445,-0.849) Temperature: 17.500C
Thank you so much it worked!
- jerryn
- Posts: 1890
- Joined: Sat Sep 14, 2013 9:05 am
Re: Adafruit Grand Central & LSM9DS1 I2C problem
FYI - The issue has been resolved and the next CrcuitPython release will work with the normal SCL/SDA pins.
- bebo
- Posts: 96
- Joined: Tue Mar 29, 2011 8:22 am
Re: Adafruit Grand Central & LSM9DS1 I2C problem
As of 4.0.0-beta.3 the issue is still present.
- jerryn
- Posts: 1890
- Joined: Sat Sep 14, 2013 9:05 am
Re: Adafruit Grand Central & LSM9DS1 I2C problem
I just tried the lsm9ds1 "simpletest" with both the standard SDA/SCL and D20/D21 and both worked wirh 4.0.beta3:
this was on D20/D21
Code: Select all
# Simple demo of the LSM9DS1 accelerometer, magnetometer, gyroscope.
# Will print the acceleration, magnetometer, and gyroscope values every second.
import time
import board
import busio
import adafruit_lsm9ds1
# I2C connection:
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
#SPI connection:
# from digitalio import DigitalInOut, Direction
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# csag = DigitalInOut(board.D5)
# csag.direction = Direction.OUTPUT
# csag.value = True
# csm = DigitalInOut(board.D6)
# csm.direction = Direction.OUTPUT
# csm.value = True
# sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm)
# Main loop will read the acceleration, magnetometer, gyroscope, Temperature
# values every second and print them out.
while True:
# Read acceleration, magnetometer, gyroscope, temperature.
accel_x, accel_y, accel_z = sensor.acceleration
mag_x, mag_y, mag_z = sensor.magnetic
gyro_x, gyro_y, gyro_z = sensor.gyro
temp = sensor.temperature
# Print values.
print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(accel_x, accel_y, accel_z))
print('Magnetometer (gauss): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(mag_x, mag_y, mag_z))
print('Gyroscope (degrees/sec): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(gyro_x, gyro_y, gyro_z))
print('Temperature: {0:0.3f}C'.format(temp))
# Delay for a second.
time.sleep(1.0)
this was on D20/D21
Code: Select all
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-beta.3 on 2019-03-07; Adafruit Grand Central M4 Express with samd51p20
>>> import lsm9ds1_simpletest
Acceleration (m/s^2): (0.399,-1.053,14.864)
Magnetometer (gauss): (0.149,0.497,-0.190)
Gyroscope (degrees/sec): (256.322,260.111,-232.829)
Temperature: 15.500C
Acceleration (m/s^2): (-1.235,-0.498,9.590)
Magnetometer (gauss): (0.141,0.487,-0.202)
Gyroscope (degrees/sec): (2.100,-4.209,-0.472)
Temperature: 17.500C
- bebo
- Posts: 96
- Joined: Tue Mar 29, 2011 8:22 am
Re: Adafruit Grand Central & LSM9DS1 I2C problem
I tried it using the lcd backpack and mcp9808 breakout and it wasn't working on D20/D21. I'll double check my version
- bebo
- Posts: 96
- Joined: Tue Mar 29, 2011 8:22 am
Re: Adafruit Grand Central & LSM9DS1 I2C problem
I retract my earlier statements, it's all running smoothly.
Where do I find the more in depth info about the chip i.e. which pins are SDA2/SCL2?
Thanks for the help.
Where do I find the more in depth info about the chip i.e. which pins are SDA2/SCL2?
Thanks for the help.
- tannewt
- Posts: 3315
- Joined: Thu Oct 06, 2016 8:48 pm
Re: Adafruit Grand Central & LSM9DS1 I2C problem
Full schematics are available on the Downloads page of the learn guide: https://learn.adafruit.com/adafruit-gra ... /downloads
- bebo
- Posts: 96
- Joined: Tue Mar 29, 2011 8:22 am
Please be positive and constructive with your questions and comments.