RobotDyn UNO + ESP8266


… oh, and USB-TTL CH340G which does the USB communicating with ESP8266. I think you otherwise need to wire something up using one of these or actually use an Arduino to do the job.

The board. The ESP8266 is that square on lower right hand side with a globe thing etched on it. That, and it ESP32 successor pretty much ARE the backbone of consumer smart devices I think.

This board has been collecting dust for a while (years), but you can get them here. Back when I bought it, after screwing around with it and failing to get it working, it was consigned to a drawer. Listening to the Hackaday podcast every week and all the talk of ESP chips inspired me to give it another go.

I was tempted to buy s bucket of ESP chips off AliExpress (at a dollar-a-piece) but I heard Greta Thunberg tutting in my ear,

“You have that ESP8266 on a board in the drawer, already which you cannot work stupid (40-year-old-English-private-school-privileged-white) man”.

Fair enough.

SPOILER ALERT: If you are wanting to use the UNO and ESP8266, together, so the ‘Arduino’ does the heavier-lifting and GPIO, and ESP8266 chip does the internet stuff as ‘shield’, the first victory below is a Pyrrhic one.

First victory: An ESP8266 web server

Setting up Arduino IDE for ESP8266 relatively simple with a quick google (there are actually some instructions on manufacturer’s website).

Setting which worked for me in Arduino IDE

Setting the DIP switches 5,6 & 7 to ON permits writing to the ESP8266 on the board. This is the code I used – cannot remember where I cut and pasted it from, but I think it is fairly ubiquitous so hopefully author can let it pass:

#include <Arduino.h>
// Load Wi-Fi library
#include <ESP8266WiFi.h>
// Replace with your network credentials
const char* SSID = <your wifi SSID name>; 
const char* PASSWORD = <you password>;
// Set web server port number to 80
WiFiServer server(80);
// Assign output variables to GPIO pins
const int output = 4;
void setup() {
  Serial.begin(115200);
  // Initialize the output and set it to LOW
  pinMode(output, OUTPUT);
  digitalWrite(output, LOW);
  // Connect to Wi-Fi network with SSID and PASSWORD
  Serial.print("Connecting to ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address 
  Serial.println("");
  Serial.println("WiFi connected at IP address:");
  Serial.println(WiFi.localIP());
  // Start Web Server
  server.begin();
}
// Main loop
void loop(){
  // Create a client and listen for incoming clients
  WiFiClient client = server.available();   
  
  // Do nothing if server is not available
  if (!client) {
     return;
  }
  
  // Wait a client 
  while(!client.available()){}
  
  // A new client is connected, get the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1) 
  {
    digitalWrite(output, HIGH);
    value = HIGH;
  } 
  if (request.indexOf("/LED=OFF") != -1)
  {
    digitalWrite(output, LOW);
    value = LOW;
  }
  
  // Display GPIO status
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); 
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.print("GPIO status: "); 
  if(value == HIGH) {
    client.print("ON");  
  } else {
    client.print("OFF");
  }
  client.println("<br><br>");
  client.println("Switch manually GPIO state");
  client.println("<br><br>");
  client.println("Turn <a href=\"/LED=ON\">ON</a><br>");
  client.println("Turn <a href=\"/LED=OFF\">OFF</a><br>");
  client.println("</html>");
  Serial.println("");
  
}

Resetting the ESP and setting DIP switch 7 to OFF (5 & 6 still ON) gives you a web server which serves a webpage and gives you control of the onboard LED. I had trouble getting the Serial working so I found the board’s IP address using Fing app on my phone.

Oh, and the ‘onboard LED’ bit is a bit disingenuous since it does not work on the RobotDyn board. Probably something to do with which pin the inbuilt LED is on (if there even is one) on the RobotDyn board – I was just not that interested in making it blink.

But it takes a web request and provides a response, which is the cool bit – that little 5mm square chip connects to the world and gives you a website in your browser. Amazing!

Second victory: PlatformIO

Arduino IDE does what it does and is always my goto to get thinks ‘working’ in the first instance, but when you are used to something a little fancier the lack of ‘help’ (code completion and stuff) is noticeable when you are spoilt by it elsewhere.

In bygone Visual Studio (Community) days VisualMicro was a good option. VS Code is my preferred code editor now – not sure if Visual Studio Community is even still a thing? It is, I checked.

I’d used the Arduino plugin for VS Code previously but I came across the PlatformIO plugin for VS Code. After installing this pretty much worked out of the box and I could upload code about with no problems.

What of the RobotDyn’s Arduino UNO?

All was right in the world, having got all this up-and-running. And, the ESP8266 is itself is a fairly capable MCU with a couple of few GPIO pins. Newer chips do have ADC (and so an analog input capability) but this does not seem to be present on my RobotDyn board.

So, you could just go and develop using just the ESP8266 (or more likely the ESP32 which also has Bluetooth) …and I might do that. There is a good comparison of ESP8266 and ESP32 here and both can be picked up on Aliexpress on prices <<$10. Nearer $1 a unit!!!

But I have this UNO-sized board, with all its Arduino UNO goodness with the ESP8266 taking up <1% of real-estate on the UNO’s 6.9.x5.3cm footprint. How do I get the two to talk?

This is where it becomes apparent the gains above were kind of in the wrong direction.

For another day; and another post.

Series Navigation

RobotDyn UNO + ESP8266: AT Mode >>