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

brickpi

v0.1.0

Published

Node.js bindings for the BrickPi

Downloads

5

Readme

node-brickpi

Node.js bindings for the BrickPi.

Usage

var BrickPi = require('brickpi')

var brickPi = new BrickPi('/dev/ttyAMA0', function() {
  brickPi.led(0).on()
})

Constructor options

All arguments are optional and order is not important.

Pass a string (path to a serial device), an options object and a callback function to invoke when the BrickPi is ready to use.

Default options are as follows:

var brickPi = new BrickPi({
    baudrate: 500000, // the speed of the connection to the BrickPi
    timeout: 10000, // stop the motors if no communication is received in this time period (ms)
    debug: false // whether to print verbose debug output
})

LED

The BrickPi has two LEDs that can be accessed by passing an index to the led function:

var led1 = brickPi.led(0)
var led2 = brickPi.led(1)

An LED supports several methods:

brickPi.led(0).on() // turn the LED on
brickPi.led(0).off() // turn the LED off
brickPi.led(0).toggle() // if the LED is on, turn it off, otherwise turn it on

Motors

var motor = brickPi.addMotor(new BrickPi.Motor(), BrickPi.PORTS.MA)

// later
motor.speed(255) // continuous motion - full speed ahead
motor.speed(0) // stop
motor.speed(-255) // reverse

// rotation
motor.rotate(180) // rotate 180 degrees
motor.rotate(-180) // rotate 180 degrees in the opposite direction

// optionally specify a speed
motor.rotate(180, 255) // rotate 180 degrees at full speed
motor.rotate(180, 128) // rotate 180 degrees at half speed

brickPi.once('emergencyStop', function() {
    console.info('stopped!')
})
brickPi.emergencyStop() // immediately stop all motors

Sensors

Valid sensor types are Distance, Light, Sound and Touch.

// add sensors
var distance = brickPi.addSensor(new BrickPi.Sensors.NXT.Distance(), BrickPi.PORTS.S1)
var light = brickPi.addSensor(new BrickPi.Sensors.NXT.Light(), BrickPi.PORTS.S2)
var sound = brickPi.addSensor(new BrickPi.Sensors.NXT.Sound(), BrickPi.PORTS.S3)
var touch = brickPi.addSensor(new BrickPi.Sensors.NXT.Touch(), BrickPi.PORTS.S4)

// later
distance.value(function(error, value) {
    // value is 0-255 in cm
}) 
light.value(function(error, value) {
  // value is 0-100 in %
})
sound.value(function(error, value) {
  // value is 0-100 in %
})
touch.value(function(error, value) {
  // value is true or false
})

Notes

What about EV3, NXT2, etc?

I only have the NXT kit, sorry. Hardware donations and/or pull requests gratefully accepted.

Why is the motor control so imprecise?

NXT motors are continuous servos equipped with encoders. This means that you tell the motor how fast to spin then read the encoders to work out what position the motor is in. Once it reaches the desired location, you stop the motor. Because the motor is a mechanical device stopping it involves it slowing down before stopping completely by which point it will most likely be slightly past the desired location. Normal servos do not have this problem because the PWM duty cycle set corresponds to a given orientation of the servo horn.

What about sensor port 5?

The second generation BrickPi has five sensor ports. This driver has been ported from the Python version which doesn't support the fifth sensor port. If a driver that does support it emerges I can add support.