Control an Arduino Zero using Node.js
I had to delve deep into the code, but I finally got nodebots working on an Arduino Zero
I recently received an Arduino Zero, arduino.cc’s latest offering. I’d been experimenting with nodebots, so I decided my first Arduino Zero project would be a nodebot.
Anna Gerber has an excellent tutorial for doing nodebots using Arduino at http://node-ardx.org/
Not only is it well written and suitable for beginners, it’s also open source. I’ve derived this project from her first tutorial, and I recommend referencing it.
Step 1: Clone the node-ardx github repository
Clone https://github.com/AnnaGerber/node-ardx into a new directory.
Run “npm install”.
Next, make sure you have the latest version of the arduino IDE installed from arduino.cc. If you don’t have a version from after July 2015, I recommend downloading the hourly build. This will make sure that the Arduino Servo library is modernized to be used with the Arduino Zero’s SAMD architecture.
What is SAMD Architecture?
The Arduino Zero uses SAMD, while older Arduino boards use AVR (the Arduino Due is also built using SAM architecture, and the Teensy and digiX are arduino clones that use ARM processors). SAM stands for “Smart ARM-based microprocessors.” The SAMD is a low-power, general purpose version of the SAM architecture.
You only notice the differences between AVR and ARM architectures when you’re writing lower level code. If you tend to stick to the Arduino IDE, probably the only difference you will notice is that the Arduino Zero and other ARM boards have a narrower voltage range.
Step 2: Launch Firmata
Launch the Arduino IDE and go to “File”> “Examples”>”Firmata”
Select the “Standard Firmata” sketch.
What is Firmata?
Firmata is a library developed to make it easy to work with Arduino using various languages. The Firmata sketch basically turns the Arduino into a slave. It takes control of the various inputs and outputs and allows them to be controlled from other languages, such as Wiring, or of course, Node.js.
Step 3: Configure the Arduino IDE to work with the Zero
Now it’s time to plug the Arduino into the computer.
You’ll notice that the Arduino Zero has two micro USB ports.
According to the page, the programming port is the one you’ll normally want to use, although sketches can be sent either over the USB port or the programming port.
After plugging the board in, select the correct board and port in the IDE.
Under “Tools” > “Boards” you’ll see about 20 boards listed, but you won’t see the Zero at first. To add it, go to “Tools” > “Boards” > “Board Manager.”
This will bring up the Board Manager window.
Scroll down to “Arduino SAMD Boards.” Select the tiny blue text that says “more info.”
This will bring up an “Install” button.
Read more: Control an Arduino Zero using Node.js