GettingStarted-Software

From ArduinoInfo
Jump to navigation Jump to search

GETTING STARTED WITH ARDUINO AND SOFTWARE:

First, you need to get your real Arduino and the free Arduino Software installed and working. After that, come back to this page and we'll try out a few fun things...

Now, click on link to our page that is right for your computer and operating system:


Then come Blinkin' Back Here!
NOTE: If you are building the YourDuino Basic Robot go back to: RobotKitAbout
NOTE: If you have one of our Starter Sets , go to this page: YourDuinoEngStarter


( A little while Later )-------------

OK, so you've got your Arduino plugged in and running. The POWER "ON" LED is on, right? And the "L" LED is blinking? (May be a little different for the various Arduino clones). Here's a detailed look at the Arduino UNO external image ArduinoUno-LED13-800.jpg

Over on the right, the ON LED should be lit (usually Green). And over on the left, the "L" LED should be blinking (usually Yellow). (Unless you already downloaded some other software SKETCH to your Arduino.) Most Arduinos have an LED and a resistor permanently connected from Pin 13 to GND. They are inside the circle above. More details in a minute.

SOFTWARE TIME:

Let's take a little while to get used to writing Arduino Software, then we'll come back and start connecting your Electronic Bricks and making more interesting things.
You should have found and downloaded and installed the Arduino software, plugged your Arduino into USB, and set the right BOARD type and SERIAL PORT. If not, jump back to the top of this page and do that...

OK?? On your desktop you should now have the Arduino ICON like this:
external image Arduino-Icon1-68.jpg Click on it, if you haven't already, and you should see the "Arduino IDE Window" pop up like this:
external image Arduino-IDE-1.jpgThis is the INTEGRATED DEVELOPMENT ENVIRONMENT where you can make Software VISIBLE! Here you will develop your own software to make Arduino into what you want it to be.

SKETCHES:

The visible text of an Arduino software program is called a SKETCH. But the Sketch becomes alive when you upload it to your Arduino. Let's walk through looking at a Sketch and Verifying it and Uploading it:
Click on FILE and then move your mouse (slowly.. It's Fussy!) over EXAMPLES and BASICS and BLINK
so it looks like this:
external image Arduino-IDE-blink.jpg
And CLICK. There are lots of examples that come with the free Arduino software system, and we will look at some of them later, as well as make our own very soon.
A new IDE window should pop up and look like this:
external image Arduino-IDE-Blink-Code.jpgWow.. A bunch of new stuff.
Let's slow down and "Watch Closely Now"!
Notice that a lot of the text is GREY. All of that is just "Comments" for you to read to help understand the Sketch. When you write software, you should also use "Comments" to explain to others what you are doing. (Arduino itself totally ignores these comments).

Now, let's go through changing software, Verifying it, and Uploading it to see Arduino DO it. We'll use the BLINK example for now, but soon you'll start with a totally blank page and write your own programs.
Every Arduino Program has the same basic structure:

  • SETUP - Runs Once at the beginning
  • LOOP - Runs over and over again, forever

You will read a LOT of program "Code" that other people wrote, in the future. You HAVE to "Watch Closely Now" and really see the details. Read the example through carefully, a couple of times. Note the colored special words that are INSTRUCTIONS.

INSTRUCTIONS: Are unique words that tell Arduino what to do.

What SETUP does: Instructs Arduino about things that need to be done once. Remember that Arduino Digital Pins can be either INPUT or OUTPUT. You have to tell Arduino when a Pin will be used as an OUTPUT. In this example, there is one line that tells Arduino that Pin 13 must be an OUTPUT.

external image Arduino-IDA-Pinmode1.jpg


Note the COLOR of the lettering. The Arduino IDE changes the color of words as it recognizes them as special instructions. Let's mess with them:
pinMode: Note that when Instructions are two words run together, like pinMode, the beginning of the SECOND word is Capitalized. Mess with it: Change the Capital "M" to "m". Note the color changes to black. Hmmm. Click the VERIFY Button: external image ArduinoIDE-VerifyButton.jpg
You will get an ERROR message: external image ArduinoIDE-pinmode-error.jpg
Fussy, Fussy, Fussy! Yep, every letter has to be recognized.
Change it back. Check the color. Click Verify again. OK??

What does VERIFY do?? external image ArduinoIDE-VerifyButton.jpg

A lot! More details later, but Verify is a program in your main computer that goes through every Instruction in your Sketch (Ignoring "Comments") and checks it against the list of valid Instructions, and checks that the structure and sequence of the statements in the Sketch are correct. Fussy, Fussy! If that's OK, then it "compiles" or "translates" the sketch into the actual machine code that Arduino actually runs on. It saves that 'ready-to-run' code for you to Upload to Arduino and run.

What does UPLOAD do?? external image ArduinoIDE-Upload-Button.jpg

First, Upload runs Verify to check and compile your program. Then it communicates to your Arduino over the USB connection, resets the Arduino chip, and talks to software already on Arduino (called the BOOTLOADER) to load your new program into the Arduino's memory. Then it restarts Arduino and your program runs it's SETUP section and then repeats the LOOP section.
Start Making Changes:
Ok, let's make a few changes to the sample BLINK program:
external image Code-Blink1.jpg

The LOOP section of your program does all the instructions in the section, and then "loops" back to the top and starts it again, over and over.

NOTE: the "Brackets" { and }
Notice that the beginning and end of the section is "inside brackets". You will see many sections of bigger programs that are grouped by these "brackets".

Now, let's look in detail at the instructions:

digitalWrite

This instruction sets an OUTPUT PIN to either HIGH (connects it to +5 V) or LOW (Connects it to GND). Remember: HIGH = 1 = ON = 5V
So, the first line in LOOP sets PIN 13 to HIGH. There is an LED and resistor already connected to PIN 13, so the LED lights up.

delay

The delay instruction just waits for a period of time. The VALUE used with delay is in Milliseconds (1/1000 second). So delay(1000); waits for 1000/1000 seconds (1 second). We'll change that soon.
NOTE: the ";"
Notice that every instruction is followed by the character " ; " which is like a period that tells the end of the sentence.
Change the delay so that the LED blinks differently:
Time to mess about and try some things!
Suggestion: Save your own version of BLINK so you can always go back to the original one. Go to File and Save As and call it something like MyBlink. This will go in your SKETCHBOOK where you'll save your own programs.

Now go change the VALUE in a delay statement to change the way the LED blinks. Think about the the 4 instructions in LOOP. What's happening??

  • Turn the LED on. Wait and look at the LED.
  • Turn the LED off. Wait and look at the dark.

So, let's change the ON time to be very short. Maybe 50 Milliseconds.

Each time you make a change, click upload external image ArduinoIDE-Upload-Button.jpg which will first Verify and Compile your program and then send it to Arduino. Notice that each time you do this the LEDS flash that are marked "Tx" (Transmit) and "Rx" (receive) as your main computer communicates with your Arduino.
Try some combinations of ON and OFF times. Like ON 1000 and OFF 50.

Try making both ON and OFF times shorter and shorter. If you make the ON and OFF times short enough your eye will no longer see blinking, because of "Persistence of Vision" which happens when there are more than about 25 blinks per second. So, hmmm.... if you make the LED be ON for 1/50 of a second and OFF for 1/50 of a second that should do it. So try 1000/50= 20 Milliseconds. Put 20 for both the ON and OFF times. What do you see?? How about 10 Milliseconds each?

More detailed HOW-TO LINKS:


Hands-On Arduino Learning: Micromputer Engineering Set::
Hands-On Arduino Learning: Basic Starter Set::
Hands-On Arduino Learning: Electronic Bricks:
Example Software Sketches:

See "ARDUINO HOW-TO" on the right menu for more topics.