Introduction¶
This library will allow you to control the LEDs and read button presses on the Adafruit Trellis Board. It will work with a single Trellis board, or with a matrix of up to 8 Trellis boards.
For more details, see the Adafruit Trellis Learn Guide.
Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Usage Example¶
See examples/trellis_simpletest.py for full usage example.
import time
import busio
from board import SCL, SDA
from adafruit_trellis import Trellis
# Create the I2C interface
i2c = busio.I2C(SCL, SDA)
# Create a Trellis object for each board
trellis = Trellis(i2c) # 0x70 when no I2C address is supplied
# Turn on every LED
print('Turning all LEDs on...')
trellis.led.fill(True)
time.sleep(2)
# Turn off every LED
print('Turning all LEDs off...')
trellis.led.fill(False)
time.sleep(2)
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Building locally¶
Zip release files¶
To build this library locally you’ll need to install the circuitpython-build-tools package.
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
source .env/bin/activate
Then run the build:
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-trellis --library_location .
Sphinx documentation¶
Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to docs/_build/html
. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
Table of Contents¶
Simple test¶
Ensure your device works with this simple test.
Single Adafruit Trellis Board
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # Basic example of turning on LEDs and handling Keypad
# button activity.
# This example uses only one Trellis board, so all loops assume
# a maximum of 16 LEDs (0-15). For use with multiple Trellis boards,
# see the documentation.
import time
import busio
from board import SCL, SDA
from adafruit_trellis import Trellis
# Create the I2C interface
i2c = busio.I2C(SCL, SDA)
# Create a Trellis object
trellis = Trellis(i2c) # 0x70 when no I2C address is supplied
# 'auto_show' defaults to 'True', so anytime LED states change,
# the changes are automatically sent to the Trellis board. If you
# set 'auto_show' to 'False', you will have to call the 'show()'
# method afterwards to send updates to the Trellis board.
# Turn on every LED
print('Turning all LEDs on...')
trellis.led.fill(True)
time.sleep(2)
# Turn off every LED
print('Turning all LEDs off...')
trellis.led.fill(False)
time.sleep(2)
# Turn on every LED, one at a time
print('Turning on each LED, one at a time...')
for i in range(16):
trellis.led[i] = True
time.sleep(.1)
# Turn off every LED, one at a time
print('Turning off each LED, one at a time...')
for i in range(15, 0, -1):
trellis.led[i] = False
time.sleep(.1)
# Now start reading button activity
# - When a button is depressed (just_pressed),
# the LED for that button will turn on.
# - When the button is relased (released),
# the LED will turn off.
# - Any button that is still depressed (pressed_buttons),
# the LED will remain on.
print('Starting button sensory loop...')
pressed_buttons = set()
while True:
# Make sure to take a break during each trellis.read_buttons
# cycle.
time.sleep(.1)
just_pressed, released = trellis.read_buttons()
for b in just_pressed:
print('pressed:', b)
trellis.led[b] = True
pressed_buttons.update(just_pressed)
for b in released:
print('released:', b)
trellis.led[b] = False
pressed_buttons.difference_update(released)
for b in pressed_buttons:
print('still pressed:', b)
trellis.led[b] = True
|
adafruit_trellis
- Adafruit Trellis Monochrome 4x4 LED Backlit Keypad¶
CircuitPython library to support Adafruit’s Trellis Keypad.
- Author(s): Limor Fried, Radomir Dopieralski, Tony DiCola,
- Scott Shawcroft, and Michael Schroeder
Implementation Notes¶
Hardware:
- Adafruit Trellis Monochrome 4x4 LED Backlit Keypad (Product ID: 1616)
Software and Dependencies:
- Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
- Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
-
class
adafruit_trellis.
Trellis
(i2c, addresses=None)¶ Driver base for a single Trellis Board
Parameters: - i2c (I2C) – The
busio.I2C
object to use. This is the only required parameter when using a single Trellis board. - addresses (list) – The I2C address(es) of the Trellis board(s) you’re using. Defaults
to
[0x70]
which is the default address for Trellis boards. See Trellis product guide for using different/multiple I2C addresses. https://learn.adafruit.com/adafruit-trellis-diy-open-source-led-keypad
Usage Example¶1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
# Basic example of turning on LEDs and handling Keypad # button activity. # This example uses only one Trellis board, so all loops assume # a maximum of 16 LEDs (0-15). For use with multiple Trellis boards, # see the documentation. import time import busio from board import SCL, SDA from adafruit_trellis import Trellis # Create the I2C interface i2c = busio.I2C(SCL, SDA) # Create a Trellis object trellis = Trellis(i2c) # 0x70 when no I2C address is supplied # 'auto_show' defaults to 'True', so anytime LED states change, # the changes are automatically sent to the Trellis board. If you # set 'auto_show' to 'False', you will have to call the 'show()' # method afterwards to send updates to the Trellis board. # Turn on every LED print('Turning all LEDs on...') trellis.led.fill(True) time.sleep(2) # Turn off every LED print('Turning all LEDs off...') trellis.led.fill(False) time.sleep(2) # Turn on every LED, one at a time print('Turning on each LED, one at a time...') for i in range(16): trellis.led[i] = True time.sleep(.1) # Turn off every LED, one at a time print('Turning off each LED, one at a time...') for i in range(15, 0, -1): trellis.led[i] = False time.sleep(.1) # Now start reading button activity # - When a button is depressed (just_pressed), # the LED for that button will turn on. # - When the button is relased (released), # the LED will turn off. # - Any button that is still depressed (pressed_buttons), # the LED will remain on. print('Starting button sensory loop...') pressed_buttons = set() while True: # Make sure to take a break during each trellis.read_buttons # cycle. time.sleep(.1) just_pressed, released = trellis.read_buttons() for b in just_pressed: print('pressed:', b) trellis.led[b] = True pressed_buttons.update(just_pressed) for b in released: print('released:', b) trellis.led[b] = False pressed_buttons.difference_update(released) for b in pressed_buttons: print('still pressed:', b) trellis.led[b] = True
-
auto_show
¶ Current state of sending LED updates directly the Trellis board(s).
True
orFalse
.
-
blink_rate
¶ The current blink rate as an integer range 0-3.
-
brightness
¶ The current brightness as an integer range 0-15.
-
led
= None¶ The LED object used to interact with Trellis LEDs.
trellis.led[x]
returns the current LED status of LEDx
(True/False)trellis.led[x] = True
turns the LED atx
ontrellis.led[x] = False
turns the LED atx
offtrellis.led.fill(bool)
turns every LED on (True) or off (False)
Read the button matrix register on the Trellis board(s). Returns two lists: 1 for new button presses, 1 for button relases.
-
show
()¶ Refresh the LED buffer and show the changes.
- i2c (I2C) – The