Simple test
For I2C or SPI communications, ensure your device works with this simple test.
examples/l3gd20_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6import board
7
8import adafruit_l3gd20
9
10# Hardware I2C setup:
11I2C = board.I2C() # uses board.SCL and board.SDA
12# I2C = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
13# Initializes L3GD20 object using default range, 250dps
14SENSOR = adafruit_l3gd20.L3GD20_I2C(I2C)
15# Initialize L3GD20 object using a custom range and output data rate (ODR).
16# SENSOR = adafruit_l3gd20.L3GD20_I2C(
17# I2C, rng=adafruit_l3gd20.L3DS20_RANGE_500DPS, rate=adafruit_l3gd20.L3DS20_RATE_200HZ
18# )
19
20# Possible values for rng are:
21# adafruit_l3gd20.L3DS20_Range_250DPS, 250 degrees per second. Default range
22# adafruit_l3gd20.L3DS20_Range_500DPS, 500 degrees per second
23# adafruit_l3gd20.L3DS20_Range_2000DPS, 2000 degrees per second
24
25# Possible values for rate are:
26# adafruit_l3gd20.L3DS20_RATE_100HZ, 100Hz data rate. Default data rate
27# adafruit_l3gd20.L3DS20_RATE_200HZ, 200Hz data rate
28# adafruit_l3gd20.L3DS20_RATE_400HZ, 400Hz data rate
29# adafruit_l3gd20.L3DS20_RATE_800HZ, 800Hz data rate
30
31# Hardware SPI setup:
32# import digitalio
33# CS = digitalio.DigitalInOut(board.D5)
34# SPIB = board.SPI()
35# SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS)
36# SENSOR = adafruit_l3gd20.L3GD20_I2C(
37# SPIB,
38# CS,
39# rng=adafruit_l3gd20.L3DS20_RANGE_500DPS,
40# rate=adafruit_l3gd20.L3DS20_RATE_200HZ,
41# )
42
43while True:
44 print(f"Angular Velocity (rad/s): {SENSOR.gyro}")
45 print()
46 time.sleep(1)
DisplayIO Simpletest
This is a simple test for boards with built-in display.
examples/l3gd20_displayio_simpletest.py
1# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3#
4# SPDX-License-Identifier: MIT
5
6import time
7
8import board
9from adafruit_display_text.bitmap_label import Label
10from displayio import Group
11from terminalio import FONT
12
13import adafruit_l3gd20
14
15# Simple demo of using the built-in display.
16# create a main_group to hold anything we want to show on the display.
17main_group = Group()
18# Initialize I2C bus and sensor.
19i2c = board.I2C() # uses board.SCL and board.SDA
20sensor = adafruit_l3gd20.L3GD20_I2C(i2c)
21
22# Create Label(s) to show the readings. If you have a very small
23# display you may need to change to scale=1.
24display_output_label = Label(FONT, text="", scale=2)
25
26# place the label(s) in the middle of the screen with anchored positioning
27display_output_label.anchor_point = (0, 0)
28display_output_label.anchored_position = (
29 4,
30 board.DISPLAY.height // 2 - 60,
31)
32
33# add the label(s) to the main_group
34main_group.append(display_output_label)
35
36# set the main_group as the root_group of the built-in DISPLAY
37board.DISPLAY.root_group = main_group
38
39# begin main loop
40while True:
41 # update the text of the label(s) to show the sensor readings
42 x, y, z = sensor.gyro
43 display_output_label.text = f"Angular Vel (rad/s):\nx:{x:.2f}\ny:{y:.2f}\nz:{z:.2f}"
44 # wait for a bit
45 time.sleep(0.5)