The seesaw firmware that ships with the ATtinyxxx breakouts includes analog capabilities on specific pins. This simple example reads the analog value of a pin.

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.

Analog Pins

The ATtiny817 breakout with seesaw firmware provides analog on the following pins:

  • 0-3, 6, 7, 18-20

The ATtiny816 and ATtiny1616 breakout with seesaw firmware provides analog on the following pins:

  • 0-5, 14-16

Example Code

Update your code.py to the following.

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

# Simple seesaw test reading analog value
# on SAMD09, analog in can be pins 2, 3, or 4
# on Attiny8x7, analog in can be pins 0, 1, 2, 3, 6, 7, 18, 19, 20

import time
import board
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.analoginput import AnalogInput

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)

analogin_pin = 2
analog_in = AnalogInput(ss, analogin_pin)

while True:
    print(analog_in.value)
    time.sleep(0.1)

Now, connect to the serial console to see the values printed out.

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

Next, you choose the analog pin from which you would like to read values, in this case pin 2, and then set it up as an AnalogInput.

Inside the loop, you read the analog pin value and print it to the serial console. Finally, you include a short delay to keep the values readable.

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

This guide was first published on Oct 20, 2021. It was last updated on Apr 16, 2024.

This page (Analog In) was last updated on Apr 16, 2024.

Text editor powered by tinymce.