npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

motor-hat

v2.0.10

Published

Node Module to control Adafruits MotorHAT for the RaspberryPi

Downloads

65

Readme

🏁 motor-hat 🎩

NPM version Build Status Dependency Status Coverage percentage semantic-release Commitizen friendly Greenkeeper badge 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