Motors and Motor Drivers
A digital pin can light an LED; it cannot reasonably drive a motor. Motors and other power loads need motor drivers — H-bridges, MOSFETs, dedicated chips — sitting between the MCU and the load to handle the current. NodeBlue covers the three common families: steppers, DC motors, and driver-chip wrappers for the boards you'll typically buy.
Steppers — nStepper and nStepDir
A stepper motor rotates a known angle per "step", controlled by a precise sequence of coil energisations. NodeBlue offers two approaches:
| Module | Use it when |
|---|---|
| nStepper | The MCU drives the coils directly through four GPIO pins — typical of cheap bipolar/unipolar steppers with a basic driver IC (ULN2003 etc.). |
| nStepDir | The MCU drives a dedicated stepper driver (DRV8825, TMC2209, A4988 …) that takes only STEP and DIR signals. |
nStepper — direct coil control
| Parameter | Description |
|---|---|
| Pin 1 / 2 / 3 / 4 | Four GPIOs wired to the coils (or the input pins of a coil-driver chip). |
| Speed | Step rate. |
Useful for small panel-mount steppers (the 28BYJ-48 ones on every hobby site). Drive it from a numeric position input; the module sequences the coils to reach that position.
nStepDir — STEP / DIR driver
Most modern stepper drivers expose just two pins: pulse one for each step (STEP) and a direction signal (DIR). nStepDir wraps that, with proper limit handling and unit conversion:
| Parameter | Description |
|---|---|
| Step Pin / Dir Pin | The two control GPIOs. |
| Dir Polarity | Flip the direction sense. |
| Unit / Scale | How many steps per unit of position you give it (e.g. steps per mm on a leadscrew). |
| Min Pos / Max Pos | Software end-stops — the module won't drive past these. |
| Max Speed | Top speed in steps/sec. |
A companion nStepDirController wraps the trajectory generation (acceleration ramps, queued moves) on top.
Open Examples/05-Control/StepDir for a minimal driver setup and Examples/05-Control/Stepper for the four-pin direct version.
DC motors — H-bridge driver wrappers
A DC motor needs direction + speed (PWM). The H-bridge driver chip does the level-shifting and the heavy lifting; NodeBlue ships pre-configured wrappers for the most common boards:
| Module / shield | Chip | Typical use |
|---|---|---|
| sMX1508 | MX1508 | The €1 mini-board on every hobby site. 1.5 A continuous, 2 channels. Brake / small toy motors / vibration motors. |
| L298N (example) | L298N | The classic dual H-bridge module. 2 A per channel. Robot wheels, mid-power loads. |
| sMotorDC (board-wiring class) | Various | Generic two-pin / three-pin DC driver wrapper for boards that have one fitted. |
The driver wrapper modules show up under the Motor-wiring palette category. You typically drop the right board module in, then a nPWMOutput per channel, and feed the channel a signed speed value (negative → reverse, positive → forward); the driver wrapper handles the direction-pin gymnastics.
Example projects:
- Motor_Control_MX1508 — MX1508 driver, signed speed, push-button forward/reverse.
- L298N — L298N classic.
- VNH5019_SpeedPot — high-current motor (the Pololu VNH5019) under analog-pot speed control.
- PWM_Dir — bare PWM + Direction wiring without a driver wrapper.
Tying motors into a control loop
A common pattern: a sensor reports a position, a target position arrives from somewhere, you want the motor to drive the error to zero. That's a classic P controller — see Examples/05-Control/P_Controller. The chain looks like:
Sensor → reading. Target → setpoint. →
nOpOffsetto compute (target − reading). →nOpGain(the P term). → driver (PWM + Direction).
For full PID you'd add an integrator (sum, see FloatSum) and a differentiator (difference per tick — usually built from a delayed copy and an nOpOffset). NodeBlue doesn't ship a single PID block — the building blocks above are flexible enough to express the family.
Picking a driver
| If your motor is… | Pick… |
|---|---|
| Cheap 28BYJ-48 stepper with ULN2003 | nStepper |
| Stepper with DRV8825 / TMC2209 / A4988 | nStepDir (+ nStepDirController for ramps) |
| Small DC / vibration motor | sMX1508 driver wrapper |
| Robot wheel-class motor | L298N example wiring |
| High-current motor (RC car, e-skate) | VNH5019 example wiring |
| Industrial servo with its own controller | nStepDir (most servo controllers speak STEP/DIR too) |
Next stop in the sim-racing pipeline: wheel bases and custom wheels.