Finally we are making waves, hopefully you are following along and grasping at the straws I am throwing your way. This lesson will teach you how to get your fancy Arduino talking, well not yet but it will display words. We will get to sounds soon enough.
STEP#1: Getting Started
Open up your Arduino sketchbook and create a new sketch and name it "Hello World".
Next copy and paste the following code into your sketchbook.
/* * Hello World! * * This is the Hello World! for Arduino. * It shows how to send data to the computer */ void setup() // run once, when the sketch starts { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Hello world!"); // prints hello with ending line break } void loop() // run over and over again { // do nothing! }
Ok lets get to work, notice how the loop is empty. Regardless the arduino requires the "setup" and "loop" to be included in the sketch even if they arent doing anything.
Take a look at the first line of code in the "setup" procedure.
Serial.begin(9600); // set up Serial library at 9600 bps
First thing we see is the word "Serial" as you read it looks as if this may be a procedure call as well. This is defined as a libary procedure call. The library is named "Serial" and in that library is a procedure called begin.
library name
|
.
|
procedure name
|
(input values)
|
;
|
---|---|---|---|---|
Serial
|
.
|
begin
|
(9600)
|
;
|
begin: This is a procedure that gets the serial things ready.
bps: This stands for bits-per-second aka baud rate
OK so Serial.begin sets up the Arduino with the transfer rate we want, in this case 9600 bits per second.
Now on to the next line.
Serial.println("Hello world!"); // prints hello with ending line break
Again the Serial library, but this time it's using a procedure called "println"
printIn: This is short for print line
Upload the sketch to your Arduino and continue to the next step.
STEP#2:
Once you have uploaded the sketch to your Arduino you should see...... nothing new lol.Do not worry though the reason nothing seems to be happening is because we need a monitor to view the serial data happening. Lucky for us, Arduino has one built right into the Arduino sketch program. Different versions of Arduino have different locations to find the "Serial Monitor".
As you can see mine is easy to locate. Once you find yours click it.
Depending on the type of Arduino you are using you may get different results such as resetting the uno then the sketch will run either way it will run. It may just be a matter of waiting seconds longer. You should now see your hard work paying off. If you experience what looks like mashing of the keyboard try changing the "baud rate". This is located in the lower right corner. ** Try clicking on the reset button and see what happens.
/* * Hello World! * * This is the Hello World! for Arduino. * It shows how to send data to the computer */ void setup() // run once, when the sketch starts { Serial.begin(9600); // set up Serial library at 9600 bps } void loop() // run over and over again { Serial.println("Hello world!"); // prints hello with ending line break delay(1000); }
Still wanna play around? Why not play around with this code. Play around with the delay(500)? or even be crafty and change the Serial.println("I'M LEARNING")
Proceed to Lesson#5
No comments:
Post a Comment