Skip to content
/ A4988 Public

Use an A4988 stepper motor controller on a Raspberry Pi with node.js

License

Notifications You must be signed in to change notification settings

echicken/A4988

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A4988

Use an A4988 stepper motor controller on a Raspberry Pi with node.js

const A4988 = require('A4988');
const a4988 = new A4988({ step: 6, dir: 5 });
a4988.turn(5000).then(steps => console.log(`Turned ${steps} steps`));

Constructor

new A4988({ step: 26, dir: 19, ms1: 13, ms2: 6, ms3: 5, enable: 22 }); // ms1, ms2, ms3, and enable are optional

All parameters are BCM GPIO pin numbers wired to the corresponding A4988 pins.

The ms1, ms2, and ms3 parameters are optional, but required if you want microstepping (step_size below).

Properties

  • direction - boolean - Clockwise or counterclockwise, depending on wiring (I think)
  • delay - number - Milliseconds between steps (pulses) (default is 1, which works for me)
  • step_size - string - 'full', 'half', 'quarter', 'eighth', or 'sixteenth'
    • ms1, ms2, and ms3 must be wired up and provided to constructor
  • enabled - boolean - Enable or disable the controller. Set 'true' to enable (default), 'false' to disable. This is at odds with how the pin actually works (active-low) but is clearer.

Methods

  • turn(steps [, callback]) - Will fire callback when turn is complete (or aborted). If callback not given, returns a Promise
    • Return value (or callback param) is the number of steps actually taken, which may vary from steps if stop() was called and the turn was aborted prematurely.
  • stop() - Abort a turn in progress