Connecting over serial#
The most common way to get data from an Arduino is to send it over the Serial port with a USB cable.
It is doubly convienient as it is also the normal method to upload compiled programmes onto the Arduino.
Requirements
An Arduino (we have used an UNO)
Code#
There is a lot of example code available for connecting over the serial port so this will be a brief tutorial. Nearly everyother (or probably actually every) tutorial includes some serial communication
void setup() {
// Initialize serial communication with a baud rate of 9600 to USB
Serial.begin(9600);
}
This sets up serial communication between the Arduino and whatever is on the other end of the USB cable. It defines the baud rate of the communication.
This can be one of many different values, but commonly you will find values of 9600 and 115200 bits / s. Normally stick to one of these so as not to leave a surprise.
Once the connection is confirmed you can now print to serial. By adding a line of code like the following
Serial.Print("Your Text");
this prints what ever is in the brackets, but does not put in a new line. Any more calls to Serial.Print will be on the same line as the previous On the other hand
Serial.PrintLn("YourText");
prints the text followed by the new line character (“\n”)