8000 Various changes from Upstream by tjanson · Pull Request #3 · ni-c/duino · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Various changes from Upstream #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Oct 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1dc1277
port is now manually configurable
setola Sep 2, 2012
737ef75
little improve in documentation
setola Sep 2, 2012
a4cd6a0
Merge https://github.com/ecto/duino
setola Dec 11, 2012
343454d
Added example of configurable port
setola Dec 11, 2012
fa22983
fixed grep syntax error on board auto searching feature
setola Dec 11, 2012
99dc318
Documentation for parameter 'device' of the object Board
setola Dec 11, 2012
7bdbd9f
update readme with stuff found in code
natevw Jan 2, 2013
6826816
fix off by one error initing val/aux buffers
natevw Jan 3, 2013
d61ef40
first go at handling commands device-side — this really won't work du…
natevw Jan 3, 2013
0091297
Revert "first go at handling commands device-side — this really won't…
natevw Jan 3, 2013
b337ee3
(not working) partial port of LiquidCrystal.cpp
natevw Jan 4, 2013
88441b0
fix some issues, including swapped display flag that was the main tro…
natevw Jan 4, 2013
3c5df29
fill in most remaining methods
natevw Jan 4, 2013
e4f05ca
implement createChar (with helper options) and fix `write(int)`
natevw Jan 4, 2013
da3b074
allow options.pins to leave out .rw
natevw Jan 4, 2013
7d7ef3c
add documentation and rev version for LCD work (sponsored by &yet)
natevw Jan 4, 2013
a3822af
Merge pull request #31 from natevw/master
Jul 14, 2013
cf4421e
Merge pull request #27 from setola/master
Jul 24, 2013
b4c7610
bump version to 0.0.9
Jul 24, 2013
05bd409
board.js updated to allow Raspberry Pi 'Arduino board' serial ports t…
Pi-Uno Apr 14, 2014
fbe78fc
Merge pull request #47 from Pi-Uno/master
ecto Apr 14, 2014
86981ed
Use `chalk` for color log instead of `colors`
tjanson Oct 3, 2014
fb115ef
Added support for rc-switch
ni-c Feb 19, 2013
dd7c08a
Added IR Remote support
ni-c Mar 3, 2013
425b625
Merge branch 'master' into HEAD
tjanson Oct 4, 2014
546ec6b
Arduino sketch `duino` moved to valid location
tjanson Oct 9, 2014
15b5767
better Arduino device regexp
tjanson Oct 9, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ The way this works is simple (in theory, not in practice). The Arduino listens f

##board

Right now, the board library will attempt to autodiscover the Arduino. I'm going to make it configurable, don't worry.
````javascript
var board = new arduino.Board({
device: "ACM"
});
````
The board library will attempt to autodiscover the Arduino.
The `device` option can be used to set a regex filter that will help the library when scanning for matching devices.
**Note**: the value of this parameter will be used as argument of the grep command

If this parameter is not provided the board library will attempt to autodiscover the Arduino by quering every device containing 'usb' in its name.

````javascript
var board = new arduino.Board({
Expand Down Expand Up @@ -119,6 +128,67 @@ Fade the to full brightness then back to minimal brightness in `interval` ms. De

Current brightness of the LED

##lcd

This is a port of the [LiquidCrystal library](http://arduino.cc/en/Reference/LiquidCrystal) into JavaScript. Note that communicating with the LCD requires use of the synchronous `board.delay()` busy loop which will block other node.js events from being processed for several milliseconds at a time. (This could be converted to pause a board-level buffered message queue instead.)

````javascript
var lcd = new d.LCD({
board: board,
pins: {rs:12, rw:11, e:10, data:[5, 4, 3, 2]}
});
lcd.begin(16, 2);
lcd.print("Hello Internet.");
````

In `options`, the "pins" field can either be an array matching a call to any of the [LiquidCrystal constructors](http://arduino.cc/en/Reference/LiquidCrystalConstructor) or an object with "rs", "rw" (optional), "e" and a 4- or 8-long array of "data" pins. Pins will default to `[12, 11, 5, 4, 3, 2]` if not provided.

###lcd.begin(), lcd.clear(), lcd.home(), lcd.setCursor(), lcd.scrollDisplayLeft(), lcd.scrollDisplayRight()

These should behave the same as their counterparts in the [LiquidCrystal library](http://arduino.cc/en/Reference/LiquidCrystal).

###lcd.display(on), lcd.cursor(on), lcd.blink(on), lcd.autoscroll(on)

These are similar to the methods in the [LiquidCrystal library](http://arduino.cc/en/Reference/LiquidCrystal), however they can take an optional boolean parameter. If true or not provided, the setting is enabled. If false, the setting is disabled. For compatibility `.noDisplay()`, `.noCursor()`, `.noBlink()` and `.noAutoscroll()` methods are provided as well.

###lcd.write(val), lcd.print(va 8000 l)

These take a buffer, string or integer and send it to the display. The `.write` and `print` methods are equivalent, aliases to the same function.

###lcd.createChar(location, charmap)

Configures a custom character for code `location` (numbers 0–7). `charmap` can be a 40-byte buffer as in [the C++ method](http://arduino.cc/en/Reference/LiquidCrystalCreateChar), or an array of 5-bit binary strings, or a 40-character string with pixels denoted by any non-space (`' '`) character. These bits determine the 5x8 pixel pattern of the custom character.

````javascript
var square = new Buffer("1f1f1f1f1f1f1f1f", 'hex');

var smiley = [
'00000',
'10001',
'00000',
'00000',
'10001',
'01110',
'00000'
];

var random =
". .." +
" . . " +
". . ." +
" . . " +
" .. " +
". . " +
" . ." +
".. .." ;

lcd.createChar(0, square);
lcd.createChar(1, smiley);
lcd.createChar(2, random);
lcd.setCursor(5,2);
lcd.print(new Buffer("\0\1\2\1\0")); // NOTE: when `.print`ing a string, 'ascii' turns \0 into a space
````

##piezo

````javascript
Expand Down Expand Up @@ -164,6 +234,20 @@ setInterval(function(){
}, 1000);
````

##ping

See: <http://arduino.cc/en/Tutorial/Ping>

````javascript
var range = new arduino.Ping({
board: board
});

range.on('read', function () {
console.log("Distance to target (cm)", range.centimeters);
});
````

##servo

````javascript
Expand Down Expand Up @@ -213,6 +297,8 @@ What is implemented right now:
* `02` digitalRead
* `03` analogWrite
* `04` analogRead
* `97` ping
* `98` servo
* `99` debug

##pin
Expand Down
15 changes: 15 additions & 0 deletions examples/adjustable-port.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var arduino = require('../');

var board = new arduino.Board({
debug: true,
device: "ACM"
});

var led = new arduino.Led({
board: board,
pin: "13"
});

board.on('ready', function(){
led.blink();
});
1 change: 1 addition & 0 deletions examples/rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var rc = new arduino.RC({

board.on('ready', function(){
setTimeout(function() {
// alternative: rc.decimal("123456")
rc.triState("0FFF0FFFFF0F");
}, 1000);
setTimeout(function() {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
Sensor: require('./lib/sensor'),
Ping: require('./lib/ping'),
PIR: require('./lib/pir'),
LCD: require('./lib/lcd'),
RC: require('./lib/rc'),
IR: require('./lib/ir')
};
15 changes: 8 additions & 7 deletions lib/board.js
8ECB
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var events = require('events'),
child = require('child_process'),
util = require('util'),
colors = require('colors'),
chalk = require('chalk'),
serial = require('serialport');

/*
Expand All @@ -12,6 +12,7 @@ var events = require('events'),
var Board = function (options) {
this.log('info', 'initializing');
this.debug = options && options.debug || false;
this.device = options && options.device || 'tty(USB|ACM|S)[0-9]?';
this.baudrate = options && options.baudrate || 115200;
this.writeBuffer = [];

Expand All @@ -28,7 +29,7 @@ var Board = function (options) {

self.log('info', 'binding serial events');
self.serial.on('data', function(data){
self.log('receive', data.toString().red);
self.log('receive', chalk.red(data.toString()));
self.emit('data', data);
});

Expand Down Expand Up @@ -72,7 +73,7 @@ util.inherits(Board, events.EventEmitter);
Board.prototype.detect = function (callback) {
this.log('info', 'attempting to find Arduino board');
var self = this;
child.exec('ls /dev | grep ACM', function(err, stdout, stderr){
child.exec('ls /dev | grep -E "'+ self.device +'"', function(err, stdout, stderr){
var usb = stdout.slice(0, -1).split('\n'),
found = false,
err = null,
Expand Down Expand Up @@ -131,7 +132,7 @@ Board.prototype.write = function (m) {
this.log('write', m);
this.serial.write('!' + m + '.');
} else {
this.log('info', 'serial not ready, buffering message: ' + m.red);
this.log('info', 'serial not ready, buffering message: ' + chalk.red(m));
this.writeBuffer.push(m);
}
}
Expand Down Expand Up @@ -180,7 +181,7 @@ Board.prototype.pinMode = function (pin, val) {
Board.prototype.digitalWrite = function (pin, val) {
pin = this.normalizePin(pin);
val = this.normalizeVal(val);
this.log('info', 'digitalWrite to pin ' + pin + ': ' + val.green);
this.log('info', 'digitalWrite to pin ' + pin + ': ' + chalk.green(val));
this.write('01' + pin + val);
}

Expand All @@ -196,7 +197,7 @@ Board.prototype.digitalRead = function (pin) {
Board.prototype.analogWrite = function (pin, val) {
pin = this.normalizePin(pin);
val = this.normalizeVal(val);
this.log('info', 'analogWrite to pin ' + pin + ': ' + val.green);
this.log('info', 'analogWrite to pin ' + pin + ': ' + chalk.green(val));
this.write('03' + pin + val);
}
Board.prototype.analogRead = function (pin) {
Expand All @@ -219,7 +220,7 @@ Board.prototype.delay = function (ms) {
Board.prototype.log = function (/*level, message*/) {
var args = [].slice.call(arguments);
if (this.debug) {
console.log(String(+new Date()).grey + ' duino '.blue + args.shift().magenta + ' ' + args.join(', '));
console.log(chalk.gray(Date.now()) + chalk.blue(' duino ') + chalk.magenta(args.shift()) + ' ' + args.join(', '));
}
}

Expand Down
Loading
0