Skip to content

Commit

Permalink
rewrite for 4.4 kernel
Browse files Browse the repository at this point in the history
* rewrite for 4.4 kernel
* upgrade to linux-io v0.5.7
* update tests
* add node.js v0.12, v4 and v6 to travis
* use g++ 4.8 on travis
* add node.js v5 and v7 to travis
* use ecap folder rather than pwm folder for pwm on p9_42
* redundant code removed
* redundant code removed
* readme updated and migration guide added
  • Loading branch information
fivdi authored and julianduque committed Apr 17, 2017
1 parent a090837 commit 33d8170
Show file tree
Hide file tree
Showing 23 changed files with 963 additions and 1,265 deletions.
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
- "7"
before_script:
- npm install -g grunt-cli
compiler: clang
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
10 changes: 5 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ module.exports = function(grunt) {
pkg: grunt.file.readJSON("package.json"),
nodeunit: {
tests: [
"test/beaglebone.js",
"test/not-implemented.js"
"test/beaglebone.js"
]
},
jshint: {
options: {
reporterOutput: "",
latedef: false,
curly: true,
eqeqeq: true,
Expand Down Expand Up @@ -50,13 +50,13 @@ module.exports = function(grunt) {
"Gruntfile.js",
"lib/**/*.js",
"test/**/*.js",
"eg/**/*.js"
"examples/**/*.js"
]
}
},

jsbeautifier: {
files: ["lib/**/*.js", "eg/**/*.js", "test/**/*.js"],
files: ["lib/**/*.js", "examples/**/*.js", "test/**/*.js"],
options: {
js: {
braceStyle: "collapse",
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports = function(grunt) {
"Gruntfile.js",
"lib/**/!(johnny-five)*.js",
"test/**/*.js",
"eg/**/*.js"
"examples/**/*.js"
],
tasks: ["default"],
options: {
Expand Down
181 changes: 145 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# BeagleBone-IO
BeagleBone Black IO Plugin for [Johnny-Five](http://johnny-five.io)
BeagleBone Black IO Plugin for [Johnny-Five](http://johnny-five.io).

Heavily based on [Galileo-IO](https://github.com/rwaldron/galileo-io) by [Rick Waldron](https://github.com/rwaldron)
BeagleBone-IO supports Node.js v0.10, v0.12, v4, v5, v6 and v7.

## News & Updates

### April-2017: Major changes for BeagleBone-IO v2.0.0

BeagleBone-IO v2.0.0 is a complete rewrite that fixes a number of
long-standing issues related to support for the Linux 4.4 kernel, support
for the latest versions of Node.js, additional pin support, performance
improvements and improved analog to digital conversion. This results in a
number of **BREAKING CHANGES** which are documented in the
[migration guide](https://github.com/julianduque/beaglebone-io#migrating-from-beaglebone-io-v1-to-v2).
Support for Linux kernel versions prior to 4.4 has been dropped.

## Install

Expand All @@ -10,27 +22,40 @@ $ npm install beaglebone-io
```

For the best user experience with BeagleBone-IO the recommended Operating
System is [Debian](http://beagleboard.org/latest-images). Debian supports
the runtime modification of the Device Tree which is a feature required
by BeagleBone-IO. If a directory matching the pattern
`/sys/devices/bone_capemgr.*` exists, the required support is available.
System is [Debian](http://beagleboard.org/latest-images).

## Usage

#### Standalone Usage of BeagleBone-IO

Turn built-in user LED 3 on and log the value of analog input A0 to the
console each time it changes. The BeagleBone Black has row of four built-in
blue LEDs mounted on the board itself. User LED 3 is the LED closest to
Ethernet port. It's possible to try this program without connecting any
hardware to the BeagleBone Black.

``` js
var BeagleBone = require('beaglebone-io');
var board = new BeagleBone();

board.on('ready', function () {
this.digitalWrite(13, this.HIGH);
this.pinMode('USR3', this.MODES.OUTPUT);
this.digitalWrite('USR3', this.HIGH);

this.pinMode('A0', this.MODES.ANALOG);
this.analogRead('A0', function (value) {
console.log(value);
});
});

```

With Johnny-Five
#### Using BeagleBone-IO with Johnny-Five

Blink the default LED with Johnny-Five. Built-in User LED 3 is the default
LED. It's possible to try this program without connecting any hardware to
the BeagleBone Black. For this program to run Johnny-Five also needs to
be installed with the command `npm install johnny-five`

``` js
var five = require('johnny-five');
var BeagleBone = require('beaglebone-io');
Expand All @@ -47,43 +72,127 @@ board.on('ready', function () {
});
```

## Pin Mappings
## Supported Pins

| Pin ID | Supported Modes | Comments |
|:----|:-----|:----|
| P8_7 or GPIO66 | INPUT, OUTPUT | |
| P8_8 or GPIO67 | INPUT, OUTPUT | |
| P8_9 or GPIO69 | INPUT, OUTPUT | |
| P8_10 or GPIO68 | INPUT, OUTPUT | |
| P8_11 or GPIO45 | INPUT, OUTPUT | |
| P8_12 or GPIO44 | INPUT, OUTPUT | |
| P8_13 or GPIO23 | INPUT, OUTPUT, SERVO, PWM | |
| P8_14 or GPIO26 | INPUT, OUTPUT | |
| P8_15 or GPIO47 | INPUT, OUTPUT | |
| P8_16 or GPIO46 | INPUT, OUTPUT | |
| P8_17 or GPIO27 | INPUT, OUTPUT | |
| P8_18 or GPIO65 | INPUT, OUTPUT | |
| P8_19 or GPIO22 | INPUT, OUTPUT, SERVO, PWM | |
| P8_26 or GPIO61 | INPUT, OUTPUT | |
| P9_11 or GPIO30 | INPUT, OUTPUT | |
| P9_12 or GPIO60 | INPUT, OUTPUT | |
| P9_13 or GPIO31 | INPUT, OUTPUT | |
| P9_14 or GPIO50 | INPUT, OUTPUT, SERVO, PWM | |
| P9_15 or GPIO48 | INPUT, OUTPUT | |
| P9_16 or GPIO51 | INPUT, OUTPUT, SERVO, PWM | |
| P9_17 or GPIO5 | INPUT, OUTPUT | |
| P9_18 or GPIO4 | INPUT, OUTPUT | |
| P9_19 | I2C2 SCL | Reserved for I2C |
| P9_20 | I2C2 SDA | Reserved for I2C |
| P9_21 or GPIO3 | INPUT, OUTPUT, SERVO, PWM | |
| P9_22 or GPIO2 | INPUT, OUTPUT, SERVO, PWM | |
| P9_23 or GPIO49 | INPUT, OUTPUT | |
| P9_24 or GPIO15 | INPUT, OUTPUT | |
| P9_26 or GPIO14 | INPUT, OUTPUT | |
| P9_27 or GPIO115 | INPUT, OUTPUT | |
| P9_30 or GPIO112 | INPUT, OUTPUT | |
| P9_33 or A4 | ANALOG | |
| P9_35 or A6 | ANALOG | |
| P9_36 or A5 | ANALOG | |
| P9_37 or A2 | ANALOG | |
| P9_38 or A3 | ANALOG | |
| P9_39 or A0 | ANALOG | |
| P9_40 or A1 | ANALOG | |
| P9_41 or GPIO20 | INPUT, OUTPUT | |
| P9_42 or GPIO7 | INPUT, OUTPUT, SERVO, PWM | |
| USR0 | OUTPUT | Built-in user LED 0 |
| USR1 | OUTPUT | Built-in user LED 1 |
| USR2 | OUTPUT | Built-in user LED 2 |
| USR3 | OUTPUT | Built-in user LED 3 / Default LED |

## Migrating from BeagleBone-IO v1 to v2

There are two **BREAKING CHANGES** in BeagleBone-IO v2 that need to be taken
into account when migrating from v1 to v2. Both breaking changes can be seen
when the following v1 program

BeagleBone Black to Arduino UNO
``` js
var BeagleBone = require('beaglebone-io');
var board = new BeagleBone();

board.on('ready', function () {
this.digitalWrite(12, this.HIGH);
});
```

is compared with its v2 equivalent.

``` js
var BeagleBone = require('beaglebone-io');
var board = new BeagleBone();

board.on('ready', function () {
this.pinMode('P8_14', this.MODES.OUTPUT);
this.digitalWrite('P8_14', this.HIGH);
});
```

#### Arduino Pin Numbers

In v1 each pin had a documented Arduino pin number.

| BBB Port | Arduino Pin | Type |
|----------|-------------|------|
|P8_7|0|Digital|
|P8_8|1|Digital|
|P8_9|2|Digital|
|P8_13|3|PWM|
|P8_10|4|Digital|
|P9_14|5|PWM|
|P9_16|6|PWM|
|P8_11|7|Digital|
|P8_12|8|Digital|
|P9_21|9|PWM|
|P9_42|10|PWM|
|P8_19|11|PWM|
|P8_14|12|Digital|
|USR3|13|Digital / Default Led|
|P9_39|A0|Analog Input|
|P9_40|A1|Analog Input|
|P9_37|A2|Analog Input|
|P9_38|A3|Analog Input|
|P9_35|A4|Analog Input|
|P9_36|A5|Analog Input|

For I2C:
In v2 this is no longer the case.

| Pin ID | Supported Modes | Comments |
|:----|:-----|:----|
| P8_14 or GPIO26 | INPUT, OUTPUT | |

In v2 pin IDs should be used in place of Arduino pin numbers. For example,
the following v1 code

``` js
this.digitalWrite(12, this.HIGH);
```

should be replaced with the following v2 code.

``` js
this.pinMode('P8_14', this.MODES.OUTPUT);
```

#### Setting Pin Modes Implicitly

The observant reader may also have noticed the addition of the following line
of code to the v2 example code above.

``` js
this.pinMode('P8_14', this.MODES.OUTPUT);
```

| BBB Port | Type |
| ---------- | -------- |
| P9_20 | I2C SDA |
| P9_19 | I2C SCL |
In v1 calling `digitalWrite` implicitly set the mode of the appropriate pin
to OUTPUT. In v2 pin modes are no longer implicitly set. Note that if you
don't call IO Plugin methods like `digitalWrite` directly yourself then
there is nothing to do here as Johnny-Five will explicitly set pin modes
to the appropriate values.

## The MIT License (MIT)

Copyright (c) Julian Duque, Alan Yorinks, Brian Cooke 2014
Copyright (c) Julian Duque, Alan Yorinks, Brian Cooke 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 17 additions & 0 deletions examples/built-in-leds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var five = require('johnny-five');
var BeagleBone = require('..');

var board = new five.Board({
io: new BeagleBone()
});

board.on('ready', function() {
var led2 = new five.Led('USR2'),
led3 = new five.Led('USR3');

led2.blink(500);
led3.blink(500);
});

21 changes: 21 additions & 0 deletions examples/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

var five = require('johnny-five');
var BeagleBone = require('..');

var board = new five.Board({
io: new BeagleBone()
});

board.on('ready', function() {
var button = new five.Button('GPIO47');

button.on('down', function() {
console.log('down');
});

button.on('up', function() {
console.log('up');
});
});

29 changes: 29 additions & 0 deletions examples/digital-write-performance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var five = require('johnny-five');
var BeagleBone = require('..');

var board = new five.Board({
io: new BeagleBone()
});

board.on('ready', function() {
var pin = board.io.normalize('GPIO46'),
writesPerSecond,
time,
i;

this.pinMode(pin, five.Pin.OUTPUT);

time = process.hrtime();

for (i = 1; i <= 250000; i += 1) {
this.digitalWrite(pin, i & 1);
}

time = process.hrtime(time);
writesPerSecond = Math.floor(i / (time[0] + time[1] / 1E9));

console.log(writesPerSecond + ' digitalWrite calls per second');
});

28 changes: 28 additions & 0 deletions examples/i2c-accelerometer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var five = require('johnny-five');
var BeagleBone = require('..');

var board = new five.Board({
io: new BeagleBone()
});

board.on('ready', function() {
var accelerometer = new five.Accelerometer({
controller: "ADXL345"
});

accelerometer.on("change", function() {
console.log("accelerometer");
console.log(" x : ", this.x);
console.log(" y : ", this.y);
console.log(" z : ", this.z);
console.log(" pitch : ", this.pitch);
console.log(" roll : ", this.roll);
console.log(" acceleration : ", this.acceleration);
console.log(" inclination : ", this.inclination);
console.log(" orientation : ", this.orientation);
console.log("--------------------------------------");
});
});

Loading

0 comments on commit 33d8170

Please sign in to comment.