All Projects → jcane86 → motor-hat

jcane86 / motor-hat

Licence: MIT license
Node Module to control Adafruits MotorHAT for the RaspberryPi

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to motor-hat

la-maison-pythonic
Projet didactique du livre "Python, Raspberry-Pi et Flask" avec ESP8266 sous MicroPython
Stars: ✭ 16 (-42.86%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
yamete
Yamete - Hentai downloader in PHP CLI - Easy site downloader PHP system
Stars: ✭ 63 (+125%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
wor-flasher
Legal utility that runs on RPiOS to flash another SD card with Windows 10/11
Stars: ✭ 451 (+1510.71%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
Raspberrypi tempmon
Raspberry pi CPU temperature monitor with many functions such as logging, GPIO output, graphing, email, alarm, notifications and stress testing. Python 3.
Stars: ✭ 52 (+85.71%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
Homekitcam
A project to make a Raspberry Pi driven, HomeKit Enabled camera.
Stars: ✭ 69 (+146.43%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
Debian Pi Aarch64
This is the first 64-bit system in the world to support all Raspberry Pi 64-bit hardware!!! (Include: PI400,4B,3B+,3B,3A+,Zero2W)
Stars: ✭ 2,505 (+8846.43%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
Gitlab
GitLab CE (Docker image) for ARM devices, this is a mirror repository of
Stars: ✭ 121 (+332.14%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
RPi-TELEBOT
Python based Telegram bot to monitor and control the raspberry pi
Stars: ✭ 19 (-32.14%)
Mutual labels:  raspberrypi, raspberry, raspberry-pi-3
FaceGuard
Face Guard: Machine Learning + IoT Surveillance demo! Face recognition
Stars: ✭ 13 (-53.57%)
Mutual labels:  raspberry, raspberry-pi-3
PiHueEntertainment
An application that can handle the Hue Entertainment Areas on a Raspberry Pi
Stars: ✭ 28 (+0%)
Mutual labels:  raspberrypi, raspberry-pi-3
Three-Factor-Security-Door
What do you get when you mix a Raspberry Pi, a MySQL database, an RFID reader, an LCD touchscreen, a relay switch, an electronic door strike and a Twilio SMS account?
Stars: ✭ 49 (+75%)
Mutual labels:  raspberry, raspberry-pi-3
ControlBlockService2
This is the driver for the ControlBlock re.v 2.X, a power switch and input/output/gameapd gadget for the Raspberry Pi
Stars: ✭ 18 (-35.71%)
Mutual labels:  raspberrypi, raspberry
SimpleStepper
A bare minimum but really fast and simple stepper library for Arduino.
Stars: ✭ 21 (-25%)
Mutual labels:  stepper-motor, stepper-library
TinyChat
💬 Extra small chat client with GUI
Stars: ✭ 15 (-46.43%)
Mutual labels:  raspberrypi, raspberry
warpi
"GUI" script running on a Raspberry Pi 4
Stars: ✭ 29 (+3.57%)
Mutual labels:  raspberry, raspberry-pi-3
Comitup
Bootstrap Wifi support over Wifi
Stars: ✭ 190 (+578.57%)
Mutual labels:  raspberrypi, raspberry-pi-3
rpi-backup
raspberry pi backup,树莓派系统备份,最小镜像备份
Stars: ✭ 213 (+660.71%)
Mutual labels:  raspberrypi, raspberry
SmartMirror
Raspberrry Pi powered smart mirror inspired by HackerHouseYT Smart Mirror project
Stars: ✭ 16 (-42.86%)
Mutual labels:  raspberrypi, raspberry-pi-3
MyIoT
[MyIoT] A start with personal server for home automation
Stars: ✭ 14 (-50%)
Mutual labels:  raspberrypi, raspberry-pi-3
EEGwithRaspberryPI
Open-Source board for converting RaspberryPI to Brain-computer interface
Stars: ✭ 402 (+1335.71%)
Mutual labels:  raspberrypi, raspberry-pi-3

🏁 motor-hat 🎩

NPM version Build Status Dependency Status Coverage percentage semantic-release Commitizen friendly Gitter badge

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 = require('motor-hat')({steppers: [{ W1: 'M1', W2: 'M2' }]}).init();
motorHat.steppers[0].setSpeed({pps:100});
motorHat.steppers[0].step('back', 2048, (err, result) => {
  if (err) return console.log('Oh no, there was an error', err);
  console.log(`Did ${result.steps} steps ${result.dir} in ${result.duration/1000} seconds. I had to retry ${result.retried} steps because you set me up quicker than your poor board can handle.`); 
});

DOCS

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 14
let spec = {
    address: 0x60,
    steppers: [{ W1: 'M1', W2: 'M2' }],
    dcs: ['M4'],
    servos: [0,14]
};
var motorHat = require('motor-hat')(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.init();

// 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.
motorHat.steppers[0].setSteps(2048);
motorHat.steppers[0].setSpeed({rpm:5});

// 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):
motorHat.steppers[0].stepSync('fwd', 2048);
motorHat.steppers[0].step('back', 2048, function(err, result) {
  if (err) {
    console.log('Oh no, there was an error');
  } else {
    // Move on..
  }
});

Further configuration

// Supported syles are 'single', 'double' (default), 'interleaved', and 'microstep'
motorHat.steppers[0].setStyle('microstep');
// Supported number of microsteps are 8 and 16 (8 by default)
motorHat.steppers[0].setMicrosteps(16);
// step[Sync] and oneStep[Sync] take number of steps/halfsteps/microsteps as input, 
// depending on selected style. To do 16 microsteps fwd:
motorHat.steppers[0].stepSync('back', 16);
// Set current at 50% to avoid overheating or to run at lower torques
motorHat.steppers[0].setCurrent(0.5);
// Release motor after moving it to avoid overheating or to let it move freely.
motorHat.steppers[0].release((err) => !err && console.log("IT'S FREE!!"));


// Calibrate the servo output. Pass in PWM frequency, position 0 pulse duration in ms,
// position 100 pulse duration in ms.
motorHat.servos[0].calibrate(50, 1, 2);
// Move to position 0
motorHat.servos[0].moveTo(0);
// Move to position 100
motorHat.servos[0].moveTo(100);


// Start dc motor forward (by default at 100% speed)
motorHat.dcs[0].runSync('fwd');
// Set DC motor speed to 50%
motorHat.dcs[0].setSpeedSync(50);
// reverse the dc motor to back direction
motorHat.dcs[0].runSync('back');
// stop the dc motor
motorHat.dcs[0].stopSync();

As seen in

Some of our friends made cool stuff using motor-hat. Drop us a PR to add your project to this list.

License

MIT © J. Cane

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].