Simple test

For I2C communications, ensure your device works with this simple test.

examples/l3gd20_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import time
from board import SCL, SDA
import busio
import adafruit_l3gd20

# define the I2C wires
I2C = busio.I2C(SCL, SDA)
# initialize the device
SENSOR = adafruit_l3gd20.L3GD20_I2C(I2C)

while True:

    print('Acceleration (m/s^2): {}'.format(SENSOR.acceleration))

    print()

    time.sleep(1)

For SPI communications, ensure your device works with this simple test.

examples/l3gd20_spi_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import time
from board import SCK, MISO, MOSI, D5
import busio
import digitalio
import adafruit_l3gd20

# define the spi conneciton
CS = digitalio.DigitalInOut(D5)  # select pin is 5
SPIB = busio.SPI(SCK, MOSI, MISO)
# now initialize the device
SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS)

while True:

    print('Acceleration (m/s^2): {}'.format(SENSOR.acceleration))

    print()

    #sleep for 1 second
    time.sleep(1)