I've read that the value of BaudRate in Serial.begin(BaudRate) makes no difference for the Moteino M0. (I've also read that Serial. and SerialUSB. do the same thing). Indeed, my experience is that it doesn't matter what the value of BaudRate is, it seems to run at the same unknown baud rate. And it does not matter what BaudRate the Arduino IDE Serial Monitor is set at, it still displays the data sent just fine.
Does anyone know how this all works? What is the baud rate? How does the specified IDE baud rate get overridden/ignored? How can I increase the baud rate over the USB port?
I need to increase the serial baud rate in order to get all the data I am collecting over the radio link and from other sensors up to the PC at my desired sample rate of at least 100 samples per second, preferably 400. For debugging I am doing this over the IDE's serial monitor in CSV format. Ultimately I will be sending the data to a Processing program on the PC in binary format. That alone may solve the problem but I sure would like to understand how this all works!
Thanks! -JD
UART serial !== USB serial. Therein is the mistery.
A baud is purely a clock thing, for hardware UARTs. With USB you are emulating a serial port over CDC (communication device). It is packetized over USB etc. Very different than a hardware UART.
A slow serial over USB likely means your program is slow to print it.
Okay, I guess I've been living in the insulated world of the Arduino UNO for too long. Reading the Wikipedia page on USB in the System Design section I see this:
QuoteWhen a USB device is first connected to a USB host, the USB device enumeration process is started. The enumeration starts by sending a reset signal to the USB device. The data rate of the USB device is determined during the reset signaling. After reset, the USB device's information is read by the host and the device is assigned a unique 7-bit address. If the device is supported by the host, the device drivers needed for communicating with the device are loaded and the device is set to a configured state. If the USB host is restarted, the enumeration process is repeated for all connected devices.
I am going to guess then that the Arduino UNO uses a UART and the IDE knows that since I told it it was a UNO (duh!) so the baud rate must be specified on both ends. Since I then told the IDE I was connecting to a Moteino M0, it knows it uses a USB and ignores the baud setting in the IDE and the begin() function.
Indeed, if I simply wrap my Serial.println() line with a for loop causing it to repeat 100 times each time through the loop, the serial monitor zooms along at a blistering pace. Upon further inspection I saw the delay() in the blink function, removed it and, voila! Things sped up nicely. Doh! again.
Thanks for pointing me in the right direction, Felix. Please let me know if I've got any of this wrong. Otherwise, this is solved for me.
The only thing I would add is that for UNOs, Moteinos, AVRs in general which connect through their UART serials, the Serial.begin(baud) has to match the serial monitor or terminal baud.