Skip to main content

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:

ModuleUse it when
nStepperThe MCU drives the coils directly through four GPIO pins — typical of cheap bipolar/unipolar steppers with a basic driver IC (ULN2003 etc.).
nStepDirThe MCU drives a dedicated stepper driver (DRV8825, TMC2209, A4988 …) that takes only STEP and DIR signals.

nStepper — direct coil control​

ParameterDescription
Pin 1 / 2 / 3 / 4Four GPIOs wired to the coils (or the input pins of a coil-driver chip).
SpeedStep 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:

ParameterDescription
Step Pin / Dir PinThe two control GPIOs.
Dir PolarityFlip the direction sense.
Unit / ScaleHow many steps per unit of position you give it (e.g. steps per mm on a leadscrew).
Min Pos / Max PosSoftware end-stops — the module won't drive past these.
Max SpeedTop 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 / shieldChipTypical use
sMX1508MX1508The €1 mini-board on every hobby site. 1.5 A continuous, 2 channels. Brake / small toy motors / vibration motors.
L298N (example)L298NThe classic dual H-bridge module. 2 A per channel. Robot wheels, mid-power loads.
sMotorDC (board-wiring class)VariousGeneric 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. → nOpOffset to 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 ULN2003nStepper
Stepper with DRV8825 / TMC2209 / A4988nStepDir (+ nStepDirController for ramps)
Small DC / vibration motorsMX1508 driver wrapper
Robot wheel-class motorL298N example wiring
High-current motor (RC car, e-skate)VNH5019 example wiring
Industrial servo with its own controllernStepDir (most servo controllers speak STEP/DIR too)

Next stop in the sim-racing pipeline: wheel bases and custom wheels.