Skip to content

Commit 306a983

Browse files
committed
adding dreidel code
1 parent c3f3ccb commit 306a983

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Planetary_Gear_Dreidels/code.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Planetary Gear Dreidel Code - slightly modified from the STSPIN220 example
7+
"""
8+
9+
import board
10+
11+
import adafruit_stspin
12+
13+
STEPS_PER_REVOLUTION = 200
14+
15+
DIR_PIN = board.D2 # DIRection pin
16+
STEP_PIN = board.D3 # STEP pin
17+
MODE1_PIN = board.D4 # Mode 1 pin (REQUIRED for mode switching)
18+
MODE2_PIN = board.D5 # Mode 2 pin (REQUIRED for mode switching)
19+
EN_FAULT_PIN = board.D6 # Enable/Fault pin (optional)
20+
STBY_RESET_PIN = board.D7 # Standby/Reset pin (REQUIRED for mode switching)
21+
22+
print("Initializing STSPIN220...")
23+
motor = adafruit_stspin.STSPIN(
24+
STEP_PIN,
25+
DIR_PIN,
26+
STEPS_PER_REVOLUTION,
27+
mode1_pin=MODE1_PIN,
28+
mode2_pin=MODE2_PIN,
29+
en_fault_pin=EN_FAULT_PIN,
30+
stby_reset_pin=STBY_RESET_PIN,
31+
)
32+
33+
# Set the speed to 60 RPM
34+
motor.speed = 60
35+
motor.step_mode = adafruit_stspin.Modes.STEP_1_128
36+
37+
while True:
38+
# continuously step the motor
39+
total_microsteps = STEPS_PER_REVOLUTION * motor.microsteps_per_step
40+
motor.step(total_microsteps)

0 commit comments

Comments
 (0)