facebook

Visit Facebook page!

follow on facebook to get instant news and updates.

Friday, 1 August 2014

Lesson 1: Let there be blink!

Introduction
Ah yes, it is finally time to make your Arduino do something! We're going to start with the classic hello world! of electronics, a blinking light.
This lesson will basically get you up and running using the Arduino software and uploading a sketch to the Arduino board. Once you've completed this step we can continue to the really exciting stuff, which is when we start writing our own sketches!
These instructions mostly show Windows software. Except when indicated, the software (should be) identical on all platforms. Linux will be added once I figure out how to get it working (yay)
Do you have everything you need?
Not much is needed for this lesson, just a USB cable and an Arduino. If you have an older Arduino you may also need an LED. Any LED is fine as long as it looks sorta like the photo, with a plastic bulb and two legs
Make sure you've gone through Lesson 0 first!
Assembled Arduino board, preferrably a Diecimila (or whatever the latest version is)
$35
USB Cable. Standard A-B cable is required. Any length is OK.
Or any computer supply store

$5
LED - Optional
Nearly any LED is OK, as long as it has two wire legs. This part is only required for NG rev c Arduinos (and maybe other older ones). Diecimila Arduino's have this part 'built-in'
Any electronics supply store$1
Download the Software
The first thing to do is download the Arduino software.
Go to the Arduino Software Download page and grab the right file for your OS. As of Sept 2007 the version is 009 but you should use whatever is most recent.
The packages are quite large, 30-50 MB so it may take a while to finish
Unpack and Install
Extract the package onto the Desktop
 
Windows

Mac OS X

Windows

Mac OS X
Startup!
Double click the Arduino software icon
 
Windows

Mac OS X
To open up the workspace
I think I get the red error text shown because I already have Arduino installed. Either way, it isn't a problem if you do or don't see it.
Select chip
The first step is to configure the Arduino software for the correct chip. Almost all Arduinos use the ATmega168, but there's a chance you have an ATmega8. Look for the chip on the Arduino that looks like this:
 
If the text says ATMEGA8-16P then you have an atmega8 chip. If the text says ATMEGA168-20P then you have anatmega168 chip. If it says "ATMEGA328P-20P" you have an atmega328p chip
Make sure the correct chip is selected (this picture is really old, will be fixed soon). This preference is saved so you only have to set it once, the program will remember next time it's run.
Select port
Next, its time to configure the Serial Port (also known as the COM Port). Go back to lesson 0 to remind yourself of which port it is. On a PC it will probably be something like COM3 or COM4. On a Mac it will be something liketty.usbserial-xxxxx

Windows port selection

Mac port selection
This preference is saved so you only have to set it once, the program will remember next time it's run.
However, if you have multiple Arduino's, they may be assigned difference COM ports. So every time you plug in a new Arduino, double check that the correct port is selected.
Open blink sketch
Sketches are little scripts that you can send to the Arduino to tell it how to act. Let's open up an Example Sketch. Go to the File menu -> Sketchbook -> Examples -> Digital -> Blink
The window should now look like this, with a bunch of text in the formerly empty white space and the tab Blinkabove it
Verify / Compile
The first step to getting a Sketch ready for transfer over to the arduino is to Verify/Compile it. That means check it over for mistakes (sort of like editing) and then translate it into an application that is compatible with the Arduino hardware.
After a few seconds, you should see the message Done compiling. in the Status Bar and Binary Sketch Size: in theNotification area. This means the sketch was well-written and is ready for uploading to the Arduino board!
Reset (NG only)
To tell the Arduino that it should prepare itself for a new Sketch upload, you must reset the board. Diecimila Arduino's have built-in auto-reset capability, so you don't need to do anything. Older Arduinos, such as NG, must be manually reset before uploading a sketch. To do that simply press the black button on the right hand side of the board, shown here.
Upload
Now it's time to upload. Make sure the Arduino is plugged in, the green light is on and the correct Serial Port is selected.
If you have an NG Arduino, press the Reset Button now, just before you select the Upload menu item.
Select Upload to I/O Board from the File menu
After a few seconds you should get this screen, with the message Done uploading. in the status bar.
If you get the following error message "avrdude: stk500_getsync(): not in sync: resp=0x00" that means that the Arduino is not responding
Then check the following:
  • If you have a NG Arduino, did you press reset just before selecting Upload menu item?
  • Is the correct Serial Port selected?
  • Is the correct driver installed?
  • Is the chip inserted into the Arduino properly? (If you built your own arduino or have burned the bootloader on yourself)
  • Does the chip have the correct bootloader on it? (If you built your own arduino or have burned the bootloader on yourself)
If you get the following error message:
It means you dont have a serial port selected, go back and verify that the correct driver is installed (lesson 0)
and that you have the correct serial port selected in the menu.
If you get the following error Expected signature for ATMEGA
Then you have either the incorrect chip selected in the Tools menu or the wrong bootloader burned onto the chip
If you get the following error: can't open device "COM10": The system cannot find the file specified (under Windows, COM port value may vary)
It means that you have too many COM ports (maybe you've got 9 Arduinos?) You should make sure that the port is numbered as low as possible. You can use a program like FTClean to clear out old COM ports you aren't using anymore. Once you've cleaned out the ports, you'll have to reinstall the driver again (see lesson 0). 
Alternately, if you're sure that the ports are not used for something else but are left over from other USB devices, you can simply change the COM port using the Device Manager. Select the USB device in the Device Manager, right click and select Properties
Then click Advanced... and in the next window change the COM port to something like COM4 or COM5. Don't forget to select the new port name in the Arduino software. The lower port names may say (in use) but as long as the other USB devices aren't plugged in, it shouldn't be a problem. This is a little riskier than just using FTClean...
Video of all steps
Here is a video showing the timing of the steps described so far.

Insert LED (NG Arduinos)
Some older Arduinos don't have a built in LED, its easy to tell if yours does or not
If you have a Diecimila or other Arduino with a built in LED you will see a translucent part as shown
If you have an NG rev C or other Arduino without an LED, the translucent part will not be there, and instead you will see two silver dots
If you don't have an LED, you'll need to add your own. Any LED will do, as long as it has two legs and kinda looks like the one shown here. LEDs are directional components. That means if you put it in backwards it will not work! To help you put the LED in right, the LED factory cuts the legs at different lengths. The longer leg goes in the hole marked 13 and the shorter one goes in the hole marked GND

Lesson 0 - Getting prepared!

Introduction
This lesson won't teach any electronics, really. Its more for making sure that everything is setup and ready for the future lessons. It will verify the Arduino is working as intended and that the computer you are using is compatible.
Do you have everything you need?
For this lesson you will need some stuff! Make sure you have this stuff or you will be unable to complete this lesson
ImageDescriptionDistributor
Assembled Arduino board, preferrably an Uno, Diecimila or Duemilanove (or whatever the latest version is) but NG is OK tooAdafruit
USB Cable. Standard A-B cable is required. Any length is OK.Adafruit
9V DC power plug with 2.1mm barrel plug, positive tip
Optional
4 Rubber bumpers
Optional
These are included in Arduinos purchased from the Adafruit shop, otherwise any hardware store should have them.
$1
Preparing the Arduino!
Take your Arduino out of its protective bag. Look at it and make sure it looks kinda like this:

Diecimila Arduino
Or like this:

NG Arduino
If there's anything missing or really wrong, make sure to contact the store you bought it from. For example, here is an Arduino that is missing the two round silver capacitors!
OK, now that you are satisfied that your Arduino looks good, put the rubber bumpers on the bottom of the board. This will protect your Arduino from spills and dirty tables. If your table is made out of metal, this is essential!
Download & Install Drivers
Depending on which Arduino and which OS you have there are different instructions
Power up! (USB)

Now we are ready for the moment of truth, it's time to plug your Arduino in and power it up. The most common way to do this is to plug one end of the USB cable into the Arduino and the other end into a computer. The computer will then power the Arduino.
The jumper-setting step is only for Diecimila and OLDER arduinos! Make sure the Power Jumper is set correctly. Right next to the USB jack, there is a jumper with 3 pins. If the jumper is on the two pins nearest USB jack, that means you are planning to power the Arduino via the USB cable. If it's on the two pins nearer the DC Jack then it means you are planning to power the Arduino using a 9V battery or wall adapter.
You'll want it set as shown in the picture above.
Make sure your cable is a A-B cable. One end should be thin, rectangular. The other end should be square.
Plug the thin end into your computer
Make sure that the USB cable is plugged in directly to a computer port. Sometimes monitors or keyboards have a USB port you can plug into. Most of the time this is fine, but I strongly suggest you plug it directly into the computer as that will eliminate any possible problems. Same goes for USB hubs.
Later on, once you've verified you can power the Arduino and upload sketches no problem, then you can try plugging it into other ports.
Plug the square end into your Arduino
You should get a small green light on the right side of the Arduino, as shown here.
And a few blinking orange lights, on the left side.
If you're plugging it into a Mac or Linux machine, you may not get as much blinking from the orange lights. The video is from plugging into a Windows computer.
If no lights or blinking occurs, double check:
  • Is the USB cable plugged into the computer and into the Arduino?
  • Is the computer on?
  • Is the jumper set correctly?
  • Try another USB port, USB cable, and computer
If you still can't get it working, your Arduino may be faulty.
Next its time to install the driver! Follow these links for instructions for each of the supported operating systems
Power up! (9V DC, optional!)
Another way to power up the Arduino is to plug in a battery or wall adapter into the DC jack.
Verify that you have a 9V DC 100-500mA power adapter, with a 2.1mm barrel plug and positive tip. If the box doesn't have any information about the adapter, you can look for these clues
Make sure the symbol near the bottom of the label is present. It means that the outside of the plug is negative and the inside is positive. A center-negative plug will not work with the Arduino.
The jumper-setting step is only for Diecimila and OLDER arduinos! Make sure the Power Jumper is set correctly. The jumper should be set so that it connects the two pins close to the DC jack
Plug in the adapter and verify you get the green light!
If not, double check:
  • Is the DC adapter plugged in?
  • Is the DC adapter the right kind? Check voltage, polarity, plug size, etc.
  • Is the jumper set correctly?
  • Try another adapter.
If you still can't get it working, your Arduino may be faulty.

Driver installation for Windows,Mac OS X or Linux

UNO Driver Installation (Windows)
This is the procedure for UNO Arduino
When you plug in the Arduino, you may hear a sound from the computer and a little popup bubble in the bottom right corner of the screen that says Found New Hardware Arduino UNO
After a few seconds, the new hardware wizard will start. Select "No not this time" and click Next>
At the next screen, select Install from a list or specific location
At the next screen make sure Include this location is selected and browse to the Arduino IDE folder and select thedrivers folder. Select the folder and click OK
It should copy some files and then come up with this window. Click Finish
Almost immediately, another window will pop up, this time it will be a warning. Click Continue Anyway
And it should complete successfully!
When the computer is done rebooting, make sure the Arduino is plugged in (and the green light is lit). Go to the Device Manager (From the Start Menu, select Settings->Control Panel. Double click on System and select the Hardwaretab. Then click on the Device Manager button)
Look for an entry under Ports (COM & LPT) that says USB Serial Port (COM) the COM number may vary but it should be something like COM3 or COM4. The COM stands for "communication", and each one has a unique number, known as the COM Port number. In this case the COM Port number is COM3.
If you don't see the COM port verify the Arduino is plugged in
FTDI Driver Installation (Windows)
If you're using an older pre-UNO arduino, you'll have to install the FTDI driver.
When you plug in the Arduino, you may hear a sound from the computer and a little popup bubble in the bottom right corner of the screen that says Found New Hardware FT232R USB UART
After a few seconds, the new hardware wizard will start. Select "No not this time" and click Next>
At the next screen, select Install from a list or specific location
At the next screen make sure Include this location is selected and browse to the folder that contains the driver you downloaded. Select the folder and click OK
It should copy some files and then come up with this window. Click Finish
Almost immediately, another window will pop up, this time it will say USB Serial Port. As before, click Install from a list or specific location
Browse to the same folder again...
And it should complete successfully!
You may need to reboot the computer.
When the computer is done rebooting, make sure the Arduino is plugged in (and the green light is lit). Go to the Device Manager (From the Start Menu, select Settings->Control Panel. Double click on System and select the Hardwaretab. Then click on the Device Manager button)
Look for an entry under Ports (COM & LPT) that says USB Serial Port (COM) the COM number may vary but it should be something like COM3 or COM4. The COM stands for "communication", and each one has a unique number, known as the COM Port number. In this case the COM Port number is COM3.
If you don't see the COM port verify the Arduino is plugged in, and check that you installed the VCP FTDI driver.



FTDI Driver Installation Mac OS X
If you have an older, pre-UNO arduino you'll need to install the FTDI drivers. UNO Arduinos do not need a driver!
Open up the driver dmg file
And double click on the driver package, go through all the steps necessary to install the driver
You will need administrative priviledges to install the software
When it's done, restart the computer
Once its rebooted, start up Terminal, located in the Utilities folder
Plug in the Arduino, make sure the green light is on.
In the Terminal window, type in ls /dev/cu.* and/or ls /dev/tty.* which should give the following responses
Make sure you see a line with the text /dev/cu.usbserial-xxxxx where the xxx's can be anything. Same for/dev/tty.usbserial-xxxxx. This indicates that the driver installed properly and that the Arduino was found.
If you can't find the text, verify that your Arduino is plugged in, try a different USB port.
You can also try running the Console application, which will possibly give you some information about why its failing.



Driver Installation (Linux)
Linux doesn't have any drivers to install, assuming you're running a v2.6 kernel. These instructions assume you're running Ubuntu. Each linux distribution is different, but the instructions should be basic enough to follow for other distros.
You can verify your kernel version by running uname -a in a terminal window, note that this kernel is version 2.6.20
Sometimes the Linux distribution installs brltty (braille device) which will conflict with the Arduino. You must uninstall brltty! Do so by running
sudo apt-get remove brltty
In a terminal window. If it says it's not installed then thats OK. If you're not running a Debian-derived installation use whatever tool is necessary to verify that you don't have brltty running
Plug in the Arduino, verify that the green LED is lit, and type ls /dev/ttyUSB* into a terminal window, you should see a device file called something like ttyUSB0
Depending on your Linux distro, it may be /dev/tty/USB0 or /dev/tty.USB etc.
If you can't seem to find it, use dmesg | tail right after plugging in the Arduino and look for hints on where it may put the device file. For example here is says Serial Device converter now attached to ttyUSB0
If you see something like this
[ 1900.712000] ftdi_sio 2-10:1.0: FTDI USB Serial Device converter detected
[ 1900.712000] drivers/usb/serial/ftdi_sio.c: Detected FT232BM
[ 1900.712000] usb 2-10: FTDI USB Serial Device converter now attached to ttyUSB0
[ 1901.868000] usb 2-10: usbfs: interface 0 claimed by ftdi_sio while 'brltty' sets config #1
[ 1901.872000] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[ 1901.872000] ftdi_sio 2-10:1.0: device disconnected
That means you have not uninstalled brltty and you should try again.