Skip to content

Instantly share code, notes, and snippets.

@boneskull
Created July 26, 2018 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boneskull/29cfbec123c2fea0d5b6bb92754d60b8 to your computer and use it in GitHub Desktop.
Save boneskull/29cfbec123c2fea0d5b6bb92754d60b8 to your computer and use it in GitHub Desktop.
How to Use an ESP8266 w/ Johnny-Five

How to Use an ESP8266 w/ Johnny-Five by boneskull

Prerequisite Software

  • 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.

Add ESP8266 Board Support to Arduino IDE

  1. Launch Arduino IDE
  2. Open Preferences
  3. 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.
  4. Click OK
  5. Navigate to menu Tools > Board.. > Boards Manager
  6. Find esp8266 by ESP8266 Community in the list. Click Install.
  7. Once this is complete, click OK.

Flash Dev Board

  1. Plug in dev board via USB to your computer.

  2. In menu Tools > Board, select “Adafruit Feather Huzzah ESP8266” from the list.

  3. 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.
  4. In menu File > Examples … Examples for any board > Firmata choose StandardFirmataWifi.

  5. Modify this sketch by uncommenting line 85: #define SERIAL_DEBUG

  6. There will be a tab for a file wifiConfig.h. Click this tab to open the file.

  7. On line 119, enter the name of your WiFi network (in double quotes), e.g., char ssid[] = “foobar”;

  8. 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.

  9. Click the Upload button (icon is a “right arrow”) in the toolbar. This should flash your board with the firmware.

  10. To confirm things are working, click the Serial Monitor button in the toolbar (icon is a magnifying glass).

  11. Change the baud rate to 9600

  12. 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!

  13. Close the serial monitor window.

Install Johnny-Five & Node Modules

  1. Create a new directory and run npm init -y to generate a package.json.
  2. Execute npm install johnny-five etherport-client.
  3. 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).

  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment