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

wpi-stepper

v0.1.5

Published

Stepper motor module for WiringPi-Node

Downloads

17

Readme

wpi-stepper

A WiringPi Stepper Motor Control Module

by Mike Green

Introduction

wpi-stepper is a flexible control class for stepper motors, written using the excellent WiringPi-Node library. If you find yourself in need of such a module, give it a try.

I wrote wpi-stepper for a few reasons:

  • I'm a web developer by trade. I'm most comfortable programming in JavaScript.
  • My wife and I keep chickens (20 laying hens and a rotating cast of broilers, if you're curious).
  • We built an automatic sliding door for our chicken coop that uses a stepper motor.
  • All existing stepper control modules I could find in JS either don't work, can't be installed in current versions of Node, or require you to wire your motor to the driver in a way that makes no rational sense.

wpi-stepper allows you to wire your motor and controller however you prefer, and you can also program your own pin activation sequences by simply feeding some arrays of 1's and 0's to the Stepper class. I can see this being useful not only for driving stepper motors, but also for controlling anything that requires a repeating sequence of activation and deactivation.

Note: This library uses WiringPi to toggle GPIO pins, which means that it must be run as root in order to work. If you're not running as root, your script will bail when WiringPi tries and fails to initialize.

Installation

npm install --save wpi-stepper

Usage

ES5 Module

Pre-compiled to ES5 with Babel and the es2015-node preset:

var Stepper = require('wpi-stepper').Stepper;

ES6 Module

The raw ES6 source, if you're transpiling it yourself:

import { Stepper } from 'wpi-stepper/es6/lib/stepper';

Example

const pins = [
  17, // A+
  16, // A-
  13, // B+
  12  // B-
];
const motor = new Stepper({ pins, steps: 200 });

motor.speed = 20; // 20 RPM

// Move the motor forward 800 steps (4 rotations), logging to console when done:
motor.move(800).then(() => console.log('motion complete'));

Additionally, Stepper is an EventEmitter, so you can subscribe to various events emitted by the class throughout its life cycle:

motor.on('start', () => console.log('Starting to move!'));
motor.on('cancel', () => console.log('Stopping that. Doing this instead!'));
motor.on('complete', () => console.log('I\'m all finished!'));

motor.move(800);
motor.move(-800);

// => "Starting to move!"
// => "Stopping that. Doing this instead!"
// => "Starting to move!"
// (a few seconds later...)
// => "I'm all finished!"

Custom Activation Modes

wpi-stepper comes configured for a 4-wire stepper motor out of the box, and thus far that's all I've tested it with. However, you can easily use the Stepper class to drive other types of motors with different numbers of wires by passing it a custom mode option when you initialize an instance.

Activation modes are arrays of arrays, whose inner members are either 1 or 0 and correspond to each pin, in the order you first specified them. wpi-stepper exports two available activation modes out of the box, and they look like this:

DUAL (this is the default mode)

Use this activation mode if you're driving a bipolar, 4-wire stepper motor:

import { MODES, Stepper } from 'wpi-stepper';

const pins = [ 17, 16, 13, 12 ];
const mode = MODES.DUAL;
/*
[
  [ 1, 0, 0, 1 ], // Pin states: (17: on, 16: off, 13: off, 12: on)
  [ 0, 1, 0, 1 ],
  [ 0, 1, 1, 0 ],
  [ 1, 0, 1, 0 ]
]
*/

const motor = new Stepper({ pins, mode });

SINGLE (for unipolar motors)

import { MODES, Stepper } from 'wpi-stepper';

const pins = [ 17, 16, 13, 12 ];
const mode = MODES.SINGLE;
/*
[
  [ 1, 0, 0, 0 ], // Pin states: (17: on, 16: off, 13: off, 12: off)
  [ 0, 1, 0, 0 ],
  [ 0, 0, 1, 0 ],
  [ 0, 0, 0, 1 ]
]
*/

const motor = new Stepper({ pins, mode });

As the motor turns, the Stepper class will step through these activation modes and apply the appropriate states to the pins you register. For both of the included modes, the pattern repeats every 4 steps. This can and should vary depending on how many wires your motor has.

Half-Stepping

TODO

Full API

See the API documentation.

License

wpi-stepper is released under the terms of the MIT License.