The seesaw firmware that ships with the ATtinyxxx breakouts 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
The ATtiny816 and ATtiny1616 breakouts with seesaw firmware provides PWM on the following pins:
- 0, 1, 7, 11, 16
- 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 code.py to the following. If you are using an ATtinyx16, update PWM_PIN
to be one of the PWM capable pins listed above to match your wiring.
# 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: # https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test # For ATtiny8x7: # https://learn.adafruit.com/adafruit-attiny817-seesaw/pwmout import time import board from adafruit_seesaw import seesaw, pwmout 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.Seesaw(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 time.sleep(delay) for cycle in range(65534, 0, -256): led.duty_cycle = cycle time.sleep(delay)
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 ATtinyxxx breakouts!
Text editor powered by tinymce.