An example of a web interface powered by Socket.IO to control an Arduino robot using johnny-five
For this project we used:
- BOE Shield: A great kit with all the stuff that you need to make a robot.
- Johnny-Five: JavaScript framework to make Arduino do cool stuff.
- Socket.IO: Library to send events to the server through the browser.
- Harp: Quick web server and pre-processors
There are two main pieces: a server and a controller.
The server connects and sends commands to the arduino. It also stands up a web server on port 8888 that receives socket commands and maps those commands to an action in the bot.
The controller is the web interface. Its job is to send different events to the server depending on the buttons that were clicked.
The server and the controller can be in two different parts of the world and it'd still work (as long as you have Internet).
Install the dependencies
npm install
Running the server:
Do this after your bot is wired and ready to go. If you're still new to johnny-five, here's a great getting started guide.
Follow the instructions on how to wire up your bot. Don't forget to calibrate your servos with a screw driver before you start crying on the floor like a baby for 2 and a half hours.
Once you have everything hooked up (wired up, Firmata in Arduino and usb plugged in), run the following command:
node server.js
You can use the repl
to test your bot by entering commands like: n.fwd(10);
or n.stop()
. The repl
is like a interactive command line tool, you can execute commands directly from the CLI.
Running the controller:
The controller creates a socket connection to the server, so the server needs to be up for the controller to work.
node controller.js
Go to localhost:9966
in your browser and you should see the controller interface.
If the controller doesn't work, make sure you're connecting to the right server. Check the globals.server
value in /harp.json
, and also check it on /public/app.js
. Both of these files specify the URL of the server that you're connecting to.
- Jorge Pedret @jorgepedret
- Donniel Thomas @donnielrt