Preamble
There is always different ways to achieve the same goal. This is very true in programming, so is in life. Most times we like to think there is only one way – our way.
set up Arch Linux system for node and johnny-five etc.
This is a good tutorial for this subject and Arduino Experimenter’s Guide for NodeJS.
- install Arduino IDE for your system
-
upload Firmata into board
-
install node.js
123sudo pacman -S nodejs -
install npm
12345sudo pacman -S npmor updatenpm update npm -g -
switch on python for default (nmp install –python=python2.7 does NOT work) to install johnny-five
123456cd /usr/bin/$ sudo ln -sf python2 pythonsudo npm install johnny-fivesudo ln -sf pytho3 python #switch off python2Note: not a good practice since it will effect other packages, make sure reset to default after installation.
-
mkdir for js files and link to johnny5 folder
123ln -s ~/node_modules/ ./node_modules -
blink.js file
123456789var j5 = require("johnny-five");var board = new j5.Board();var LEDPIN = 13;board.on("ready", function(){var led = new j5.Led(LEDPIN);led.strobe();}); -
run node blink.js
123456node blink.js1430631447456 Device(s) /dev/ttyACM01430631447475 Connected /dev/ttyACM01430631450138 Repl Initialized
Bridging with Arduino via pySerial, pyFirmata or PyMata
-
Install pyfirmata and/or PyMata
123sudo pip install pyfirmata - with python via pyserial only Only serial strings can be passed with Serial.write and Serial.read. Customized sketch code required for advanced function, very powerful via pyhton GUI (esp PyQt), but required some serious coding from both end (python and Arduino sketch).
-
with python via pyfirmata /or PyMata and pyerial Firmata needs to be loaded into Arduino. All the coding is from python end with PyFirmata framework. This is a very easy approach to control Arduino. Following code from PyFirmata
1234567891011121314>>> import sh>>> pin=13>>> port='/dev/ttyACM0'>>> board = pyfirmata.Arduino(port)>>> board.digital[pin].write(1)>>> board.digital[pin].write(0)>>> board.digital[pin].read()0>>> board.digital[pin].write(1)>>> board.digital[pin].read()1>>> board.digital[pin].write(0)
Control from the Internet with a web Interface
- Using Arduino Ethernet Shield Did not get a chance to try this way, and do not understand why spend $80 for a shield instead of $35 for a Raspberry PI with so much more to offer.
-
Use Python CGI as gateway to web interface As shown in RLM site , with jQuery you are a true master of your Arduino and peripheral Hardwares. I will post some other project we did later.
Firmata_test to quick test your system
-
Download firmata_test from firmata.org, roll to bootom to get the righ version – 64 bit in my case
1234chmod +x firmata_test.64bit./firmata_test.64bit -
The screenshot
JUN
About the Author:
Beyond 8 hours - Computer, Sports, Family...