Serial monitor is a very popular tool in Arduino programming. It is the default interface for programmers to 'talk' to Arduinos.
Here is a code snippet of using serial monitor to send data to your computer.
You may be taught that the baud rate is a magical number which must be the same in the code and in the serial monitor, otherwise a bunch of random nonsense codes would appear in the serial monitor.
However, this is not the case for XRCU. XRCU uses a native USB port, so it does not depend on the baud rate. The serial monitor will work even both baud rates don't match, as long as the Serial.begin(...) function is called.
Yet, it is still a good idea to keep a reasonable baud rate (e.g. 9600) in the Serial.begin(...) function. Sometimes you may want to reuse the same piece of code on an Arduino and on an XRCU, so keeping a reasonable baud rate reduces the changes we need to adapt when switching the board.
Now, try to upload the above code to XRCU and run it. Open the serial monitor with a different baud rate (e.g. 115200). See whether the serial monitor prints Hello, world! or a bunch of random codes. Is this the same as what you would expect to see?
Take a screenshot of the serial monitor with its baud rate and the output. Submit this screenshot to your assignment portal at checkpoint 4.1.
For traditional Arduinos, the data exchange speed with serial monitor is largely confined to the baud rate we choose. Since we don't have a Serial-USB converter acting as a 'translator' between XRCU and your computer, data could be exchanged much faster than Arduinos.
Remove the delay(100); statement in your code and run it on XRCU again. Open the serial monitor with timestamp. Observe the speed of new lines of Hello, world! being printed on the serial monitor. This is the speed an Arduino Uno could never produce, not even at its maximum baud rate of 2,000,000 bps. Could you guess how many lines are being printed every second?
Take a screenshot of the serial monitor with the output and their timestamps. Submit this screenshot to your assignment portal at checkpoint 4.2.
However, this instant large amount of information could flood the serial monitor. In Arduino IDE 1.X, the serial monitor could take up a large portion of your computer's memory in a very short period of time, causing the serial monitor and the IDE to lag. This is obviously a bad idea. That's why sometimes we would put delays to prevent sending too much data to the serial monitor in a short period of time.
On traditional Arduinos, the program is restarted every time you open the serial monitor. This is because the computer sends a reset signal via the USB power cable. However, XRCU does not rely on the power from USB cable. The program continues regardless of whether the serial monitor is opened or not.
Try to run the code snippet below.
Close the serial monitor before running this code. Only open the serial monitor after you started running this code. Disable auto-scroll in serial monitor. Observe the first number being printed. Is it 0? or is it a number larger than 0? Is this the number you expected to see in the first line?
Take a screenshot of the serial monitor with the first few lines of output. Submit this screenshot to your assignment portal at checkpoint 4.3.
Sometimes we don't want to miss any data from XRCU. For this, our program would need to wait for us to open the serial monitor. Fortunately, this could be easily achieved.
We could simply add a line while (!Serial) {} after Serial.begin(...); to wait for the user to open serial monitor on their computer. You could imagine Serial as giving false when the user hasn't opened the serial monitor yet, and turns true after the user has opened the serial monitor.
Try to run the code snippet below.
Close the serial monitor before running this code. Only open the serial monitor after you started running this code. Disable auto-scroll in serial monitor. Observe the first number being printed. Is it 0? or is it a number larger than 0? Is this the number you expected to see in the first line?
Take a screenshot of the serial monitor with the first few lines of output. Submit this screenshot to your assignment portal at checkpoint 4.4.