1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Updated ReadMe Raspberry Pi (Advanced) (markdown)

Dave Conway-Jones 2013-09-08 06:11:42 -07:00
parent acab46f793
commit 495f42af09

@ -1,5 +1,5 @@
#Raspberry Pi - Advanced
This version of working with the Raspeberry Pi uses the WiringPi libraries so gives
This version of working with the Raspberry Pi uses the WiringPi libraries so gives
you much richer control of all Pi GPIO pins and also access to the PiFace expansion board.
For more details about WiringPi see http://wiringpi.com/
@ -21,8 +21,8 @@ Edit the node-red-master/settings.js file to contain
//functionGlobalContext: { }
functionGlobalContext: { wpi:require('wiring-pi') }
This makes the wiring-pi library available to any functions you write.
It is accessable by declaring in within a function (for example) :
This makes the wiring-pi library available to any functions you write. As we are now accessing the library globally, there are NO new nodes added to the palette. All the interaction now has to happen inside function blocks. This is why we call this advanced :-)
It is accessible by declaring in within a function (for example) :
var wpi = context.global.wpi;
@ -33,8 +33,6 @@ Then start Node-RED,
then browse to http://{your-pi-address}:1880
As we are now accessing the library globally, there are NO new nodes added to the palette. All the interaction now has to happen inside function blocks. This is why we call this advanced :-)
##Blink
To run a "blink" flow that uses the WiringPi pin 0 - Pin 11 on the header - as per Gordon's blink sketch.
@ -44,7 +42,7 @@ Import the following flow, by cutting the line below into your clipboard.
[{"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":[]}]
Then in the Node-RED browser - Use Options (top right) - Import From - Clipboard, or the shortcut Ctrl-I, and paste in the text, Ctrl-V.
Then in the Node-RED browser - Use Options (top right) - Import From - Clipboard, or the shortcut Ctrl-i, and paste in the text, Ctrl-v.
Hit <b>Deploy</b> - and the flow should start running. The LED should start toggling on and off once a second.