Trouble using the gyroscope with CircuitPython

I’m using the adafruit_lis3dh module but getting an error on the Wio Terminal when trying to use the gyroscope.

code:

import time
import board
import digitalio
import busio
import adafruit_lis3dh
import adafruit_lis331

i2c = busio.I2C(board.GYROSCOPE_SCL, board.GYROSCOPE_SDA)
int1 = digitalio.DigitalInOut(board.GYROSCOPE_INT)

lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

error:

Adafruit CircuitPython 6.0.0-alpha.2 on 2020-07-23; Seeeduino Wio Terminal with samd51p19

code.py output:
Traceback (most recent call last):
  File "code.py", line 12, in <module>
  File "adafruit_lis3dh.py", line 334, in __init__
  File "adafruit_lis3dh.py", line 92, in __init__
  File "adafruit_lis3dh.py", line 312, in _read_register_byte
  File "adafruit_lis3dh.py", line 341, in _read_register
  File "adafruit_lis3dh.py", line 339, in _read_register
  File "adafruit_bus_device/i2c_device.py", line 104, in write
TypeError: extra keyword arguments given

Hi @Steve_M

You can try the following code:

import time
import board
import digitalio
import busio
import adafruit_lis3dh

i2c = busio.I2C(board.GYROSCOPE_SCL, board.GYROSCOPE_SDA)
int1 = digitalio.DigitalInOut(board.GYROSCOPE_INT)

lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x18, int1=int1)

# Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G).
lis3dh.range = adafruit_lis3dh.RANGE_2_G

# Loop forever printing accelerometer values
while True:
    # Read accelerometer values (in m / s ^ 2).  Returns a 3-tuple of x, y,
    # z axis values.  Divide them by 9.806 to convert to Gs.
    x, y, z = [
        value / adafruit_lis3dh.STANDARD_GRAVITY for value in lis3dh.acceleration
    ]
    print("x = %0.3f G, y = %0.3f G, z = %0.3f G" % (x, y, z))
    # Small delay to keep things responsive but give time for interrupt processing.
    time.sleep(0.1)

Hi @ansonhe97,

The issue is now resolved. It was related to changes with CircuitPython 6 and the i2c library needing to be updated. The changes have been made and an updated package for adafruit_bus_device has been released and the lis3dh device initializes properly now.

1 Like

Good to hear :smiley: Have a good day

2 Likes