ESP32-C3 lags when not powered by a computer

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ethannordhaug
 
Posts: 5
Joined: Wed Feb 02, 2022 2:54 pm

ESP32-C3 lags when not powered by a computer

Post by ethannordhaug »

I am encountering a strange issue which only occurs on a new ESP32-C3, which does not occur on the ESP32 DevKitC with the same code.
I am not sure if it is the WiFi, or some other component which is struggling, however I am noticing a huge contrast between WiFi speeds/latency based on whether or not the device is plugged into my computer or a power bank.

When powered by a power bank, the device struggles to send sensor data over MQTT, with other MQTT clients receiving these messages at about 1 message per 1-2 seconds

When plugged into my computer, where I use the Arduino IDE for develpoment, the device works smoothly and is able to send 5-10 messages per second, even with multiple sensor data points.

Something interesting to note aswell, is that sometimes during development, the code flashed to the device would only properly run once the Serial Monitor is running.
I have a feeling that when the device is plugged into my computer, is is running in some sort of debug/flash mode where it is allowed to act differently than when only power is being sent over the USB.

As for connections to the ESP32-C3, I have a MPU6050 sensor wired to 3.3v power, and a RCWL-1604 distance sensor wired to GPIO pins 20 and 10.

As for the moment, I am unable to utilize the ESP32-C3 for my use case until it is able to run properly and consistently on power sources excluding the development computer.

Is there something im missing?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: ESP32-C3 lags when not powered by a computer

Post by adafruit_support_mike »

That's likely to be a power issue.

Double check the connection between the ESP32 and the power bank to see how much current the chip is really getting. A standard USB connection can deliver 500mA, and USB-C Power Delivery can handle several Amps.

User avatar
ethannordhaug
 
Posts: 5
Joined: Wed Feb 02, 2022 2:54 pm

Re: ESP32-C3 lags when not powered by a computer

Post by ethannordhaug »

adafruit_support_mike wrote:That's likely to be a power issue.

Double check the connection between the ESP32 and the power bank to see how much current the chip is really getting. A standard USB connection can deliver 500mA, and USB-C Power Delivery can handle several Amps.
As a power bank, I was using the Powerboost 1000C with a 2200mAh-ish battery, which is also charged where I have no low-power LED.
But I went ahead and tried another powerbank, a typical consumer phone power bank, while still using the same cable used when connecting to my computer and the PowerBoost 1000C, the lagging issue still persists.

I would like to clarify that the entire device could be lagging, however, I am only able to see that the incoming MQTT messages are highly delayed, and also that it seems to be skipping many of the messages that it was meant to send. I notice that movements to the MPU6050 sensor are detected with typically a 1-2 second delay, which makes me believe I am not receiving the other 4 updates per second

User avatar
ethannordhaug
 
Posts: 5
Joined: Wed Feb 02, 2022 2:54 pm

Re: ESP32-C3 lags when not powered by a computer

Post by ethannordhaug »

I have made an interesting finding after finding an unrelated but similar issue online.

Someone had suggested that the ESP32 may be having issues writing to Serial when there is no computer attached, and so I commented out all lines including Serial.begin, and Serial.println, and now my code is running much faster, with the exception of random freezing which occurs for an unknown reason.

While this solution helps, it is difficult to have to comment out all mentions of Serial output whenever testing the project away from the computer. I have not experienced this issue with my ESP32 DevKitC, is this something that can be fixed, or a limitation of the small-size?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: ESP32-C3 lags when not powered by a computer

Post by adafruit_support_mike »

ethannordhaug wrote:As a power bank, I was using the Powerboost 1000C with a 2200mAh-ish battery, which is also charged where I have no low-power LED.
But I went ahead and tried another powerbank, a typical consumer phone power bank, while still using the same cable used when connecting to my computer and the PowerBoost 1000C, the lagging issue still persists.
The first rule fo debugging is 'don't believe anything you haven't confirmed instrumentally'. Device specs tell you what's supposed to happen, instruments tell you what actually happens.
ethannordhaug wrote:While this solution helps, it is difficult to have to comment out all mentions of Serial output whenever testing the project away from the computer. I have not experienced this issue with my ESP32 DevKitC, is this something that can be fixed, or a limitation of the small-size?
Serial functions are written to fail transparently when there's no signal connection, but it's a good idea to wrap debugging statements in a macro that can be turned on or off.

User avatar
ethannordhaug
 
Posts: 5
Joined: Wed Feb 02, 2022 2:54 pm

Re: ESP32-C3 lags when not powered by a computer

Post by ethannordhaug »

adafruit_support_mike wrote: The first rule fo debugging is 'don't believe anything you haven't confirmed instrumentally'. Device specs tell you what's supposed to happen, instruments tell you what actually happens.
I recently got a multimeter, so I will be sure to investigate power issues whenever I notice this pattern now
adafruit_support_mike wrote: Serial functions are written to fail transparently when there's no signal connection, but it's a good idea to wrap debugging statements in a macro that can be turned on or off.
That is a good idea and I will implement some sort of macro for this.

Is there any plausible reason as to why this lagging behavior would be correlated to Serial output?
Thanks

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: ESP32-C3 lags when not powered by a computer

Post by adafruit_support_mike »

ethannordhaug wrote:Is there any plausible reason as to why this lagging behavior would be correlated to Serial output?
Sure.. latency of a Serial object that keeps looking for a potential connection instead of failing immediately.

It's not what I'd expect, but I have no direct evidence to rule out the possibility.

User avatar
ethannordhaug
 
Posts: 5
Joined: Wed Feb 02, 2022 2:54 pm

Re: ESP32-C3 lags when not powered by a computer

Post by ethannordhaug »

adafruit_support_mike wrote: Sure.. latency of a Serial object that keeps looking for a potential connection instead of failing immediately.

It's not what I'd expect, but I have no direct evidence to rule out the possibility.
So far, it seems that I have found a general idea of how lag is occuring on the chip.
I realized that the code would run slowly regardless of where it was plugged in, however, opening the Serial Monitor in Arduino and PlatformIO would significantly speed everything up. After hiding all mentions of Serial output in the code as mentioned earlier, it runs fast anywhere it's plugged in.
In this case, the lag seemed to be isolated to MQTT publishing and not loop code.

I had an unrelated issue later on which also caused a constant lag in my code, even with viewing the Serial Monitor, all loop code would run almost exactly every second, this turned out to be because I had removed the RCWL-1604/HC-SR04 distance sensor temporarily, while relevant code was still present. After removing the distance sensor code, I am able to send 4+ data points up to 10 times per second somewhat smoothly with occasional lag spikes which I will just blame on wifi connectivity being spotty.

I believe I am in a good spot now to keep working with this project for battery use

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: ESP32-C3 lags when not powered by a computer

Post by adafruit_support_mike »

Glad to hear you've got it working. Happy hacking!

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”