Projects

Fixing Firmware - Part 1

Updating Firmware on the Arduino Bootloader

Geoff Cohen

Issue 33, April 2020

We show you how to install or upgrade microcontroller firmware to eliminate WiFI errors in some Uno and Mega WiFi combo boards.

PICTURED ABOVE: ISP (In-System Programmer) to be published in Part 2

If you are not aware of what firmware does, firmware is defined as “permanent software programmed into a read-only memory”. Simply put, it remembers instructions, even when switched off. For the Jaycar Arduino Mega (and Uno) with WiFi, an on-board Espressif ESP8266 IC provides WiFi functionality. The standard ESP firmware includes code that converts the venerable ‘AT’ command set into internal ESP machine code, enabling the ESP8266 to send and receive WiFi data packets over the Internet. The “AT” command set has been around since the 1981 and is still used in virtually every modem.

Many Arduino compatible Mega with WiFi and Uno with WiFi combo boards contain obsolete WiFi firmware that prevents their WiFi working with standard Arduino WiFi libraries.

XC4411 Duinotech Classic with Wi-Fi from Jaycar.
XC4421 Duinotech MEGA with Wi-Fi from Jaycar.

We discovered this problem when we attempted to run some WiFi code on our Arduino Mega with WiFi board and discovered it contained obsolete ESP8266 WiFi firmware that crashed with current Arduino WiFi libraries. Of course, even if it contained the more common (and slightly newer) V1 firmware, as all our ESP-01 boards had, V1 firmware contains some annoying and time wasting bugs. The worst example we’ve encountered was that WiFi Signal Strength ( WiFi.RSSI() ) didn’t work correctly. If you look carefully through the H2O Timer code from last month’s issue, you’ll find a kludge/workaround for this particular bug.

We have also come across Arduino clones that didn’t even have a Bootloader, and more recently, we encountered an Arduino bootloader problem with a friend’s Creality Ender 3 3D printer. This brought us to making our own In-System Programmer to solve the issues. We'll present the ISP project in next month's issue.

THE BROAD OVERVIEW

In part one of our two part project, we’ll show you how to easily update your ESP8266 firmware and enable your Arduino with WiFi combo board to work with Arduino WiFi libraries. Next month, we’ll show you how to build your own ISP (In-System Programmer) to fix the firmware in your other Arduino-based microprocessors.

How to:

Update Firmware in your Arduino with WiFi Combo

The majority of hobbyist WiFi boards, including the Jaycar Arduino XC4411 Uno with Wifi and XC4421 Mega with WiFi combo, use an onboard Espressif ESP IC to make the WiFi side work. In a nutshell, standard ESP firmware contains code that converts the ubiquitous ‘AT’ modem command set to internal ESP machine code that sends and receives WiFi data over the Internet.

We first noticed the Jaycar Arduino Mega with WiFi (Cat no. XC4421) when we started designing the DIYODE H20 Timer (see Issue 031 Feb 2020). On paper, it looked like this Arduino/WiFi combo board would fit the bill exactly, reducing the project’s component count and simplifying the wiring, compared to the standard Arduino Mega and separate ESP-01 WiFi card we were using for the prototyping at the time.

When our Mega with WiFi arrived in the mail, we already had an early version of the DIYODE-H2O-Timer software running and, after reading the instructions, it seemed all we had to do was change switch settings. Unfortunately, it wasn’t that easy and the WiFi didn’t work at all. Instead, the Serial debugger displayed the (quite unhelpful) error message that the on-board ESP chip contained unsupported WiFi firmware (only version 0.9.5. We've found it pays to be wary of versions under 1.0 for most software).

WiFi connect #1
[WiFiEsp] Initializing ESP module
[WiFiEsp] Warning: Unsupported firmware 0.9.5
getFwVersion=0.9.5
WiFi - Connecting to Kitchen
[WiFiEsp] Failed connecting to Kitchen

After spending a few hours trying to fix it, we temporarily gave up and decided to try again after the H2O Timer project was finished (Which was in Feb 2020). Since then, we’ve discovered that upgrading ESP firmware is possible and, in fact, it's quite easy. But only after spending tens of hours researching online, eliminating a large amount of incorrect “web-wrong” URL’s and extracting the rather sparse correct information.

After successfully testing several versions, we settled on updating the firmware to version v2.2.1, as it’s the last version to support both the 32MB “Mega/Uno with WiFi” and the smaller ESP-01. So far, we haven’t found any bugs in V2.2.1, so it’s running on all of our WiFi combo Arduino’s and most of our ESP-01’s (we have quite a few).

HARDWARE SETUP

All that’s needed to update the firmware on your Mega/Uno with WiFi is to set DIP switches 1,2,3,4 OFF and 5,6,7 ON (8 is not used).

If you’re updating a Mega, you also need to set the slide switch to TXD3. This allows you to use COM1 for Serial Debugging messages and COM3 for the ESP WiFi side and is 100% compatible with a standard Mega with separate ESP-10, like the DIYODE H2O Timer.

The DIP switches are minuscule (only 1mm spacing) and found it difficult to tell if they were on or off, so we used a texta colour to put a tiny dot on each DIP switch. Even then, we occasionally had to verify the settings using our phone’s camera as a magnifying glass. As we also needed a very small tool to actually set the DIP switches, we used a tiny DIY 3D printed 1mm screwdriver (https://www.thingiverse.com/thing:4168665), but any tiny tool would work.

SOFTWARE SETUP

We upgraded the firmware using a PC and the Espressif flash download tool, which is available at: https://www.espressif.com/sites/default/files/tools/flash_download_tools_v3.6.8.zip

We initially wasted an extraordinary amount of time getting this Flash Download tool to work. It turned out to be really easy, once you know how. The secret is in selecting the files, and equally importantly, the hex offset addresses. Once these are correct, it’s a doddle.

The V2.2.1 data files needed are at the very bottom of URL: https://github.com/espressif/ESP8266_NONOS_SDK/releases/tag/v2.2.1

Or directly from: https://github.com/espressif/ESP8266_NONOS_SDK/archive/v2.2.1.zip

There are also copies of both zip files that you can download from our website.

After downloading, unzip both files to your preferred folders. Run flash_download_tools_v3.6.8.exe, click on the ESP8266 DownloadTools button and select the ESP8266 Download Tool V3.6.8 window.

These are the files and offset addresses you need to enter (you can cut and paste from diyodemag.com to prevent hex address errors). These files are in subfolders of where you unzipped ESP8266_NONOS_SDK-2.2.1.zip

Each hex Address consists of 7 or 8 digit hexadecimal numbers, all beginning with 0x [zero “X”], followed by 5 or 6 hex numbers. (FYI - Hex numbers range from 0 to 9 plus abcdef, equating to (or matching) decimal numbers 0 to 15).

The ESP8266 Download Tool V3.6.8 window is used to set up the four bin files, their hex addresses, speed, size, and mode.

First, tick the left box, then click the ... Button which allows you to add each individual file, and then type in the corresponding offset address for each file. Also, set:

Also select the correct COM port (it’s much less confusing if there are no other COM ports in use).

Check your settings very very carefully. When every option is correct, press the reset button on your Arduino and then press the ESP8266 Download Tool’s START button.

The Download Tool’s status button will change from IDLE to SYNC and then to DOWNLOAD, also the DETECTED INFO box will show what’s actually inside your Arduino’s ESP WiFi chip.

The firmware download takes around 40 seconds to complete, after which the status button changes from DOWNLOAD to FINISH. When the firmware has finished uploading, set DIP switch 7 to OFF, to prevent any accidental reprogramming of your new firmware.

To verify everything worked OK, start your Arduino IDE (or preferred Serial comms program), open the Serial Monitor and set it to 115,200 baud and Both NL & CR (New Line & Carriage Return). Press the Arduino Mega/WiFi's Reset button then type in AT+GMR. You will see a line of garbage followed by:

ready
AT+GMR
AT version:1.6.2.0(Apr 13 2018 11:10:59)
SDK version:2.2.1(6ab97e9)
compile time:Jun  7 2018 19:34:26
Bin version(Wroom 02):1.6.2
OK

If you don’t get a line saying “SDK version:2.2.1”, recheck everything, fix any typos or incorrect checkboxes and try again (don’t forget to set DIP 7 back ON first). When you do get this line, everything is good. By the way, you can ignore the first line of garbage, it’s just the ESP8266 responding with bootup information at 74,880 baud, before it switches to AT interpreter mode at 115,200 baud and displays the “ready” message. No doubt, it’s been left in for compatibility with old code.

That’s it really, to use your Arduino WiFi combo board as if it’s a standard Mega (or Uno) with an on-board ESP WiFi chip that responds to AT commands, and works with current Arduino WiFi libraries. Just set DIP switches 1,2,3,4 ON and 5, 6, 7 OFF and the slide switch to TXD3 (Mega only).

You can test if your WiFi actually works by using the H2O Timer software from Issue 031 Feb 2020, with just a Mega/WiFi combo board. Just set displayWiFi to true and displayRTC to false, and also enter your WiFi Name and password (in DIYODE-H2O-Timer.ino), and change the Arduino Serial Monitor baud rate to 250,000. When the program has been uploaded, the Serial port shows a WiFi connected message, similar to this.

No Touch Screen
WiFi connect #1
[WiFiEsp] Initializing ESP module
[WiFiEsp] Initilization successful - 2.2.1
WiFi - Connecting to Kitchen
[WiFiEsp] Connected to Kitchen

You can also upgrade ESP-01 firmware with the ESP8266 Download Tool, but it’s much more complex and requires making a programmer.

Part 2