Serial
Serial communication is a digital, two wire method of sending and receiving text data between two devices. Laptops no longer have physical serial ports, but USB communication can emulate the data transfer. When you plug an Arduino or Teensy into a computer, a port name is created, like COM4 on Windows or tty.usbserial####. Both devices are configured to send and receive data at a number of bits per second, or baud. If these numbers do not match, the data is misinterpreted and garbage.
To use serial communication on the Teensy, enable the module in setup() using Serial.begin(). To print text to the computer, use Serial.println(). The “ln” at the end of the print function sends the return character after the line of text is printed. If you want to print some text and the value of a variable, use the ‘ln’ only with the last print function.
For example, Serial.print(“The value of i is “); Serial.println(i);
Print a line of text containing the button and potentiometer data
Make a new file and initialize the serial and button pin functions. If the button is pressed, read the value of the potentiometer and print it to the computer as “Pot Voltage= “ and the value in volts. Open the serial monitor and press the button a few times. Do you notice any repeated prints? Any problems converting the integer number from analogRead() to a floating point number as volts?
Read text from the monitor
You can send text to the Teensy using the serial monitor by typing in the textbox and pressing send. The data is sent one letter at a time. The function Serial.available() returns if any letters are available to read on the Teensy, and can be read with char c = Serial.read().
Wait for a character, collect potentiometer data and plot
Make a new file and write some code to send 100 values from the potentiometer at 100Hz after reading a “r” from the serial monitor. Try running it from the serial plotter as well.