The seesaw firmware that ships with the ATtiny817 breakout includes PWM capabilities on specific pins. This example fades an external LED.

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

PWM Pins

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

  • 0, 1, 9, 12, 13


This example uses an external LED. Wire it up 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 the + leg (longer leg) of LED to breakout pin 12
  • Connect the - leg (shorter leg) of LED to 1kΩ resistor
  • Connect 1kΩ resistor to breakout GND

Example Code

Update your to the following.

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

# Simple seesaw test for writing PWM outputs
# On the SAMD09 breakout these are pins 5, 6, and 7
# On the ATtiny8x7 breakout these are pins 0, 1, 9, 12, 13
# See the seesaw Learn Guide for wiring details.
# For SAMD09:
# For ATtiny8x7:

import time
import board
from adafruit_seesaw import seesaw, pwmout

ss = seesaw.Seesaw(board.I2C())

PWM_PIN = 12  # If desired, change to any valid PWM output!
led = pwmout.PWMOut(ss, PWM_PIN)

delay = 0.01
while True:
    # The API PWM range is 0 to 65535, but we increment by 256 since our
    # resolution is often only 8 bits underneath
    for cycle in range(0, 65535, 256):  #
        led.duty_cycle = cycle
    for cycle in range(65534, 0, -256):
        led.duty_cycle = cycle

The brightness of the LED will fade up and then down, and repeat!

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

Next, you choose a pin for the LED, and then create the LED PWMOut object and provide it the PWM_PIN.

Before the loop, you set a delay of 0.01 seconds.

Inside the loop, you initially cycle up through the PWM range (0 - 65535) in increments 0f 256, and once complete, cycle down from the max back to 0 in increments of 256. The step is limited to increments of 256 because the resolution is often only 8 bits underneath. Both cycles have the delay included.

That's all there is to using CircuitPython seesaw PWM to fade an LED on the ATtiny817 breakout!

This guide was first published on Oct 20, 2021. It was last updated on 2021-10-20 12:04:17 -0400.

This page (PWMOut) was last updated on Aug 27, 2022.

Text editor powered by tinymce.