The main use case for this Feather is to use it for making props with lights, sound and movement. CircuitPython has the Adafruit_CircuitPython_NeoPixel module, which allows you to easily write Python code that lets you control NeoPixels, as well as the Adafruit_CircuitPython_LIS3DH module that lets you write Python code to interface with the onboard LIS3DH accelerometer. In the examples below, you'll attach a bunch of prop-making components to the Feather and see how you can write code to control all of them for your next prop.
NeoPixels
- NeoPixel DIN to Feather terminal block NEO (blue wire)
- NeoPixel GND to Feather terminal block G (black wire)
- NeoPixel 5V to Feather terminal block 5V (red wire)
Button
- Button GND to Feather terminal block G (black wire)
- Button output to Feather terminal block Btn (green wire)
Speaker
- Speaker positive to Feather terminal block + (red wire)
- Speaker negative to Feather terminal block - (black wire)
Servo
- Servo signal to Feather Sig (yellow wire)
- Servo power to Feather V+ (red wire)
- Servo GND to Feather G (black wire)
CircuitPython Usage
To use with CircuitPython, you need to first install the NeoPixel and LIS3DH libraries, and their dependencies, into the lib folder onto your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries, audio .wav file (StreetChicken.wav) and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folders:
- adafruit_bus_device/
- adafruit_led_animation/
- adafruit_motor/
- adafruit_lis3dh.mpy
- adafruit_pixelbuf.mpy
- neopixel.mpy
Example Code
Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries # # SPDX-License-Identifier: MIT '''RP2040 Prop-Maker Feather Example''' import time import board import audiocore import audiobusio import audiomixer import pwmio from digitalio import DigitalInOut, Direction, Pull import neopixel from adafruit_led_animation.animation.rainbow import Rainbow from adafruit_motor import servo import adafruit_lis3dh # enable external power pin # provides power to the external components external_power = DigitalInOut(board.EXTERNAL_POWER) external_power.direction = Direction.OUTPUT external_power.value = True # i2s playback wave_file = open("StreetChicken.wav", "rb") wave = audiocore.WaveFile(wave_file) audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA) mixer = audiomixer.Mixer(voice_count=1, sample_rate=22050, channel_count=1, bits_per_sample=16, samples_signed=True) audio.play(mixer) mixer.voice[0].play(wave, loop=True) mixer.voice[0].level = 0.5 # servo control pwm = pwmio.PWMOut(board.EXTERNAL_SERVO, duty_cycle=2 ** 15, frequency=50) prop_servo = servo.Servo(pwm) angle = 0 angle_plus = True # external button switch = DigitalInOut(board.EXTERNAL_BUTTON) switch.direction = Direction.INPUT switch.pull = Pull.UP switch_state = False # external neopixels num_pixels = 30 pixels = neopixel.NeoPixel(board.EXTERNAL_NEOPIXELS, num_pixels) pixels.brightness = 0.3 rainbow = Rainbow(pixels, speed=0.05, period=2) # onboard LIS3DH i2c = board.I2C() int1 = DigitalInOut(board.ACCELEROMETER_INTERRUPT) lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) lis3dh.range = adafruit_lis3dh.RANGE_2_G while True: # rainbow animation on external neopixels rainbow.animate() # read and print LIS3DH values x, y, z = [ value / adafruit_lis3dh.STANDARD_GRAVITY for value in lis3dh.acceleration ] print(f"x = {x:.3f} G, y = {y:.3f} G, z = {z:.3f} G") # move servo back and forth prop_servo.angle = angle if angle_plus: angle += 5 else: angle -= 5 if angle == 180: angle_plus = False elif angle == 0: angle_plus = True # if the switched is pressed, turn off power to external components if not switch.value and switch_state is False: external_power.value = False switch_state = True if switch.value and switch_state is True: external_power.value = True switch_state = False time.sleep(0.02)
This example utilizes all of the special pins on the Prop-Maker Feather. It begins by enabling the EXTERNAL_POWER
pin to power up the external NeoPixels (EXTERNAL_NEOPIXELS
), servo (EXTERNAL_SERVO
) and speaker from the onboard I2S amp. Then, the I2S amplifier is instantiated with a mixer
object passed to it. This allows for easy volume control in software.
In the serial console, you'll see the movement data from the LIS3DH printed out.
The following will happen with the attached components:
- The external NeoPixels will display a rainbow swirl animation
- The external servo motor will move back and forth
- When the external button is pressed, the external power pin is turned off. As a result, the servo, audio playback and NeoPixels all stop
- An audio file will play on a loop
Text editor powered by tinymce.