Practical Arduino Robotics by Lukas Kaul

Practical Arduino Robotics by Lukas Kaul

Author:Lukas Kaul
Language: eng
Format: epub
Publisher: Packt
Published: 2023-11-15T00:00:00+00:00


You can familiarize yourself more with the Serial Plotter by playing with the parameters at the beginning of this code. You can examine what effect enabling auto-scaling has (by omitting the min and max data lines) and what effects changing the print period has. You will find that too short of a print period can lead to unexpected, undesirable effects.

Explanation

Serial.print() writes the data to a transmit buffer and returns immediately. Behind the scenes, an interrupt-driven mechanism feeds the data from this buffer to the UART peripheral, byte by byte, without using the CPU. However, if you call Serial.print() too frequently or print too much at once, you may fill the transmit buffer faster than the UART can send the data. In this case, Serial.print() needs to wait for the UART to transmit the data and free up space in the buffer. Serial.print() then becomes a blocking call that can alter the behavior of your program. For this reason, adding printouts for debugging can sometimes make the bug disappear by unintentionally changing the timing of your program. This problematic phenomenon is jokingly called load-bearing printf. In practice, you want a high baud rate and leave a few tens of milliseconds between calls to Serial.print() to avoid this problem. You can also programmatically check the available space in the transmit buffer with the Serial.availableForWrite() function before a print command to be sure that you are not clogging up the buffer.

The Serial Plotter also has an input line, just like the Serial Monitor. With some modifications based on what we learned in the previous section, you can write a program that allows you to change the parameters of the sine and cosine waves on the fly right from the Serial Plotter. This is a great exercise to test and further your understanding of this chapter.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.