Page last edited December 06, 2013
Text editor powered by tinymce.
Page last edited December 06, 2013
Text editor powered by tinymce.
Page last edited December 06, 2013
Text editor powered by tinymce.
Place the Adafruit_Trellis library folder your sketchbookfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. You can figure out your sketchbookfolder by opening up the Preferences tab in the Arduino IDE.
If you're not familiar with installing Arduino libraries, please visit our tutorial: All About Arduino Libraries!Adafruit_Trellis matrix = Adafruit_Trellis();when you have many Adafruit_Trellis objects, we suggest creating a TrellisSet which will read all the buttons at once, write all the LEDs at once, etc. Each TrellisSet is given the names of the Adafruit_Trellis objects you created, up to 8.
Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0, &matrix1, &matrix2, &matrix3);When you call begin to start the Adafruit_TrellisSet object, pass in the addresses that correspond to your PCBs (see the next page on how to set addresses). The addresses range from 0x70 to 0x77
trellis.begin(0x70, 0x71, 0x72, 0x73); // or four!
trellis.readSwitches()It will return true if there has been any change in switches since the last time you called readSwitches(). So if some buttons were pressed and now aren't or vice versa, it will return true. If nothing's changed, it will return false
isKeyPressed(k)If you want to know if there was a change in the button, you can ask if it's been pressed or released since the last call to readSwitches()
trellis.justReleased(k)
trellis.justPressed(k)
Page last edited December 06, 2013
Text editor powered by tinymce.
For a more robust connection, use a small bare wire across the pads instead of just solder. The legs trimmed off the LEDs are perfect for this!
Page last edited December 06, 2013
Text editor powered by tinymce.
It's easy to use the Adafruit Trellis with Python or CircuitPython, and the Adafruit CircuitPython Trellis module. This module enables you to write Python code that allows you to easily control the LEDs and read button presses on a single Trellis board, or with a matrix of up to eight Trellis boards.
You can use this board with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
First wire up a Trellis to your board exactly as shown on the previous pages for Arduino. Here's an example of wiring a Feather M0 to the Trellis using I2C:
Since there's dozens of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired to a Trellis:
Next you'll need to install the Adafruit CircuitPython Trellis library on your CircuitPython board.
First, make sure you are running the latest version of Adafruit CircuitPython for your board.
Next, you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle. Our introduction guide has a great page on how to install the library bundle for both express and non-express boards.
Copy the following libraries from the bundle to the lib folder on your CIRCUITPY drive:
Before continuing make sure your board's lib folder or root filesystem has the adafruit_trellis.mpy, and adafruit_bus_device files and folders copied over.
Next connect to the board's serial REPL so you are at the CircuitPython >>> prompt.
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-trellis
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
To demonstrate the usage of the Trellis, we'll initialize it, control the LEDs and read the button presses from the board's Python REPL.
Run the following code to import the necessary modules and initialize the I2C connection with the Trellis:
import time import busio from board import SCL, SDA from adafruit_trellis import Trellis i2c = busio.I2C(SCL, SDA) trellis = Trellis(i2c)
import time import busio from board import SCL, SDA from adafruit_trellis import Trellis i2c = busio.I2C(SCL, SDA) trellis = Trellis(i2c)
Now, you're ready to control the LEDs and read button presses with the following:
show()
to update the LEDs. Defaults to True.auto_show=False
.To turn on all the LEDs:
To turn off all the LEDs:
To read when the buttons are pressed and released:
pressed_buttons = set() while True: 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
pressed_buttons = set() while True: 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
That's all there is to using your Trellis with CircuitPython!
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # 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(0.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(0.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(0.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
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # 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(0.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(0.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(0.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
Page last edited December 06, 2013
Text editor powered by tinymce.
Page last edited December 06, 2013
Text editor powered by tinymce.