RobotKitMenu-1

From ArduinoInfo
Jump to navigation Jump to search

BACK to MENU
SideWhiteBack1-128.jpg

START: YOURDUINO BASIC ROBOT KIT

Please email comments, critiques, suggestions and questions to: terry@yourduino.com
The OLDER Version 1 Info(Click HERE):

This section will help you get the Arduino software downloaded and installed, and have a first look at programming the YourDuino RoboRED Microcomputer that will control your robot. Oh: What's an Arduino Anyway?? See HERE:

I have Arduino working, I know all this and I want to just Build The Robot! (SKIP AHEAD)


Unpacking Your Robot Kit and getting out a few parts: GO HERE: and then return.



GETTING STARTED

The Arduino "IDE" software you will use to program your Robot looks virtually the same on Windows, MAC or Linux, but the Installation procedures are different. Below, you can pick which one you need.

Oh.. "What's this IDE thing all about anyway" ?? The Arduino Integrated Development Environment (WikiPedia) is the software you use on your computer to write software Sketches and then upload and run them on the YourDuino hardware. The IDE is like a word processor for writing software.

Now, go to the page for your Operating System to download and install the software for your operating system:

Then come back here!

MY Arduino / YourDuino board is board is already installed! OK, (CONTINUE BELOW)



==RoboRed-Annotated-900E16.jpg==

CHECK OUT THE NEW YourDuino RoboRED:

The new YourDuino RoboRED is now used in these Starter Kits. It is equivalent to an Arduino UNO, but has added features.

NOTE: The RoboRED MAY have a switch labelled 3V3 5V that can change the operating voltage. Usually there will be a jumper that is to the Right for 5V. If you have the switch make SURE it is in the 5V position as shown.
Near the upper left is the PWR LED which should light up whenever the board is plugged into a USB connection, or has power from an external power supply.
At the upper left there are two added red LEDs which will blink when a software sketch is being uploaded to the board, or other data is being transferred over USB.
In the center is a red LED which is internally connected to pin 13 through a current-limiting resistor. It should blink after you load the example BLINK software sketch. The colored 3-pin connectors on every I/O Pin make it easy to connect many input and output devices. Vcc(+5V) pins and (Ground) pins with every I/O pin are good for connections to breadboards etc.


(FOR ALL OF US, NOW: MAC, WINDOWS, LINUX):

RUN THE ARDUINO "IDE" SOFTWARE:


You should have followed the IDE Installation for your PC/MAC Operating System and now you've got your YourDuino plugged in and running. The POWER "ON" LED is on, right? You have successfully UPLOADED the "Blink" Sketch? And the "13" LED is blinking? (This may be a little different for the various YourDuino versions and the '13' LED may or may not blink now).

Soon we'll start connecting the things in the Kit, but first we'll use that built-in Pin 13 LED to get started. You'll see how to edit Software Sketches and change the way hardware reacts.



"SOFTWARE TIME" : WRITING ARDUINO SKETCHES

Let's take a little while to get used to writing Arduino Software, then we'll come back and start connecting your Robot kit parts and making more interesting things. We will give you software examples to test each part of the Robot kit. On your desktop you should now have the Arduino ICON like this:

Arduino-Icon1-68.jpg

Click on it, if you haven't already, and you should see the "Arduino IDE Window" pop up like this: IDE-topE-900.jpg



You'll use this IDE (Integrated Development Environment) to make Software VISIBLE! With it you will develop your own software to make Arduino into what you want it to be.

FIRST, YOU MUST SET THE CORRECT BOARD TYPE AND SERIAL PORT:

In the Arduino IDE top menu click <Tools> and then <Board>. You will see a drop-down menu that looks like this (left).

NOTE: For the YourDuino RoboRED in all current kits, pick "Arduino UNO". (Same for PC and MAC)
SERIAL PORT: Now click <Tools> and then <Serial Port>. On the PC There will usually be only one choice. But you may have COM1 and then some higher number which is Arduino.
PC-Board-Select-450.jpgPC-Select-SerialPort-450.jpg

MAC

MAC-SelectSerialPort-450.jpg
On the MAC, see the example above. Pick the entry that has both "tty" and "usbserial" in it.

OK, you're ready to upload software sketches to your YourDuino or Arduino!

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 Editing a Sketch and Verifying it and Uploading it:

LCSS-IDE-Blink.jpg
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. Click on FILE and then move your mouse (slowly.. It's Fussy!) over EXAMPLES to BASICS and then to BLINK so it looks like this (above):
And CLICK on BLINK).
LCSS-IDE-BlinkCode.jpg



A new IDE window should pop up and look like this:
Wow.. A bunch of new stuff.

Let's slow down and "Watch Closely Now"! Notice that a lot of the text is GRAY. 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 Editing software, Verifying it, and Uploading it to see Arduino DO it. We will use the YourDuino version of Blink: YourDuinoStarter_Blink . Click on the link to see it's page.

Now, highlight all the code (in the gray area) , do <Ctrl>C to Copy.
In the IDE, click the New button to get a blank page and do <ctrl>V to Paste it in. Click Verify to make sure it's OK. You should see "Compiling Sketch" and then "Compiling Done". Now look at the sketch in detail. Take some time to read it slowly.

STRUCTURE OF ARDUINO SOFTWARE:

Every Arduino Software Sketch has two main parts:

  • 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 YourDuinoStarter_Blink example through carefully, a couple of times. Note the colored special words that are Instructions . These are unique words that tell Arduino what to do. They have to be spelled perfectly!

What SETUP does: Tells Arduino about things that need to be done once. 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.
pinMode.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. Change the Capital "M" to "m". Note the color changes to black. Hmmm. Click the VERIFY VerifyButton.jpg button.

You will get an ERROR message: external image ArduinoIDE-pinmode-error.jpg

Fussy, Fussy, Fussy! Yep, every letter has to be correct and also correct upper or lower case.

Change it back. Check the color. Click Verify again. OK??

What LOOP does: Loop contains all the active parts of your Sketch that continue to run after SETUP is finished. It will run over and over again, forever, or until you stop it or power down.

What does VERIFY do?? 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 they're OK, then it "compiles" or "translates" the sketch into the machine code that Arduino actually runs on. It saves that 'ready-to-run' code for you to Upload to Arduino and run. Other systems would call this process "Make" or "Compile". Arduino refers to it as "Build" and if you want the gory details (Click Here). This is an example of how much Arduino lets you ignore some gory details!

What does UPLOAD do?? UploadButton.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(W)) 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.
[NOTE: The (W) Means this is a Wikipedia link.]

Start Making Changes:

Ok, let's make a few changes to the YourDuinoStarter_Blink program:

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:

Instruction: digitalWrite


This instruction sets an OUTPUT PIN to either HIGH (connects it to +5 V) or LOW (Connects it to GND). Lots of new words will be thrown about here!

Thing To Remember: HIGH = 1 = ON = 5 Volts and LOW = 0 = OFF = 0.0 Volts

So, the first line in LOOP sets PIN 13 to HIGH. This means Pin 13 is connected to +5 Volts, and current flows through a resistor and LED that are already connected to pin 13 on the Arduino board. The LED lights up.

Instruction: 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 ";" (Semi-Colon)

Notice that every instruction is followed by the character " ; " which is like a period that tells the end of a sentence. Run-on sentences will make you stay after school to fix your error messages!

Change the delay so that the LED blinks differently:

Time to mess about and try some things! Maybe we'll break it. Then we'll fix it..

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 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 short. Maybe 50 Milliseconds. That's 1/20 of a second. Change the first delay instruction to be delay(50);

Then try 10 milliseconds. The LED is only on 1/100 of the time. Can you still see it blink? How about 1 millisecond?

Each time you make a change, click UploadUploadButton.jpg which will first Verify and Compile your program and then send it to Arduino. Notice that each time you do this the LEDS on the Arduino board that are marked "Tx" (Transmit) and "Rx" (receive) flash as your main computer communicates with your Arduino.

Try out some combinations of ON and OFF delay() 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"(W) 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? Depending on your personal eye's physiology, at some speed you will not see any more blinks. Young people can usually see faster blinks than old codgers like me :-)

ASIDE: This control of brightness/power by changing the ON time vs the OFF time is called Pulse Width Modulation (PWM) Arduino has a built-in capability of doing it with the analogWrite command.

All right. You are hacking code. You're the Programmer! You can save any of the sketches for use later on. Go to File>Sketchbook and you'll see them.

Next, we'll start hooking up the Parts in your Robot Kit! And we'll give you example Software Sketches for each one of them.

Go To the Next Section: MicroComputer Software OR back to the Main Menu:


Please email comments, critiques, suggestions and questions to:
terry@yourduino.com