Servo blocks remain in PWM and are implemented in src/blocks/hardware/pwm.js. A single _Servo class composes MicroPython machine.PWM at 50 Hz; it is not a native machine class. Both kinds of hardware receive the same pulse signal. The class makes no assumptions about the attached hardware type; angle and speed methods are numeric mappings, not hardware mode changes. Standard micro:bit and SPIKE firmware have separate APIs.
Create a named object once with the actual pin, calibrated minimum/maximum pulses, angle range and optional rotation-neutral pulse (defaults to the midpoint). The same creation block is used for either hardware type. Use the variable dropdown on subsequent blocks. A 180°, 270° or 360° position servo differs in configured angle range, not class.
arm = _Servo(18, 500, 2500, 180)
arm.angle(0)
arm.angle(180)
arm.angle(0)
arm.deinit()Creation allocates PWM but sends no target until the first angle or pulse command. angle(degrees) clamps to the configured range; pulse(us) is restricted to the calibrated endpoints and updates the target estimate. target_angle() reports the angle corresponding to the last commanded pulse (None initially), never measured shaft position. The target-angle block stores this result in the selected variable. It is meaningful only for a positional servo. The driver has no motion timing, interpolation, or scheduler. Actual motion depends on mechanics, load and the servo's speed.
Gradual motion is an application policy composed of ordinary loop, angle and wait blocks, for example:
for angle in range(0, 181):
arm.angle(angle)
time.sleep_ms(20)Choose the step size, delay, direction, and any easing or feedback in the application. This changes the commanded target, not measured physical speed. Wait for physical settling as needed; there is no implicit blocking until the shaft reaches its target. Do not present synthesized movement timing as a native servo capability.
wheel = _Servo(18, 1000, 2000, 180, 1500)
wheel.speed(50)
wheel.speed(-50)
wheel.stop()
wheel.deinit()A continuous-rotation servo interprets pulse width as direction and relative speed, not a target angle. Construction does not send any control pulse. Explicitly call stop() to send neutral or speed() to begin movement. The position range parameter is not used by the speed mapping. Signed speed is clamped to -100…100, with 0 sending neutral. The two sides are mapped independently so asymmetric calibration works. Physical direction and RPM depend on the model, supply and load; ordinary three-wire servos provide no external position feedback. stop() continues sending neutral, whereas deinit() removes PWM (idempotent). Both types use the same object, pulse and release blocks. Choose the method appropriate for the actual hardware: speed() on a positional servo changes its target position rather than its speed; angle() on continuous hardware changes its rotation command rather than its position. stop() sends neutral and is meaningful as a stop only for continuous hardware. Do not treat release as power-off or a guaranteed mechanical stop.
Use the manufacturer's pulse range and supply requirements. The example's 500–2500 µs positional range is not universal; start with conservative endpoints and avoid mechanical limits. The continuous example uses 1000/1500/2000 µs; adjust neutral until the unloaded servo stops. Use adequate servo power and common ground. Choose an output-capable GPIO, keep different outputs on separate pins, and avoid frequency conflicts on ports sharing PWM timers. Create one owner per output; release before reusing a pin. Requires a firmware port with PWM.duty_ns(), duty_u16(), and deinit().
- Immediate sweep: alternate 0 and 180 with delays.
- Slow sweep: compose a gradual sweep from standard counting loops, angle commands and waits; no servo-specific motion helper.
- Continuous rotation: rotate, reverse, stop and release.
The old pin-based blocks and separate continuous-servo creation/operation blocks are replaced, not migrated. Recreate those blocks in existing saved projects. Tests simulate generated Python with fake PWM/time; physical-board validation is separate.