Arduino Slow SW UART Limits with ESP8266

The Plan… Originally

My previous post showed some LED’s being controlled through a very simple TTY interface.  I decided I wanted to upgrade the user interface by implementing a mini web server on the Arduino.

Problem

Once I started trying to parse an incoming HTML request, it was very unreliable.  Debugging showed that the Arduino was missing huge chunks of data.

Debugging

After I kept not being able to parse the HTML request reliably, I loaded up the pass through program and saw the following capture…

+IPD,0,340:GET / HTTP/1.1
Host: 192.168.0.173
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) ApeWeKi/53.3 (HTM, ikeGeko)Chom/390.17171Saar/53.3
Acet-ncoin: gip dflae,sdc
ccptLanuae: n-S,n;q0.
 
K Link

… which looks like a garbled request.  I think the last line is supposed to be an “OK” followed by “Link”.  Also, I think the “ccptLanuae” should be “Accept-Language”.

I knew that the SW UART was going to be limited under stress when I started using it so I hooked up my FTDI cable in parallel to see if the issue was the ESP8266 output or if the Arduino SW UART was too slow to keep up.  The FTDI cable showed…

+IPD,0,340:GET / HTTP/1.1
Host: 192.168.0.173
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8


OK
Link

… which looked as expected while the Arduino logs showed the same above garbled output.

Conclusion

Seems the SW UART on the Arduino is too slow.  I already have the ESP8266 UART speed down at 9600 so can’t go any slower.

Solution

Unfortunately there doesn’t seem to be any way to work around this SW UART limitation.  I could use the HW UART to interface with the ESP8266 but then will lose serial debug log capabilities.  Luckily I have been anticipating this dead end so ordered an Arduino Mega 2560 which has 4 HW UARTs.  I hooked up the ESP8266 to one of the Mega 2560 HW UARTs and everything worked much better.  Here is the same serial logging I am getting on the Arduino Mega 2560 using 115200 baud…

Link

+IPD,1,366:GET / HTTP/1.1
Host: 192.168.0.173
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8

… which is what the FTDI cable was showing and what I was expecting.  I even jacked up the UART speed to 115,200 and was able to get reliable communication.  For now, I am switching over to using the Arduino Mega 2560 while needing to debug.

Links:

I oredered the Arduino ESP8266 for $14.69 here: https://www.banggood.com/Mega2560-R3-ATmega2560-16AU-Control-Board-With-USB-Cable-For-Arduino-p-73020.html … Note that I chose to get it shipped from a US warehouse for extra cost.  You can get it for only $10.80 from the same place if you choose to get it shipped from a China warehouse but can take several weeks if you are in the US.

Advertisements