#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.
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
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.
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.
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.
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.
Thank you for what you've done with this! I've incorporated this into a slightly re-engineered version of the simplebot from your “Building Robots with Lo-tech Materials” contribution to Make: JavaScript Robotics. (my adaptation here) We used your design and code, coached a bunch of kids through building their own bots and we sumoed with them for nodebot day 2017. Here's a video of them working
There are some occasions where the bot looses connectivity, it seems, and we have to break out of the script and re-run it to gain control of the bot. Have you experienced this? Any ideas for how best to ensure that the bot doesn't go AWOL?
Thank you again!!