🏁 motor-hat 🎩
Node Module to control Adafruit's MotorHAT for the Raspberry Pi http://jcane86.github.io/motor-hat
Installation & Basic Usage
$ npm install --save motor-hat
var motorHat = steppers: W1: 'M1' W2: 'M2' ;motorHatsteppers0;motorHatsteppers0;
DOCS
- See the full api here: http://jcane86.github.io/motor-hat
- See it on GitHub here: http://github.com/jcane86/motor-hat
Notes about 2.0
Some changes will need to be made to transition to the async version of the library in 2.0:
Main library:
- Instance needs to be init()'d
- Servo and Stepper instances exposed in servos and steppers arrays are already init()'d.
DC Motors:
- Methods are now async, and need a callback as last parameter.
- Old Sync methods remain, just call them as stopSync(), etc..
- Instance needs to be init()'d
Servo Motors:
- No changes, everything is still sync (I didn't feel it was necessary, feel free to open an issue or send a PR otherwise).
Stepper Motors:
- Most methods already had the Sync suffix. Only setFrequency is now setFrequencySync.
- Async methods added.
- Release and current methods added (actually in 1.3).
- Instance needs to be init()'d
Advanced usage
// get a motor-hat instance with the following initialized:// * a non-default I2C address for the motor hat (default is 0x6F)// * a stepper with winding one on 'M1' and winding two on 'M2' ports// * a dc motor on port 'M4'// * a servo on channel 0// * a servo on channel 14let spec = address: 0x60 steppers: W1: 'M1' W2: 'M2' dcs: 'M4' servos: 014;var motorHat = spec; // Since MotorHat 2.0, the instance needs to be initialized.// This is to enable async initialization, feel free to open an issue if this is a pain.motorHat; // For steppers, set speed in rpm or pps (pulses per second) or sps (steps per second).// To set it in rpm, set you steps/rev first (default 200)// If you set it in pps, the speed will not be constant for different styles or number of microsteps.motorHatsteppers0;motorHatsteppers0; // Move the motor one full turn fwds synchronously, one back async.// step[Sync] and oneStep[Sync] take number of steps as input, // depending on selected style. To do 2048 full steps fwd (sync), 2048 back (async):motorHatsteppers0;motorHatsteppers0;
Further configuration
// Supported syles are 'single', 'double' (default), 'interleaved', and 'microstep'motorHatsteppers0;// Supported number of microsteps are 8 and 16 (8 by default)motorHatsteppers0;// step[Sync] and oneStep[Sync] take number of steps/halfsteps/microsteps as input, // depending on selected style. To do 16 microsteps fwd:motorHatsteppers0;// Set current at 50% to avoid overheating or to run at lower torquesmotorHatsteppers0;// Release motor after moving it to avoid overheating or to let it move freely.motorHatsteppers0; // Calibrate the servo output. Pass in PWM frequency, position 0 pulse duration in ms,// position 100 pulse duration in ms.motorHatservos0;// Move to position 0motorHatservos0;// Move to position 100motorHatservos0; // Start dc motor forward (by default at 100% speed)motorHatdcs0;// Set DC motor speed to 50%motorHatdcs0;// reverse the dc motor to back directionmotorHatdcs0;// stop the dc motormotorHatdcs0;
As seen in
Some of our friends made cool stuff using motor-hat. Drop us a PR to add your project to this list.
- @joeljameswatson : Laser Mandala, a really cool remote controlled lights show (joeljameswatson/laser-mandala)
License
MIT © J. Cane