You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/hardware/arduino.md
+6-4
Original file line number
Diff line number
Diff line change
@@ -20,17 +20,17 @@ to communicate with it.
20
20
### Firmata
21
21
22
22
[Firmata](http://firmata.org/) is a protocol for communicating between an
23
-
Arduino (as well as other microcontrollers) and the host computer, providing
23
+
Arduino (as well as other microcontrollers) and the host computer, providing
24
24
direct access to the IO pins.
25
25
26
26
#### Installation
27
27
28
28
First you need to load the default Firmata sketch onto the Arduino using the
29
-
standard Arduino software download tools. This is usually found under
29
+
standard Arduino software download tools. This is usually found under
30
30
*Files - Examples - Firmata - Standard Firmata*.
31
31
32
32
To ensure you have the Arduino nodes in the Node-RED palette, install the
33
-
firmata npm module and restart Node-RED
33
+
firmata npm module and restart Node-RED
34
34
35
35
$ cd node-red
36
36
$ npm install firmata
@@ -42,7 +42,9 @@ To run a "blink" flow that uses LED 13, copy the following flow and paste it
42
42
into the Import Nodes dialog (*Import From - Clipboard* in the dropdown menu, or
43
43
Ctrl-I). After clicking okay, click in the workspace to place the new nodes.
44
44
45
-
[{"id":"d7663aaf.47194","type":"arduino-board","repeat":"25","device":"/dev/ttyUSB0"},{"id":"8c09ca6c.a975d","type":"arduino out","name":"","pin":"13","state":"OUTPUT","arduino":"d7663aaf.47194","x":509.16667556762695,"y":162.16666984558105,"wires":[]},{"id":"e37b6a97.610968","type":"inject","name":"tick","topic":"","payload":"","repeat":"0.5","once":false,"x":116.16668319702148,"y":62.16666507720947,"wires":[["60b4aeaa.800d58"]]},{"id":"60b4aeaa.800d58","type":"function","name":"Toggle output on input","func":"\n// initialise level as a context variable if currently undefined \n// (context variables persist between calls to the function)\ncontext.level = context.level || false;\n\n// if it's a 0 make it a 1 else make it a 0...\ncontext.level = !context.level;\n\n// set the payload to the level and return\nmsg.payload = context.level;\nreturn msg;","outputs":1,"x":298.1666793823242,"y":113.16665458679199,"wires":[["8c09ca6c.a975d"]]}]
45
+
````json
46
+
[{"id":"d7663aaf.47194","type":"arduino-board","repeat":"25","device":"/dev/ttyUSB0"},{"id":"8c09ca6c.a975d","type":"arduino out","name":"","pin":"13","state":"OUTPUT","arduino":"d7663aaf.47194","x":509.16667556762695,"y":162.16666984558105,"wires":[]},{"id":"e37b6a97.610968","type":"inject","name":"tick","topic":"","payload":"","repeat":"0.5","once":false,"x":116.16668319702148,"y":62.16666507720947,"wires":[["60b4aeaa.800d58"]]},{"id":"60b4aeaa.800d58","type":"function","name":"Toggle output on input","func":"\n// initialise level as a context variable if currently undefined \n// (context variables persist between calls to the function)\ncontext.level = context.level || false;\n\n// if it's a 0 make it a 1 else make it a 0...\ncontext.level = !context.level;\n\n// set the payload to the level and return\nmsg.payload = context.level;\nreturn msg;","outputs":1,"x":298.1666793823242,"y":113.16665458679199,"wires":[["8c09ca6c.a975d"]]}]
47
+
````
46
48
47
49
This flow is set to use `/dev/ttyUSB0`. If you need to change that, double click
48
50
the node labelled `Pin 13` - the Arduino node. Click the pencil icon and change
Click the deploy button and the flow should start running. The LED should start
46
48
toggling on and off once a second.
@@ -55,8 +57,8 @@ expansion board. More details about WiringPi are available [here](http://wiringp
55
57
56
58
#### Installation
57
59
58
-
After [installing](../getting-started/installation.html) Node-RED, follow these
59
-
[instructions](http://wiringpi.com/download-and-install/) to get Wiring Pi
60
+
After [installing](../getting-started/installation.html) Node-RED, follow these
61
+
[instructions](http://wiringpi.com/download-and-install/) to get Wiring Pi
60
62
installed.
61
63
62
64
#### Configuring Node-RED
@@ -67,7 +69,7 @@ available for use in Function nodes.
67
69
To do this, update `settings.js` to add the `wiring-pi` module to the Function
68
70
global context:
69
71
70
-
functionGlobalContext: {
72
+
functionGlobalContext: {
71
73
wpi: require('wiring-pi')
72
74
}
73
75
@@ -82,7 +84,9 @@ Then copy the following flow and paste it into the Import Nodes dialog
82
84
(*Import From - Clipboard* in the dropdown menu, or Ctrl-I). After clicking
83
85
okay, click in the workspace to place the new nodes.
84
86
85
-
[{"id":"860e0da9.98757","type":"function","name":"Toggle LED on input","func":"\n// select wpi pin 0 = pin 11 on header (for v2)\nvar pin = 0;\n\n// initialise the wpi to use the global context\nvar wpi = context.global.wpi;\n\n// use the default WiringPi pin number scheme...\nwpi.setup();\n\n// initialise the state of the pin if not already set\n// anything in context. persists from one call to the function to the next\ncontext.state = context.state || wpi.LOW;\n\n// set the mode to output (just in case)\nwpi.pinMode(pin, wpi.modes.OUTPUT);\n\n// toggle the stored state of the pin\n(context.state == wpi.LOW) ? context.state = wpi.HIGH : context.state = wpi.LOW;\n\n// output the state to the pin\nwpi.digitalWrite(pin, context.state);\n\n// we don't \"need\" to return anything here but may help for debug\nreturn msg;","outputs":1,"x":333.16666412353516,"y":79.16666793823242,"wires":[["574f5131.36d0f8"]]},{"id":"14446ead.5aa501","type":"inject","name":"tick","topic":"","payload":"","repeat":"1","once":false,"x":113.16666412353516,"y":59.16666793823242,"wires":[["860e0da9.98757"]]},{"id":"574f5131.36d0f8","type":"debug","name":"","active":true,"x":553.1666641235352,"y":99.16666793823242,"wires":[]}]
87
+
````json
88
+
[{"id":"860e0da9.98757","type":"function","name":"Toggle LED on input","func":"\n// select wpi pin 0 = pin 11 on header (for v2)\nvar pin = 0;\n\n// initialise the wpi to use the global context\nvar wpi = context.global.wpi;\n\n// use the default WiringPi pin number scheme...\nwpi.setup();\n\n// initialise the state of the pin if not already set\n// anything in context. persists from one call to the function to the next\ncontext.state = context.state || wpi.LOW;\n\n// set the mode to output (just in case)\nwpi.pinMode(pin, wpi.modes.OUTPUT);\n\n// toggle the stored state of the pin\n(context.state == wpi.LOW) ? context.state = wpi.HIGH : context.state = wpi.LOW;\n\n// output the state to the pin\nwpi.digitalWrite(pin, context.state);\n\n// we don't \"need\" to return anything here but may help for debug\nreturn msg;","outputs":1,"x":333.16666412353516,"y":79.16666793823242,"wires":[["574f5131.36d0f8"]]},{"id":"14446ead.5aa501","type":"inject","name":"tick","topic":"","payload":"","repeat":"1","once":false,"x":113.16666412353516,"y":59.16666793823242,"wires":[["860e0da9.98757"]]},{"id":"574f5131.36d0f8","type":"debug","name":"","active":true,"x":553.1666641235352,"y":99.16666793823242,"wires":[]}]
89
+
````
86
90
87
91
Click the `Deploy` button and the flow should start running. The LED should start
88
92
toggling on and off once a second.
@@ -110,7 +114,5 @@ Once you reboot you should then be able to attach to the screen session by
0 commit comments