Skip to content

Instantly share code, notes, and snippets.

@mwittig
Forked from ajfisher/0x00000.bin
Created December 2, 2015 09:12
Show Gist options
  • Save mwittig/13fa0afe2891ae9fa74c to your computer and use it in GitHub Desktop.
Save mwittig/13fa0afe2891ae9fa74c to your computer and use it in GitHub Desktop.
ESP8266 Transparent bridge to J5

#ESP8266 Transparent bridge to J5

How to use an ESP8266 as a transparent bridge to enable wifi between your arduino and johnny five. AKA, how to get rid of your serial cable and use WiFi instead!

Update: For a long time, this process used 5shekel's TCP transparent bridge which works okay but hasn't been updated much and with Johnny Five, TCP isn't the best protocol for this type of messaging.

As a result there was a desire to move to UDP instead for performance and this has been accomplished thanks to the hard work of Riven from MakeBlock, Mark Wolfe, Andy Gelme and Luis Montes.

ESP8266 Config

You need to make sure you have both esptool.py as well as esptool-ck. The first will help with testing you can talk to the board and erasing it and the second does a better job flashing to the ESP8266 module.

Put your ESP8266 in flash mode then

esptool.py --port /dev/ttyDEVICE erase_flash

It's important to wipe it clean so it gets rid of any user settings you might have. After that it's time to write the bins to the clean memory. The bins are attached to this gist and are built from Mark Wolfe's project.

esptool -cp /dev/ttyDEVICE -cd ck -ca 0x00000 -cf 0x00000.bin \
 -ca 0x40000 -cf 0x40000.bin

Reset the ESP8266 and drop out of flash mode and you should see an AP come up called NBD_XXXXXX where XXXXXX is the last 6 hex values of the mac address. So mine looks like NBD_FBE7C3. By default the network is open however you can configure that by connecting to the AP and then pointing a web browser at 192.168.4.1

Johnny Five setup

From Johnny Five we use the UDP-serial project to create a virtual serial port across UDP.

Dependencies:

npm install johnny-five firmata udp-serial

By default the address we want to talk to is 192.168.4.1 and the UDP port is 1025 so confiure them in the options.

Arduino setup

Load standard firmata and change the firmata speed to 115200 instead of 57600 ( search 57600 in the standardfirmata sketch - it's the only instance). Compile and upload to arduino.

Connect TX / RX pins to arduino and ESP01, add power to each one, grounds together.

Running it all

After that, run the script ncluded in this gist and it should work quite well you should get a nicely blinking light. Now use this structure to go make awesome wireless robots.

Acknowledgments:

Putting this together was made much easier by the people laid the foundations and also put up with me asking questions, asking for builds as my environment was toasted and generally being demanding due to the lead up to NodeBots Day.

  • Riven from MakeBlock who started down this path as part of NodeBots Day China but we ran out of time. This baseline is excellent to have worked from.
  • Luis Montes who provided insight on how the Johnny Five network stream would work and who quickly produced UDP-Serial such that the whole nodebots community can now work with this as an IO transport method.
  • Mark Wolfe who spent considerable time debugging what was happening and refined the build process so we now have a stable and replicable build environment to work on this further.
  • Andy Gelme who debugged a gnarly bridge issue that looked to be a critical blocker and refined the bridge code so that things are nice and zippy.

If you use this code and you like it, ping a message to those listed above because they have done an awesome job producing this in a very short time period.

'use strict';
var VirtualSerialPort = require('udp-serial').SerialPort;
var firmata = require('firmata');
var five = require("johnny-five");
//create the udp serialport and specify the host and port to connect to
var sp = new VirtualSerialPort({
host: '192.168.4.1',
type: 'udp4',
port: 1025
});
//use the serial port to send a command to a remote firmata(arduino) device
var io = new firmata.Board(sp);
io.once('ready', function(){
console.log('IO Ready');
io.isReady = true;
var board = new five.Board({io: io, repl: true});
board.on('ready', function(){
console.log('five ready');
//Full Johnny-Five support here:
var led = new five.Led(13);
led.blink();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment