This is a small, sample project demonstrating how to use:
johnny-five
(a Node library which lets you talk to many microcontoller platforms—including the Arduino and Tessel—via JavaScript)express
(another Node library which lets you write a simple web server with JavaScript)- and
socket.io
(a Node library which lets us talk over WebSockets—a protocol for easy, two-way communication between a browser and server—via JavaScript
To run this project, we need to do two things:
- Teach the Arduino how to receive communications from our computer for the
johnny-five
library. - And install the required libraries and run the code for this sample project.
To do (1):
- Download and install the Arduino IDE (integrated development environment—kind of like a Sublime Text which can talk to the Arduino)
- Open the Arduino IDE, and open the
StandardFermata
example by going toFile > Examples > Fermata > StandardFermata
- Upload the
StandardFermata
sketch by selectingSketch > Upload
To do (2):
- Clone this repository via GitHub Desktop or from the command line (
git clone [email protected]:dgmd/arduino-websocket-example.git
). - Open the cloned repository in your terminal.
- Within the repository, run
npm install
in your terminal. This usesnpm
—Node's package manager—to install the libraries required for this project (express
andjohnny-five
) by looking within thepackage.json
file. - Connect your Arduino to your computer via USB.
- In your terminal (which should still be within the cloned repository), run
node server.js
- You should see
Server's up at http://localhost:3000!
; when you do, go tohttp://localhost:3000
and you should see "Hello fromserver.js
!" - Now you can explore the other routes and behavior detailed in
server.js