Overview
'Tis the season for festive displays, but Hanukkah doesn't always get the same kitschy, fun decor that other holidays do. In this project, you'll build a planetary gear that rotates three dreidels using an STSPIN220 silent stepper motor driver and a KB2040 running CircuitPython. It's giving Stu Pickles chaotic menorah energy from A Rugrats Chanukah Special.
An MPM3610 buck converter makes it possible to power the entire project with a 12V power supply. The stepper motor needs 12V and then the MPM3610 is able to output 5V to power the KB2040 via its RAW pin.
Page last edited December 16, 2025
Text editor powered by tinymce.
Circuit Diagram
An MPM3610 buck converter lets you power the entire project with a 12V DC power supply. It converts the 12V down to 5V to power the KB2040 through the RAW pin.
Power
- DC power positive to MPM3610 Vin (red wire)
- DC power ground to MPM3610 GND (black wire)
- DC power positive to STSPIN220 + terminal block (red wire)
- DC power ground to STSPIN220 - terminal block (black wire)
- MPM3610 5V to KB2040 RAW (orange wire)
- MPM3610 GND to KB2040 G (black wire)
STSPIN220 Wiring
- KB2040 3V to STSPIN220 VDD (red wire)
- KB2040 GND to STSPIN220 GND (black wire)
- KB2040 D2 to STSPIN220 DIR (blue wire)
- KB2040 D3 to STSPIN220 STEP (green wire)
- KB2040 D4 to STSPIN220 MS1 (yellow wire)
- KB2040 D5 to STSPIN220 MS2 (white wire)
- KB2040 D6 to STSPIN220 EN (cyan wire)
- KB2040 D7 to STSPIN220 RST (pink wire)
Stepper Motor
- STSPIN220 1A to stepper motor coil A+ (green wire)
- STSPIN220 2A to stepper motor coil A- (grey wire)
- STSPIN220 1B to stepper motor coil B+ (yellow wire)
- STSPIN220 2B to stepper motor coil B- (red wire)
Page last edited December 16, 2025
Text editor powered by tinymce.
3D Printing
You can 3D print all of the parts for this project. Here is a list to help you keep track:
- Main enclosure - 1x
- Bottom lid - 1x
- Sun gear - 1x
- Planet gears - 3x
- Dreidels - 3x
- Gear carrier - 1x
- Stepper motor mount - 1x
- Electronics mount - 1x
- Disk cover - 1x
The files can be downloaded directly below or from Printables. The files are available as .STL files or compiled .3MF files that include multicolor info, multiple copies of the model if needed and printing settings.
The source file is also available as both a Fusion360 project file and .STEP file.
The Hebrew letters on the dreidels and enclosure can be printed with a contrasting color for printers that can do multicolor printing. They are designed with a 45° chamfer around the edges so that they print cleanly.
Modeling Gears
Modeling gears can be tricky. I followed along with this YouTube video to get the gear system in place. It goes into great detail on the math you use to create these gear systems.
Page last edited December 16, 2025
Text editor powered by tinymce.
Install CircuitPython
CircuitPython is a derivative of MicroPython designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the CIRCUITPY drive to iterate.
CircuitPython Quickstart
Follow this step-by-step to quickly get CircuitPython running on your board.
Click the link above to download the latest CircuitPython UF2 file.
Save it wherever is convenient for you.
To enter the bootloader, hold down the BOOT/BOOTSEL button (highlighted in red above), and while continuing to hold it (don't let go!), press and release the reset button (highlighted in red or blue above). Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!
If the drive does not appear, release all the buttons, and then repeat the process above.
You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.
A lot of people end up using charge-only USB cables and it is very frustrating! Make sure you have a USB cable you know is good for data sync.
You will see a new disk drive appear called RPI-RP2.
Drag the adafruit_circuitpython_etc.uf2 file to RPI-RP2.
The RPI-RP2 drive will disappear and a new disk drive called CIRCUITPY will appear.
That's it, you're done! :)
Safe Mode
You want to edit your code.py or modify the files on your CIRCUITPY drive, but find that you can't. Perhaps your board has gotten into a state where CIRCUITPY is read-only. You may have turned off the CIRCUITPY drive altogether. Whatever the reason, safe mode can help.
Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode bypasses any code in boot.py (where you can set CIRCUITPY read-only or turn it off completely). Second, it does not run the code in code.py. And finally, it does not automatically soft-reload when data is written to the CIRCUITPY drive.
Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the CIRCUITPY drive.
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)
In Safe Mode
If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.
If you connect to the serial console, you'll find the following message.
Auto-reload is off. Running in safe mode! Not running saved code. CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode. Press any key to enter the REPL. Use CTRL-D to reload.
You can now edit the contents of the CIRCUITPY drive. Remember, your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode.
Flash Resetting UF2
If your board ever gets into a really weird state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. You will lose all the files on the board, but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.
Page last edited December 16, 2025
Text editor powered by tinymce.
Code the Dreidels
Once you've finished setting up your KB2040 with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.
To do this, click on the Download Project Bundle button in the window below. It will download to your computer as a zipped folder.
# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Planetary Gear Dreidel Code - slightly modified from the STSPIN220 example
"""
import board
import adafruit_stspin
STEPS_PER_REVOLUTION = 200
DIR_PIN = board.D2 # DIRection pin
STEP_PIN = board.D3 # STEP pin
MODE1_PIN = board.D4 # Mode 1 pin (REQUIRED for mode switching)
MODE2_PIN = board.D5 # Mode 2 pin (REQUIRED for mode switching)
EN_FAULT_PIN = board.D6 # Enable/Fault pin (optional)
STBY_RESET_PIN = board.D7 # Standby/Reset pin (REQUIRED for mode switching)
print("Initializing STSPIN220...")
motor = adafruit_stspin.STSPIN(
STEP_PIN,
DIR_PIN,
STEPS_PER_REVOLUTION,
mode1_pin=MODE1_PIN,
mode2_pin=MODE2_PIN,
en_fault_pin=EN_FAULT_PIN,
stby_reset_pin=STBY_RESET_PIN,
)
# Set the speed to 60 RPM
motor.speed = 60
motor.step_mode = adafruit_stspin.Modes.STEP_1_128
while True:
# continuously step the motor
total_microsteps = STEPS_PER_REVOLUTION * motor.microsteps_per_step
motor.step(total_microsteps)
Upload the Code and Libraries to the KB2040
After downloading the Project Bundle, plug your KB2040 into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called CIRCUITPY. Unzip the folder and copy the following items to the KB2040's CIRCUITPY drive.
- lib folder
- code.py
Your KB2040 CIRCUITPY drive should look like this after copying the lib folder and the code.py file.
How the CircuitPython Code Works
The code begins by assigning variable names to the GPIO pins used with the STSPIN220.
DIR_PIN = board.D2 # DIRection pin STEP_PIN = board.D3 # STEP pin MODE1_PIN = board.D4 # Mode 1 pin (REQUIRED for mode switching) MODE2_PIN = board.D5 # Mode 2 pin (REQUIRED for mode switching) EN_FAULT_PIN = board.D6 # Enable/Fault pin (optional) STBY_RESET_PIN = board.D7 # Standby/Reset pin (REQUIRED for mode switching)
These pins are passed to the STSPIN initializer.
print("Initializing STSPIN220...")
motor = adafruit_stspin.STSPIN(
STEP_PIN,
DIR_PIN,
STEPS_PER_REVOLUTION,
mode1_pin=MODE1_PIN,
mode2_pin=MODE2_PIN,
en_fault_pin=EN_FAULT_PIN,
stby_reset_pin=STBY_RESET_PIN,
)
Before the loop, a few parameters are setup for motor speed, microstep mode and steps per revolution.
STEPS_PER_REVOLUTION = 200 motor.speed = 60 motor.step_mode = adafruit_stspin.Modes.STEP_1_128
In the loop, the motor is stepped continuously to rotate the gear mechanism.
while True:
# continuously step the motor
total_microsteps = STEPS_PER_REVOLUTION * motor.microsteps_per_step
motor.step(total_microsteps)
Page last edited December 16, 2025
Text editor powered by tinymce.
Wiring
Solder the black wire from the JST-PH plug connector to the ground terminal on the DC jack. Solder the red wire from the JST-PH plug connector to the voltage terminal on the DC jack. Cover the connections with heat shrink.
Solder the red wire from the JST-PH socket connector to Vin. Solder the black wire from the JST-PH socket connector to GND.
Solder a second red wire to Vin. This wire will power the stepper motor via the terminal block on the STSPIN220 breakout.
Solder two additional black wires to GND. One will connect to the STSPIN220 GND terminal block and the other will connect to the KB2040 GND.
Solder a wire from GND on the STSPIN220 to GND on the KB2040 (black wire).
Solder a wire from 3V on the KB2040 to VDD on the STSPIN220 (red wire).
Solder wires to DIR (blue wire), STEP (green wire), MS1 (yellow wire), MS2 (white wire), EN (green wire) and RST (blue wire) on the STSPIN220. To keep the wire organized, you may want to use a piece of larger heat shrink.
Connect the STSPIN220 pins to the KB2040:
- DIR to D2 (blue wire)
- STEP to D3 (green wire)
- MS1 to D4 (yellow wire)
- MS2 to D5 (white wire)
- EN to D6 (green wire)
- RST to D7 (blue wire)
That completes all of the wiring.
Page last edited December 16, 2025
Text editor powered by tinymce.
Assembly
Carefully flex the KB2040 mount to secure the KB2040. Attach the MPM3610 to the outer mounting hole with an M2.5 screw. Attach the STSPIN220 to the mount with M2.5 screws.
Connect GND from the MPM3610 to the - terminal block on the STSPIN220 (black wire). Connect Vin from the MPM3610 to the + terminal block on the STSPIN220 (red wire).
Connect the stepper motor wires to the terminal block on the STSPIN220:
- Stepper coil 1 positive to STSPIN220 1A (green wire)
- Stepper coil 1 negative to STSPIN220 2A (grey wire)
- Stepper coil 2 positive to STSPIN220 1B (yellow wire)
- Stepper coil 2 negative to STSPIN220 2B (red wire)
Place the stepper motor mount over the stepper motor, lining up the top mounting holes. Place the electronics mount on top of the stepper mount. The electronics should be facing downwards.
Secure the cover disk over the mounts with four M3 screws so that all of the pieces are attached to the stepper motor.
Now is a good time to install CircuitPython on the KB2040 and upload the Project Bundle to the board, if you have not previously done so.
Plug the DC jack JST-PH connector into the MPM3610 JST-PH connector. This connects the power supply to Vin and GND.
Take the stepper motor assembly and put it inside the enclosure. Secure the motor mount to the bottom lid with four M3 screws.
Page last edited December 16, 2025
Text editor powered by tinymce.
Dreidel Dreidel Dreidel
After assembly, plug in a 12V power supply to the DC jack. You'll see the gears start to spin. The planetary gear mechanism has two motions occurring at the same time. The outer planet gears are rotating while revolving around the center sun gear.
Page last edited December 16, 2025
Text editor powered by tinymce.