-
Notifications
You must be signed in to change notification settings - Fork 225
Continuous Logging
There are multiple reports of users having problems with logs containing dropped characters at baud rates above 9600bps. Here are some tips and tricks to get more of your characters logged at higher baud rates.
Format your card
Remember to use a clean card with few or no files on it. A microSD card with 100MB worth of ZIP files or MP3s has a slower response time than an empty card.
Add delays between character writes
By adding a small delay between Serial.print() statements you can give OpenLog a chance to record its current buffer. For example:
Serial.begin(115200);
for(int i = 1 ; i < 10 ; i++) {
Serial.print(i, DEC);
Serial.println(":abcdefghijklmnopqrstuvwxyz-!#");
}
May not work because there are a lot of characters being sent right next to each other.
Serial.begin(115200);
for(int i = 1 ; i < 10 ; i++) {
Serial.print(i, DEC);
Serial.println(":abcdefghijklmnopqrstuvwxyz-!#");
delay(15);
}
Inserting a small delay of 15ms between large character writes will help OpenLog record without dropping characters.
This card works but this one doesn’t
There are many different types of card manufacturers, relabeled cards, card sizes, and card classes. It’s maddening. We always use a regular, generic, 1GB microSD card. It works great for us at 9600bps. If you need higher baud rates you may want to try larger, class 6 and above cards. We cannot guarantee that a faster card will work better – the evidence is very spotty.
Use 9600 baud
OpenLog has a limited amount of RAM (2048 bytes). When you send serial characters to OpenLog these characters get buffered. The SD spec allows an SD card to take up to 250ms to record a data block to flash memory.
At 9600bps that is 960 bytes (10 bits per byte) per second. That is 1.04ms per byte. OpenLog currently uses a 512 byte receive buffer so it can buffer about 500ms of characters. This allows OpenLog to successfully receive all characters coming in at 9600bps. As you increase the baud rate, let’s see how long our buffer will last:
- 9600bps = 1.04ms per byte = 532ms before buffer is overrun
- 57600bps = 0.174ms per byte = 88ms before buffer is overrun
- 115200bps = 0.087ms per byte = 44ms before buffer is overrun
The solution is to use a lower baud rate, increase the buffer size by moving to an IC that has more RAM, moving to an external RAM solution, or increase the amount of time between the characters sent at the higher baud rate.
Related Issues
Here is a list of issues that are related and have been discussed in the past:
Continuous binary logging data loss : https://github.com/nseidle/OpenLog/issues/62