LESSON 03 – OUTPUTTING TO SCREEN

 

TRADITIONAL OUTPUTTING

 

In most programming languages, the first program that we learn is usually how to output a message to screen. 

 

We will do the same here with our Arduino.

 

SERIAL COMMUNICATION

 

Arduino programs are loaded onto the Arduino and executed from there.  If we want to output a message on the computer’s screen, then we need to have a form of communication between the Arduino and the computer.

 

Serial communication allows our Arduino to send messages back to our computer (via USB connection). 

 

There are two simple steps to sending a message.

 

First, we need to establish a connection.  This is only done once in the program (even if we send many messages) so we place this in the setup function.  The statement that does this is:

 

            Serial.begin(9600);

 

Then, we can send a message by using:

 

     Serial.println("Hi");

 

Note that any text that appears between the quotes will be displayed in the Serial Monitor on the computer.

 

Important: To see the message on the computer, you must have the Arduino software open and have the Serial Monitor open (Tools > Serial Monitor).

 

PRINT vs PRINTLN

 

We can use either

 

     Serial.println("Hi");

 

or

 

     Serial.print("Hi");

 

The difference is that the println() command brings the cursor to the next line while the print() command leaves it immediately after the message.

 

 

TRY THIS…

 

PRACTICE PROGRAM 01

 

Make an Arduino program output the message “Hello World” to the computer’s screen once.

Note: If this is your first program, you might have to go under Tools and choose the correct Port.  This only needs to be done once.

 

Alterations

 

a)    Try pressing the reset button on the Arduino to restart the program. You should see “Hello World” appear another time.

b)    Try changing the program so that “Hello World” is appearing continuously.

 

PRACTICE PROGRAM 02

 

Inside the setup() function, display two different messages to screen.  Try using println() and then changing to print() to fully understand the difference between the two.