In desktop/web application I've got lots of options for error logging. A microcontroller doesn't really have such an option though, the best I can think of is to dump messages to the Serial output.
If there a best practice/good advice for how to handle error logging at runtime?
A Arduino Uno has a microcontroller which can do awesome things with its hardware, but the software is limited. Turn a led on, turn a led off, check an input, and so on. Writing good code is main goal.
Newer processors have more memory and can capture software exceptions, but most Arduino boards do not have a (micro)SD memory card. The Serial output is indeed the most common debug output.
A few simple error counters can be stored in EEPROM.
I wonder why you ask this ? Do you have a bad Serial/UART communication or a bad I2C bus or is your sketch so bad that you need error logging ?
For one project, I stored data in EEPROM. After a year I checked how many error there were, but it turned out that my code was wrong and the EEPROM data was useless.
For another project I count the communication errors between a serial Nextion display and the AltSoftSerial library on a Arduino Uno. I can show that error count on the display, it says zero errors after a few years running.
That is all I use, that is very minimal.
A ESP32 has a FreeRTOS operating system and can "store" a file in Flash memory. That file might become too big, or it might fail with a big crash. Even the underlying ESP32 system shows errors to the Serial output.
When a ESP32 runs on its own without capturing the Serial debug output, you might never know what went wrong. That's how it is.
What's wrong with logging to the serial port? Is it already in use?
That made me chuckle. Sounds like exactly the sort of thing I'd do.
There's no particular errors I want to catch, just a broad question around best practice. I like the EEPROM idea though, I could also dump logs to an SD card.
Nothing. Serial is my current technique, I'm just canvasing for opinions.
It sort of depends on the application and environment, what should happen to the reports. A debug report from a machine that's not connected to anything isn't much use... many MCU applications are stand alone, all you can usefully provide is an error LED, or some equivalent behaviour that gives a clue something has gone wrong.
I like @Koepel's suggestion of using the EEPROM. I'd like to let it run for a while and then check the EEPROM or an SD card for any logs.
Make it a circular buffer. EEPROM is tiny compared with SD. Either way, watch out you don't create code that freezes or malfunctions when the log memory is full.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.