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

udoo

v0.2.0

Published

UDOO GPIO abstraction library for Node.js & command line tool. (callback, promise, and synchronous styles supported)

Downloads

24

Readme

Logo

NPM NPM

node-udoo is a UDOO GPIO abstraction library for Node.js & command line tool. All shared GPIO pinouts described in the UDOO Pinout Diagram are supported.

This library provides user an option to develop UDOO apps on Node.js using asynchronous (both callback & promise styles) and synchronous patterns. However, it is strongly recommended to stick to Node.js' asynchronous (non-blocking I/O) style.

Demo Video

Demo Video on YouTube

Installation

$ npm install udoo

GPIOs Warnings

Please pay attention to the GPIOs Warnings section of the UDOO Starting Manual:

When changing i.MX6 GPIOs directions, it is necessary to pay special attention. New direction must be compatible with SAM3x8E pinout configuration and/or with the load of the physical pin.

If you are not interacting with SAM3X (or you don't really understand what this is all about), just reset all shared pinouts to INPUT mode on SAM3X (Arduino Due microcontroller) using this sketch file so you can move the potential direction conflict issue out of the way.

Usage

Blink example from Arduino Tutorials implemented in different styles:

Asynchronous Version w/ Callbacks

var udoo = require('udoo');

var led = udoo.outputPin(13),
    on = false;

(function loop() {
  led.set(on = !on, function () {
    setTimeout(loop, 1000);
  });
}());

Asynchronous Version w/ Promise (Q)

var udoo = require('udoo');

var led = udoo.outputPin(13),
    on = false;

(function loop() {
  led
    .set(on = !on)
    .done(function () {
      setTimeout(loop, 1000);
    });
}());

Asynchronous Version w/ Async.js

var udoo = require('udoo');

var led = udoo.outputPin(13),
    on = false;

udoo.async.forever(function (cb) {
  udoo.async.series([
    function (cb) {
      led.set(on = !on, cb);
    },
    function (cb) {
      setTimeout(cb, 1000);
    }
  ], cb);
});

Synchronous Version (not recommended)

var udoo = require('udoo');

var led = udoo.outputPin(13),
    on = false;

(function loop() {
  led.setSync(on = !on);
  setTimeout(loop, 1000);
}());

API

  • node-udoo API provides all these patterns: asynchronous style using callbacks, asynchronous style using promise, and synchronous style.

  • You will be tempted to use synchronous style because the code looks simpler and easier, however it is not the recommended way to program in Node.js.

  • All asynchronous API functions accept callback as the last parameter. Whether you pass a callback function or not, they will always return a promise object built using Q. You can do whatever you want with the returned promise, or stick with the traditional callback style.

  • Pin name can be any of key values in PIN_MAPPING.

// List all supported pinouts
.gpioNumbers()
.pinNames()

// Create new pin
.inputPin(pinName)
.outputPin(pinName)

// Pin getter/setter (append `Sync` for synchronous calls)
.get(callback)              // Returns `true` for high/1, `false` for low/0
.setHigh(callback)          // Sets true/high/1
.setLow(callback)           // Sets false/low/0
.set(value, callback)       // Sets (boolean) value

// Pin mode (append `Sync` for synchronous calls)
.getMode(callback)          // Returns one of `udoo.PIN_MODE.*`
.setInputMode(callback)     // Change to input mode
.setOutputMode(callback)    // Change to output mode

// Reset (calling on `udoo` resets all pinouts to `INPUT` mode)
.reset(callback)
.resetSync()

// Constants
.PIN_MODE
.PIN_MODE_INVERT

// Libraries exported
._                    // Lodash (underscore.js)
.Q                    // Q (promise)
.async                // Async.js

Command Line Tool

node-udoo comes with a convenient command line tool (udoo) for quick and easy control of UDOO GPIO pins. The command line tool can be installed using the following command:

$ sudo npm install udoo -g

Available Commands

$ udoo help
$ udoo high [<pinName> <pinName> ...]     # aliases: `udoo on`, `udoo 1`
$ udoo low [<pinName> <pinName> ...]      # aliases: `udoo off`, `udoo 0`
$ udoo reset [<pinName> <pinName> ...]
$ udoo blink [<pinName> <pinName> ...]

TODOs

Here is a list of various ports need to be supported. Please contribute to the node-udoo project by sending Pull Requests.

  1. ~~GPIO (all 51 shared GPIO pinouts described in the UDOO Pinout Diagram)~~
  2. PWM
  3. SPI
  4. UARTs
  5. I2C
  6. Can Bus
  7. USB-OTG
  8. DAC
  9. JTAG
  10. DMA

Credits

See the contributors.

License