bot-io

1.0.2 • Public • Published

bot-io

ADC, GPIO, PWM, UARTs, and more with Node.js on the BeagleBone Black.

Features

  • LEDs - Light Emitting Diodes
  • Buttons and Switches
  • ADC - Analog to Digital Conversion
  • GPIO - General Purpose Input Output
  • PWM - Pulse Width Modulation
  • UART - Serial Communication

Installation

$ npm install bot-io

News & Updates

bot-io v1.0.0 - March 28th 2016

bot-io v1.0.0 dropped support for the 3.8.x kernel and added support for the 4.1.x-ti kernel. bot-io v0.1.1 was the last version of bot-io that supported the 3.8.x kernel. All versions of bot-io require cape manager support.

For further information about breaking changes introduced with v1.0.0 see Migrating from bot-io v0.1.1 to v1.0.0

Note that cape_universal should be disabled when using bot-io. This can be achieved by editing /boot/uEnv.txt and modifing the following line

cmdline=coherent_pool=1M quiet cape_universal=enable

to

cmdline=coherent_pool=1M quiet

Usage

LEDs

Let's start off with something simple that doesn't require any hadrware other than the BeagleBone Black itself. The following example will blink onboard user LED0 at a frequency of 1Hz.

var bot = require('bot-io'),
  led0 = new bot.Led(bot.Led.USR0);
 
led0.once('ready', function () {
  // Blink at 1Hz. Period = 1000ms, on for 500ms, off for 500ms.
  led0.blink();
});

The next example heartbeats all four onboard user LEDs at 100Hz.

var bot = require('../'),
  Led = bot.Led,
  leds;
 
leds = [Led.USR0, Led.USR1, Led.USR2, Led.USR3].map(function (usrledName) {
  return new Led(usrledName);
});
 
bot.once('ready', leds, function () {
  leds.forEach(function (led) {
    led.heartbeat();
  });
});

Buttons

Toggle the state of an LED every time a button is pressed.

var bot = require('bot-io'),
  button = new bot.Button(bot.pins.p9_24),
  led = new bot.Led(bot.pins.p9_26),
  ledState = 0;
 
button.on('pressed', function () {
  led.value(ledState ^= 1);
});

PWM - Pulse Width Modulation

Fade an LED on and off once per second.

var bot = require('bot-io'),
  led = new bot.Pwm(bot.pins.p9_42);
 
led.once('ready', function () {
  var period = led.period(),
    duty = 0,
    delta = period / 50;
 
  (function updateDuty() {
    led.duty(duty);
 
    duty += delta;
 
    if (duty < 0 || duty > period) {
      delta = -delta;
      duty += delta;
    }
 
    setTimeout(updateDuty, 10);
  }());
});

ADC - Analog to Digital Conversion

Determine the ambient light level with an analog ambient light sensor.

var bot = require('bot-io'),
  ain = new bot.Ain(bot.pins.p9_36);
 
ain.once('ready', function () {
  setInterval(function () {
    console.log('value: ' + ain.value() + ', rawValue: ' + ain.rawValue());
  }, 1000);
});

Documentation

Classes

  • Ain - Analog to Digital Conversion
  • Button - Buttons and Switches
  • Gpio - General Purpose Input Output
  • Led - Light Emitting Diodes
  • Pwm - Pulse Width Modulation
  • Uart - Serial Communication

Objects

Functions

  • once - One Time Listener

Additional Information

Tested on a BeagleBone Black rev. A5C with

  • Debian Jessie 8.3 2016-03-20, Kernel 4.1.18-ti-r53, and Node.js v0.12.12

Package Sidebar

Install

npm i bot-io

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • fivdi