CircuitPython and Python
It's easy to use the Adafruit NeoPot with Python or CircuitPython, and the Adafruit_CircuitPython_NeoPixel module. This module allows you to easily write Python code to set the color of the NeoPixel. The Potentiometer can be read with the built-in analogio module.
You can use the NeoPixel and analogio modules with any CircuitPython microcontroller board.
CircuitPython Microcontroller Wiring
First wire up the breakout to your board exactly as follows. The following is the NeoPot wired to a Feather RP2040 using the STEMMA connector:
- Board 3.3V to NeoPot P+ (red wire)
- Board GND to NeoPot P- (black wire)
- Board A0 to NeoPot POT (yellow wire)
- Board D4 to NeoPot Nin (green wire)
You also need make the following connections if you did not solder closed the jumpers on the bottom of the NeoPot:
- NeoPot P- to NeoPot GND
- NeoPot P+ to NeoPot Vcc
See 2nd and 3rd photos for jumper location, and wiring to use when the jumpers are soldered closed.
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_NeoPixel library, and its dependencies, into the lib folder on 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 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 files:
- adafruit_pixelbuf.mpy
- neopixel.mpy
Example Code
Once everything is saved to the CIRCUITPY drive, turn the knob to see it shift between the colors of the rainbow as you turn.
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
NeoPot NeoPixel Rainbow Demo
"""
import board
import analogio
import neopixel
import rainbowio
analog_pin = analogio.AnalogIn(board.A0)
knob_pixel = neopixel.NeoPixel(board.D4, 1, brightness=0.75, auto_write=True)
analog_smoothing_buffer = []
def map_range(x, in_min, in_max, out_min, out_max):
return (x - in_min) / (in_max - in_min) * out_max - out_min
def average(values):
if not values:
return 0
return sum(values) / len(values)
while True:
analog_smoothing_buffer.insert(0, analog_pin.value)
if len(analog_smoothing_buffer) >= 10:
analog_smoothing_buffer.pop(-1)
knob_pixel[0] = rainbowio.colorwheel(
map_range(average(analog_smoothing_buffer), 0, 65525, 0, 255)
)
The code stores readings in a list and takes an average of the last 10 readings, then maps the average reading into the range 0-255 so it can be passed to rainbowio.colorwheel() to get back a color, which is then set on the NeoPixel.
Page last edited August 19, 2025
Text editor powered by tinymce.