A Small Experiment with Node.JS, Arduino, Johnny Five, Sphero, Cylon.js, Socket.IO, Redis, and Angular.
or click here for a blog post that kinda explains what this is
This is an Arduino device interacting with a web browser. Buttons and lights on a breadboard interact with users connected to a Node.JS server. The underlying technologies to make this work are all (pretty much) based on JavaScript.
Basically this is me playing with stuff.
This allows an Arduino or Spark Core to randomly blink two differently colored LED lights for a few seconds. When the lights stop blinking, the state of each LED (on or off) is communicated with any connected web client.
It is up to the user to guess which LEDs will be lit (or off) at the end of the blinking sequence. The user confirms the guess by clicking on the red & green buttons on the page served by the Node.JS application. In this case, the red and green buttons look like owl eyes.
Guessing correctly scores a point.
The history of the blinking sequences is stored in a Redis database, and the most recent 25 results can be viewed by the user (by clicking the hamburger icon in the upper left corner of the screen).
- Install Node.jS
- Install Redis
- Download/Clone this repository
- Run
npm install
to fetch the dependencies - Bonus Check out the sphero branch of this repo for extra Sphero functionality (only if you have a Sphero).
- Run
node index.js
to start the server. - Open a web browser to
http://localhost:3000/#?debug
- Click the Auto Blink checkbox and wait a few seconds.
- The Node console should output some information, and your browser window should update.
- Connect a Spark Core with 2 LEDs and a Pushbutton (see diagram below).
- Make sure it is running the voodoospark firmware.
- In
index.js
, comment out this line:var owled = require('./server/owled-fake');
- In
index.js
, uncomment this line://var owled = require('./server/owled');
- Ensure the Spark Core is on and connected to the 'cloud' (pulsing cyan).
- Run
node index.js
Basically the same setup as the spark core, but go to /server/owled.js
and comment out the Spark Core board init code (lines 10-15) and the Spark Core pins (lines 28-30).
Then uncomment the Arduino board init (line 19) and the Arduino pins (34-36)
Change the pin numbers depending on how you wired up your board.
-
- Check out the
sphero
branch of this project.
- Check out the
-
- Pair a Sphero to your computer via bluetooth. See the Cylon docs for more info.
-
- Find the Sphero connection ID. On a Mac, do
ls /dev/tty.*
and look fortty.Sphero-ABC-DEF
in the output.
- Find the Sphero connection ID. On a Mac, do
- Open
/server/mysphero.js
and replace the Sphero id on line 17 with your own. - Run
node index.js
and hopefully your Sphero will connect. (It may take a few tries). - There is a 5 second calibration period to orient Sphero.
- Whenever a user guesses correctly and scores a point, Sphero will roll forward.