How to Use an ESP8266 w/ Johnny-Five by boneskull
- Node.js v8.x
- Arduino IDE v1.8.5
- CP2104 driver (found linked here)
A toolchain to build native modules may be required. windows-build-tools may be the quickest way to get setup on Windows. macOS users will need to install XCode; Linux users will need to install build-essential
, python
, and likely some other stuff.
- Launch Arduino IDE
- Open Preferences
- Add
http://arduino.esp8266.com/stable/package_esp8266com_index.json
to the Additional Boards Manager URLs input. If you have something in this field already, you can add multiple URLs by delimiting with commas. - Click OK
- Navigate to menu Tools > Board.. > Boards Manager
- Find esp8266 by ESP8266 Community in the list. Click Install.
- Once this is complete, click OK.
-
Plug in dev board via USB to your computer.
-
In menu Tools > Board, select “Adafruit Feather Huzzah ESP8266” from the list.
-
In menu Tools > Port, select the proper port.
- On Windows, this will be
COMx
. - On Linux, this will likely look like
/dev/ttyUSBx
. - On Mac, this will likely look like
/dev/tty.xxxxx
.
- On Windows, this will be
-
In menu File > Examples … Examples for any board > Firmata choose StandardFirmataWifi.
-
Modify this sketch by uncommenting line 85:
#define SERIAL_DEBUG
-
There will be a tab for a file
wifiConfig.h
. Click this tab to open the file. -
On line 119, enter the name of your WiFi network (in double quotes), e.g.,
char ssid[] = “foobar”;
-
If using a secured network (requiring a password), on line 151, enter the WiFi network password in double quotes. Otherwise, uncomment line 183 for an unsecured network.
-
Click the Upload button (icon is a “right arrow”) in the toolbar. This should flash your board with the firmware.
-
To confirm things are working, click the Serial Monitor button in the toolbar (icon is a magnifying glass).
-
Change the baud rate to 9600
-
Assert that you see something like:
connected with SON OF ZOLTAR, channel 11 dhcp client start... ip:10.0.0.49,mask:255.255.255.0,gw:10.0.0.1 IP will be requested from DHCP ... Attempting to connect to WPA SSID: SON OF ZOLTAR WiFi setup done scandone .SSID: SON OF ZOLTAR IP Address: 10.0.0.49 signal strength (RSSI): -39 dBm
…where
SON OF ZOLTAR
is your WiFi network’s name.Note the IP address. This is important!
-
Close the serial monitor window.
- Create a new directory and run
npm init -y
to generate apackage.json
. - Execute
npm install johnny-five etherport-client
. - Create
blink.js
:
'use strict';
const {
EtherPortClient
} = require('etherport-client');
const five = require('johnny-five');
const board = new five.Board({
port: new EtherPortClient({
host: '10.0.0.49',
port: 3030
}),
repl: false
});
const LED_PIN = 2;
board.on('ready', () => {
board.pinMode(LED_PIN, five.Pin.OUTPUT);
const pin = five.Pin(LED_PIN);
let value = 0;
setInterval(() => {
if (value) {
pin.high();
value = 0;
} else {
pin.low();
value = 1;
}
}, 500);
});
Replace '10.0.0.49'
with the IP address you noted from the serial monitor.
You may need to change LED_PIN
to 13
. I forget what the number is for the builtin LED on Huzzah (this guide was tested on a Wemos D1 Mini, which is functionally equivalent in most ways which matter).
- Save this file, and execute it:
$ node hello.js
1532643089553 SerialPort Connecting to host:port: 10.0.0.49:3030
1532643089556 Connected Connecting to host:port: 10.0.0.49:3030
You should see the onboard LED blink. When satisfied, hit Ctrl-C
to quit.