Pages

Friday, January 10, 2020

ESP32 Brownout problem

For an index to all my stories click this text

I have been doing a lot of tests and projects on the ESP32. And just as with the Arduino or ESP8266 you just write a program, upload it from your computer and it works.

And then suddenly I encountered some severe problems.



The programs would not start and the Serial Monitor showed the above text: Brownout Detector was triggered. This did not occur all the time but only when some heavy programming was involved. In my particular case it happened when I was develloping a program that included multiple libraries:


#include <Time.h>
#include <TimeLib.h>

#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUDP.h>

And an extra speech synthesizer library, on which I'll come back in a later story.

Please note that I am using the ESP32 Devkit board V1 from DOIT. This problem might not occur with other boards. I also noted that the problem occured when Wifi was activated (and therefore power consumption was increased).

Brownout detection.

I thought it was strange that this error occured as I knew from the Attiny 85 micro controllers that Brown-out Detection (BOD) is activated when the chip gets to low Voltage. And I had nothing attached to the ESP32. So nothing was drawing power except the ESP32 itself. Therefore the voltage should not get too low for the microcontroller to work.
Nevertheless the ESP32 detected the brownout and kept resetting itself.

Searching the internet revealed that many others encountered the same problem and some solutions were suggested:

- You are using a poor quality USB cable. Try to use a good quality one
- The USB cable is too long. Use a shorter one
- Bad computer USB port. Attach the ESP32 to another port
- Not enough power supplied through the USB port: Use a USB Hub with an external power supply.

I tried all of these suggestions and it did not help.

The solution.

In the end I found a software solution and I do not want to keep that from you.

The solution is to disable the Brown-Out Detection. This is obviously a makeshift solution as there is something wrong with the Devkit ESP32's power supply. But it works like a charm.

Start your program with the following lines:


#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

#define nobrownout true
#define lowtxpower true

In the start of the setup routine add the following line:


if(nobrownout) WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);

This seems to solve the problem.

From the moment I incorporated these lines into my ESP32 programs I did not encounter this problem again.

Solution number 2

I started experimenting and I found another solution.

It occurred to me that the Brow-Out Detection was triggered by a Voltage drop. I was programming my ESP32 from my USB port and when the programming was finished the ESP32 rebooted and started its program. The ESP32 however was still attached to the USB port of my computer. This way I could monitor the proceedings over the Serial Port.

So I decided to program the ESP32 with my computer and then attach the ESP32 to a power bank. I have a big powerbank which has 2 outputs. One supplies 1A and the other port supplies 2A.

Guess what. This solved my problem.
So it seems that the USB port of my computer is not capable of supplying enough power to get the ESP32 fully working.

This also worked with a USB power supply.

The setback is that this is only good when your program is finished as you are not able to monitor anything through the Serial Port.

Solution number 3

This one is a bit tricky, so you have to be absolutely sure of what you are doing.
I decided to use a double power supply for the ESP32.



I plugged the USB port of the ESP32 into my computer and attached a second power USB supply to the V-IN pin of the ESP32 and that worked flawlessly !!! Be aware that the actual connections on your USB breadboard connector might be different as displayed above. GND and VCC might be on different pins !! And I see I mixed up the colors of the wiring. GND should be blue and VCC should be red.

The ESP got enough power to work and at the same time had a connection with my computer so I could monitor data through the Serial Monitor.

If you do this make sure you use a decent 5Volt power supply. You are connecting an external power-supply indirect to the USB port of your computer. If anything fails you are in risk of damaging your computer !! So make absolutely sure that you are using an excellent external power supply, which does not deliver more as 5 volts.

Till next time

Luc Volders