PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Motors & actuators

Jog buttons

MediumBudget $12Python · gpiozero

A 28BYJ-48 stepper on its ULN2003 board: IN1–IN4 on GPIO17, 18, 27, 22, powered from 5 V. Half-step sequence (IN1..IN4): 1000, 1100, 0100, 0110, 0010, 0011, 0001, 1001 — walking it forwards turns the shaft clockwise (increasing angle). 4076 half-steps make one output turn; from rest, keep to at most one half-step every 2 ms.

Add two push buttons (to ground, Pi pull-ups): GPIO5 jogs the shaft 45° clockwise (510 half-steps forwards), GPIO6 jogs it 45° anticlockwise (510 back). One press, one jog.

The test presses GPIO5 at 1 s and 2.5 s, then GPIO6 at 4 s (each press 0.2 s; each jog takes about 1 s at 2 ms a half-step), and checks the position after each jog: 510, 1020, then 510 half-steps.

More in Motors & actuators