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 🙏

© 2026 – Pkg Stats / Ryan Hefner

zeropi

v0.0.5

Published

A node 5.0.0+ module for running a zeropi

Downloads

6

Readme

ZeroPi node module for RaspberryPi

Build Status

I took it upon myself to rewrite the original node module developed by the creators of ZeroPi, which can be found here.

The function names are the same, and so are the arguments passed to them. I just felt like the original code needed 'a bit of work'.

Prerequisites

Hardware

You will need the following:

  • A Raspberry Pi (I have tested it on a RPi 2)
  • A ZeroPi
  • A Power Supply (To run motor(s), I scavenged a 12v 1A DC PSU off an old Linksys router)
  • A Power Supply (To run the RPi)

The rest is up to you, I bought a Nema 23 Stepper motor and a stepper motor driver online to start me off.

Software

You will need the following:

  • An operating system on your RPi (I used Raspbian Jessie)
  • Node v5+

Hardware Setup

I will include the process I went through to get it all working, as I had a lot of trial and error. Hopefully it will help someone out in the same situation.

Setting up the Raspberry Pi

I followed the steps shown here

Configuring the Raspberry Pi

When you first log in you will need to stop Raspbian using the serial ports, so they are free for you to use.

  • In the terminal: sudo raspi-config
  • Select 'Advanced Options'
  • Select 'Serial'
  • Select 'No'

You will need to restart for the settings to take effect. Once rebooted you will have full control over the serial ports.

Configuring the ZeroPI

The ZeroPi requires firmware to be uploaded to it via the Arduino IDE. I had to do this bit on windows, because I couldn't get the board connected on Mac OSX (El Capitan).

Configuring Arduino IDE

Follow the steps shown here

Uploading the firmware

Follow the steps shown here

Connecting it all up

Once you have completed the setup of the Raspberry Pi and the ZeroPi has it's firmware uploaded, you can connect them together.

Setting up the Node Environment

If you have your own way of setting up node feel free to do it your way. I did the following:

  1. In terminal: sudo apt-get install npm
  2. Once npm is installed get 'n' which is a node version manager: sudo npm install n -g
  3. Once 'n' is installed get the latest version of node: n latest

This should download and install the latest version of node. To check: node --version (as of today that will be 6.0.0)

Setting up a node app with the ZeroPi node module

This will detail the setup of your application. If you know how to do this already, skip to Basic Usage.

  • Create a folder for your app in a location of your choice: mkdir MyApp
  • Enter the directory: cd MyApp
  • Initialise npm in the app: npm init
  • Fill in all the details to suit (or hit enter until finished to get a basic setup)
  • Use npm to install the zeropi module: npm install zeropi --save (this will save the reference to the module in your package.json file)
  • Create an index.js (or whatever you want to name it)

Basic Usage

npm install zeropi --save
const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();

zeropi.onOpen(() => {
  // The serial port has been opened successfully
  // We can do the business in here
  zeropi.stepperRun(0, 1000);
});

Note: you must always call the main methods after the serial port has been opened. Doing it before will have no effect

How Devices/Pins Work

Devices work differently based on what you are targeting:

DC motor

  • 0 = Slot 1 (1A+, 1A-)
  • 1 = Slot 2 (1B+, 1B-)
  • 2 = Slot 3 (2A+, 2A-)
  • 3 = Slot 4 (2B+, 2B-)
  • and so on...

Stepper motor

  • 0 = Slot 1 (1A+, 1A-, 1B+, 1B-)
  • 1 = Slot 2 (2A+, 2A-, 2B+, 2B-)
  • 2 = Slot 3 (3A+, 3A-, 3B+, 3B-)
  • 3 = Slot 4 (4A+, 4A-, 4B+, 4B-)

Servos

  • 0 = A0
  • 1 = A1
  • 2 = A2
  • 3 = A3
  • 4 = MO
  • 5 = MI
  • 6 = SCK
  • 7 = SDA
  • 8 = SCL

Methods

The methods mirror the original module exactly. I will list them here for convenience.

digitalWrite

digitalWrite(pin, level)

  • Pin: number (I don't know what the range is at the moment...)
  • Level: number
const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Turn the blue LED off
  zeropi.digitalWrite(13, 0);

  // Turn it back on after 5 seconds
  setTimeout(() => zeropi.digitalWrite(13, 1), 5000);
});

pwmWrite

pwmWrite(pin, pwm)

See here for an explanation of PWM

  • Pin: number (I don't know what the range is at the moment...)
  • PWM: -255 - 255
const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Use pwm to flash the led
  zeropi.digitalWrite(13, 64);
});

digitalRead

digitalRead(pin, callback)

  • Pin: number (I don't know what the range is at the moment...)
  • Callback: function
const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Get the level of pin 13
  zeropi.digitalRead(13, level => {
    console.log('Read: ', level);
  });
});

analogRead

analogRead(pin, callback)

  • Pin: number (I don't know what the range is at the moment...)
  • Callback: function
const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Get the level of pin 1
  zeropi.analogRead(1, level => {
    console.log('Read: ', level);
  });
});

dcMotorRun

dcMotorRun(device, pwm)

See here for an explanation of PWM

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Run the motor on slot 1 at 25% Duty Cycle
  zeropi.dcMotorRun(0, 64);
});

dcMotorStop

dcMotorStop(device)

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Stop DC motor in slot 1
  zeropi.dcMotorStop(0);
});

stepperRun

stepperRun(device, speed)

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Run stepper motor continuosly on slot 1 at speed 1000
  zeropi.stepperRun(0, 1000);
});

stepperMove

stepperMove(device, distance, speed, callback)

  • Device: see How Devices/Pins Work
  • Distance: Any number (both positive and negative)
  • Speed: 0 - 20000
  • Callback: function
const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Move stepper motor in slot 1 1000 steps at speed 1000
  zeropi.stepperMove(0, 1000, 1000, () => {
    console.log('Stepper motor move complete');
  });
});

stepperMoveTo

stepperMoveTo(device, position, speed, callback)

  • Device: see How Devices/Pins Work
  • Position: Any number (both positive and negative)
  • Speed: 0 - 20000
  • Callback: function
const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Move stepper motor in slot 1 to position 1000 steps at speed 1000
  zeropi.stepperMoveTo(0, 1000, 1000, () => {
    console.log('Stepper motor move to complete');
  });
});

stepperStop

stepperStop(device)

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Stop stepper motor in slot 1
  zeropi.stepperStop(0);
});

steppersEnable

steppersEnable()

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Enable all stepper motors
  zeropi.steppersEnable();
});

steppersDisable

steppersDisable()

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Disable all stepper motors
  zeropi.steppersDisable();
});

stepperSetting

stepperSetting(device, microstep, acceleration)

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Set settings for stepper motor in slot 1
  zeropi.stepperSetting(0, 2, 1000);
});

servoRun

servoRun(device, angle)

const ZeroPi = require('zeropi');

const zeropi = new ZeroPi();
zeropi.onOpen(() => {
  // Move servo on pins A0 to 90 degrees
  zeropi.servoRun(0, 90);
});

Contribution and Collaboration

At a stretch I am a beginner when it comes to electronics, I am a software developer by trade. Most of my information has been gleaned via Google searches... So I welcome feedback.

If you want to make a contribution to improve any aspect of this node module please feel free to put up a pull request. I will try to keep the module as up to date as possible.