Here's an example project you can do with your Nunchuck breakout to control some NeoPixels with joystick, button, and motion from a Wii Nunchuck.

Parts

Hand holding a Wiichuck controller pressing buttons. The controller is connected to the breakout wired to a Feather with OLED showing the streaming controller data
Dig out that old Wii controller and use it as a sleek controller for your next robot if you like. The Adafruit Adafruit Wii Nunchuck Breakout Adapter fits snugly into the Wii connector...
$2.95
In Stock
Hand gripping Wii controller (Nunchuck / Wiichuck)
This is a generic Wii Nunchuck controller, we haven't tried it with a Wii but it does work great with the Video Game shield, and all the microcontroller code we tried. May come in...
$12.50
In Stock

You can use pretty much any CircuitPython-capable board for this, I had a Metro M4 Airlift handy.

Adafruit Metro M4 Airlift Lite dev board with SAMD51 an ESP32 Wifi Co-processor.
Give your next project a lift with AirLift - our witty name for the ESP32 co-processor that graces this Metro M4. You already know about the Adafruit Metro...
$34.95
In Stock

This will work with any NeoPixel strand, strip, or ring.

NeoPixel Ring with 60 x 5050 RGBW LEDs lighting up rainbow and white
What is better than smart RGB LEDs? Smart RGB+White LEDs! These NeoPixels now have 4 LEDs in them (red, green, blue and white) for excellent lighting effects. Round and round...
Out of Stock
Top view of JST SH 4-pin to Premium Male Headers Cable next to US quarter for scale.
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the...
$0.95
In Stock

Wiring

Use the STEMMA QT/qwiic to male header pin adapter to plug the Nunchuck breakout into your microcontroller's 3.3V, GND, SDA, & SCL lines.

Wire your NeoPixels into the board's 5V, GND, and D6 (to NeoPixel DIN) pins (if your board only has 3.3V that's usually fine, too, but NeoPixels prefer 5V when available).

Then, plug your Nunchuck controller into the adapter, making sure to follow the silkscreened "NOTCH UP" guidline.

Code

Set up your board as shown on the previous page, then download this code onto the board as code.py.

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

import time
import board
import adafruit_nunchuk
import neopixel
import simpleio

i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
nc = adafruit_nunchuk.Nunchuk(i2c)
#  create neopixel object
NEOPIN = board.D6
NEOLENGTH = 60
NEOORDER = neopixel.GRBW  # set to GRB for 'regular' RGB NeoPixels
pixels = neopixel.NeoPixel(
    NEOPIN, NEOLENGTH, brightness=0.1, auto_write=False, pixel_order=NEOORDER
)

RED = (220, 0, 0)
PURPLE = (80, 0, 160)
PINK = (100, 0, 80)
GREEN = (0, 180, 0)
CYAN = (0, 80, 100)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)

COLORS = [RED, PURPLE, PINK, GREEN, CYAN, BLUE]
pix = 0  # selected pixel
color_pick = 0  # current color index
pixels.fill(BLACK)
pixels.show()

while True:
    x, y = nc.joystick  # get joystick values
    ax, ay, az = nc.acceleration  # get accelerometer values

    tilt_x = simpleio.map_range(ax, 300.0, 800.0, 0.0, 1.0)  # remap tilt to brightness
    # remap y to current pixel
    pix = int(
        simpleio.map_range(y, 0, 255, 0, NEOLENGTH - 1)
    )

    if nc.button_C:  # hold C button to use tilt for brightness
        pixels.brightness = tilt_x

    if nc.button_Z:
        color_pick = (color_pick + 1) % 4  # cycle through colors
        time.sleep(0.02)  # debounce

    pixels.fill(BLACK)  # turn off pixels
    for i in range(0, pix + 1):  # light up all pixels up to the current one
        pixels[i] = COLORS[color_pick]

    pixels.show()

Now, you can control your LEDs with the nunchuck!

  • move the joystick up and down to choose how many pixels are lit
  • tap the Z button to change colors
  • hold the C button while tilting the controller from side to side to adjust brightness. Let go of the C button to lock in that brightness level

This guide was first published on Jan 10, 2021. It was last updated on Jun 14, 2024.

This page (Sample Project: Nunchuck NeoPixel Ring) was last updated on Jun 14, 2024.

Text editor powered by tinymce.