This number does nothing...
Yes, I know it's a bit click-baity - but I'm struggling to come up with entertaining and amusing titles...
UPDATE - I gave it a quick test on an old ESP32 board with a USB-to-serial converter and got 2.26 Mbit/s. This is with a baud rate set to 3,100,000 - which is the highest I set it to and get consistent results.
What are we talking about? This line of code that appears in pretty much every single Arduino sketch/project:
Serial.begin(115200);
This line of code is everywhere - a quick search on GitHub finds over 450,000 instances of it.
I started to question this when I was testing out my new boards. I was streaming audio from the board and noticed that the rate I was receiving data at bore no relation to the baud rate I was setting.
If we look closely at the image, we can see that we connected to the serial port at 115200 baud. This matches exactly what I put in the Serial.begin
of the firmware.
This baud rate (115200) should give us 14.4kByte/s. But if we look at the rate at which we are receiving data, we can see that it is much higher. 94.7kByte/s.
What on earth is going on?
Well, my board is based around an ESP32-S3. This has native USB support - and the serial connection is running over the USB connection.
We don’t have a USB-to-serial converter on the board.
There is no UART.
Which means there’s no actual baud rate (this is not strictly true, it is possible to find out what the baud rate was set to - but that’s for another day).
I did a quick test to confirm this - I ran the firmware with 115200 and then connected with a python script that tried a variety of baud rates.
As you can see from the results - everything just worked.
A good question to ask now is, just how fast can we send data? What’s the limit?
Well, USB Full Speed is 12Mbit/s. With overheads and other factors, realistically we should be able to get around 9.6Mbit/s.
So I wrote another quick bit of code to test this. The firmware sends out a 4MB payload and a python script received it. Just to make sure there’s no cheating I run a CRC check on the data.
With an arduino version of the firmware, I was able to get over 7Mbits/s.
With the ESP32-S3 version of the firmware, I was able to get over 5Mbits/s.
The IDF is surpsingly slower than the Arduino version. There’s is an issue open at the moment on the ESP32 TinyUSB implementation that may fix this at some point.
Obvisouly, my tests are very much raw performance tests. Real world behaviour is likely to be very different.
But it’s interesting none the less. Obviously, with boards that have a UART, you will be limited by the ESP32 UART hardware. I believe this maxes out at 5Mbits/s but I’m planning to test this soon.
All my test code is available on GitHub.
Have a watch of the video - it’s got some fun bits and more details.