The seesaw firmware that ships with the ATtinyxxx breakouts includes digital capabilities on specific pins. This example blinks the turns on the built-in LED when a button is pressed.

Follow the instructions on the Python & CircuitPython page to get set up.

Though the Fritzing diagrams depict an ATtiny817, the examples work as written with the ATtiny816 and ATtiny1616.

Digital Pins

There are 15 pins on the ATtiny817 breakout that can be used with digitalio:

  • 0-3, 5-9, 12-14, 18-20

There are 12 pins on the ATtinyx16 breakouts that can be used with digitalio:

  • 0-6, 8, 11, 14-16

Wiring

Connect a button up to your already wired up breakout as follows.

  • Use a STEMMA QT cable to connect the STEMMA QT connector on the Feather to the STEMMA QT connector on the breakout.
  • Connect one leg of button to breakout GND
  • Connect opposite leg of button to breakout pin 2

Example Code

Update your code.py to the following.

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# Simple seesaw test using an LED attached to Pin 5 and a button on pin 2
#
# See the seesaw Learn Guide for wiring details.
# For SAMD09:
# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test
# For ATtiny8x7:
# https://learn.adafruit.com/adafruit-attiny817-seesaw/digital-input

import time
import board
import digitalio
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.digitalio import DigitalIO

i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
ss = Seesaw(i2c)

button_pin = 2
led_pin = 5

button = DigitalIO(ss, button_pin)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

led = DigitalIO(ss, led_pin)
led.direction = digitalio.Direction.OUTPUT

while True:
    # simply set the LED to the same 'value' as the button pin
    led.value = button.value
    time.sleep(0.1)

Now, press the button to see the little red LED light up! Release the button to turn it off.

First, you import all the necessary modules and libraries. Then you instantiate the seesaw on I2C.

Next, you choose the button pin and LED pin. The button is on pin 2, and the built-in LED is on pin 5.

Then you create the button object, and set it up as an input with a pullup. Following that, you create the LED object and set up the pin as an output.

Finally, inside the loop, you simply set the LED state equal to the button state with a 0.1 second delay for debounce.

That's all there is to using CircuitPython seesaw digitalio with the ATtinyxxx breakouts!

This guide was first published on Oct 20, 2021. It was last updated on Mar 29, 2024.

This page (Digital Input) was last updated on Mar 28, 2024.

Text editor powered by tinymce.