node-red-node-arduino
Advanced tools
Comparing version
@@ -26,8 +26,8 @@ /** | ||
this.repeat = n.repeat||25; | ||
//node.log("opening connection "+this.device); | ||
var node = this; | ||
node.board = new ArduinoFirmata(); | ||
// TODO: nls | ||
ArduinoFirmata.list(function (err, ports) { | ||
if (!node.device) { | ||
node.log("connecting to first board found."); | ||
node.log(RED._("arduino.status.connectfirst")); | ||
node.board.connect(); | ||
@@ -37,7 +37,7 @@ } | ||
if (ports.indexOf(node.device) === -1) { | ||
node.warn(node.device + " not found. Trying to find board."); | ||
node.warn(RED._("arduino.errors.devnotfound",{dev:node.device})); | ||
node.board.connect(); | ||
} | ||
else { | ||
node.log("connecting to "+node.device); | ||
node.log(RED._("arduino.status.connect",{device:node.device})); | ||
node.board.connect(node.device); | ||
@@ -48,4 +48,6 @@ } | ||
node.board.on('boardReady', function() { | ||
node.log("connected to "+node.board.serialport_name); | ||
if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); } | ||
node.log(RED._("arduino.status.connected",{device:node.board.serialport_name})); | ||
if (RED.settings.verbose) { | ||
node.log(RED._("arduino.status.version",{version:node.board.boardVersion})); | ||
} | ||
}); | ||
@@ -59,3 +61,3 @@ }); | ||
done(); | ||
if (RED.settings.verbose) { node.log("port closed"); } | ||
if (RED.settings.verbose) { node.log(RED._("arduino.status.portclosed")); } | ||
}); | ||
@@ -80,5 +82,5 @@ } catch(e) { done(); } | ||
var node = this; | ||
node.status({fill:"red",shape:"ring",text:"connecting"}); | ||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"}); | ||
node.board.on('connect', function() { | ||
node.status({fill:"green",shape:"dot",text:"connected"}); | ||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"}); | ||
//console.log("i",node.state,node.pin); | ||
@@ -111,3 +113,3 @@ if (node.state == "ANALOG") { | ||
else { | ||
this.warn("port not configured"); | ||
this.warn(RED._("arduino.errors.portnotconf")); | ||
} | ||
@@ -129,6 +131,6 @@ } | ||
var node = this; | ||
node.status({fill:"red",shape:"ring",text:"connecting"}); | ||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"}); | ||
node.board.on('connect', function() { | ||
node.status({fill:"green",shape:"dot",text:"connected"}); | ||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"}); | ||
//console.log("o",node.state,node.pin); | ||
@@ -146,3 +148,3 @@ node.board.pinMode(node.pin, node.state); | ||
if (node.state === "PWM") { | ||
msg.payload = msg.payload * 1; | ||
msg.payload = parseInt((msg.payload * 1) + 0.5); | ||
if ((msg.payload >= 0) && (msg.payload <= 255)) { | ||
@@ -153,3 +155,3 @@ node.board.analogWrite(node.pin, msg.payload); | ||
if (node.state === "SERVO") { | ||
msg.payload = msg.payload * 1; | ||
msg.payload = parseInt((msg.payload * 1) + 0.5); | ||
if ((msg.payload >= 0) && (msg.payload <= 180)) { | ||
@@ -166,3 +168,3 @@ node.board.servoWrite(node.pin, msg.payload); | ||
else { | ||
this.warn("port not configured"); | ||
this.warn(RED._("arduino.errors.portnotconf")); | ||
} | ||
@@ -169,0 +171,0 @@ } |
{ | ||
"name" : "node-red-node-arduino", | ||
"version" : "0.0.2", | ||
"version" : "0.0.3", | ||
"description" : "A Node-RED node to talk to an Arduino running firmata", | ||
"dependencies" : { | ||
"arduino-firmata" : "0.3.2" | ||
"arduino-firmata" : "0.3.3" | ||
}, | ||
@@ -8,0 +8,0 @@ "repository" : { |
node-red-node-arduino | ||
===================== | ||
A <a href="http://nodered.org" target="_new">Node-RED</a> node to talk to an Arduino running firmata. | ||
A <a href="http://nodered.org" target="_new">Node-RED</a> node to talk to an | ||
Arduino running standard firmata 2.2 or better. | ||
**Note** : This is the same node as was in the core of Node-RED. | ||
As of v0.10.8 you will need to install it from here if still required. | ||
Install | ||
@@ -13,7 +11,6 @@ ------- | ||
Run the following command in the root directory of your Node-RED install, usually | ||
this is ~/.node-red . | ||
this is `~/.node-red` | ||
npm install node-red-node-arduino | ||
Usage | ||
@@ -27,22 +24,32 @@ ----- | ||
###Input Node | ||
### Input Node | ||
Connects to local Arduino and monitors the selected pin for changes. | ||
You can select either Digital or Analogue input. Outputs the value read as **msg.payload** and the pin number as **msg.topic**. | ||
You can select either **Digital** or **Analogue** input type. | ||
Outputs the value read as **msg.payload** and the pin number as **msg.topic**. | ||
It only outputs on a change of value - fine for digital inputs, but you can get a lot of data from analogue pins which you must then handle. | ||
You can set the sample rate in ms from 20 to 65535. | ||
You can set the sample rate from `20` to `65535` mS. | ||
###Output Node | ||
### Output Node | ||
Connects to local Arduino and writes to the selected pin. | ||
You can select Digital, Analogue (PWM) or Servo type outputs. Expects a numeric value in **msg.payload**. The pin number is set in the properties panel. | ||
You can select | ||
###Example | ||
- **Digital** - accepts 0, 1, true, false, on, off | ||
- **Analogue** (PWM) - accepts Integer 0 to 255 | ||
- **Servo** - accepts Integer 0 - 180 | ||
Expects a numeric value in **msg.payload**. The pin number is set in the properties panel. | ||
*Note* - some servos will not travel a full 180 degree range so may only accept 30 - 150 degrees for example. | ||
Please use the `range` node to scale the input appropriately. | ||
### Example | ||
Simple flow to blink Pin 13 | ||
[{"id":"d7663aaf.47194","type":"arduino-board","device":""},{"id":"dae8234f.2517e","type":"inject","name":"0.5s tick","topic":"","payload":"","payloadType":"date","repeat":"0.5","crontab":"","once":false,"x":150,"y":100,"z":"359a4b52.ca65b4","wires":[["56a6f8f2.a95908"]]},{"id":"2db61802.d249e8","type":"arduino out","name":"","pin":"13","state":"OUTPUT","arduino":"d7663aaf.47194","x":570.5,"y":100,"z":"359a4b52.ca65b4","wires":[]},{"id":"56a6f8f2.a95908","type":"function","name":"Toggle output on input","func":"\n// If it does exist make it the inverse of what it was or else initialise it to false\n// (context variables persist between calls to the function)\ncontext.level = !context.level || false;\n\n// set the payload to the level and return\nmsg.payload = context.level;\nreturn msg;","outputs":1,"noerr":0,"x":358,"y":100,"z":"359a4b52.ca65b4","wires":[["2db61802.d249e8"]]}] |
Sorry, the diff of this file is not supported yet
29002
7.68%6
20%196
24.84%54
14.89%+ Added
- Removed
Updated