Upload Your First Sketch

OK don't forget - you have to go though the Lesson #0 steps to install drivers, software, and verify that your Arduino is powered, has the bootloader installed and shows up as a COM/Serial port... Don't continue unless that has been done!

Startup!

Double click the Arduino software icon on your desktop

To open up the workspace, also called the IDE. IDE stands for Integrated Development Environment. Basically, a word processor for writing code. The full name is really a mouthfull, so we say I.D.E. (Eye Dee Eee)

Anyhow, it looks like this:

The main IDE window has multiple tabs and areas, we'll visit all of these shortly, so keep your eye on this diagram!

Getting Ready To Do This Thing!

We're going to jump right in! Before you can run a program on the Arduino you need to tell the IDE where to find it and what kind you're going to be programming (as we mentioned in lesson #0 there are dozens of types of Arduinos!)

Select Board Type Arduino UNO

Under the Tools menu, find the Board submenu and navigate that to select Arduino (Genuino) UNO.

You should use this board selection also if you are using an Adafruit Metro or any other Arduino UNO compatible

Select Correct Serial Port

Most important you will also need to select the correct Serial port. This is where people can get tripped up. The good news is if you have a genuine Arduino UNO, the name will appear next to the serial port menu item to make it easy to pick out!

If you have an Arduino compatible like Adafruit Metro, you may not see anything after the Serial port name, but it will still be the only option available that is not COM1 or something with Bluetooth in the name

~~ Hints! ~~

Windows: It will never be COM1 don't pick that one. You should only have one other option.

Mac OS X and Linux: It will never be an option with 'bluetooth'  in the name, look for /dev/cu.usbmodem or /dev/cu.usbserial or /dev/ttyUSB or similar!

Have lots of Serial ports? Try unplugging your Arduino and seeing which port disappears next time you look at the Ports list!

The board and serial port preferences are 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 and type 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 -> Examples -> 01.Basics -> Blink

This should open up a new window that should now look like this, with a bunch of text in the center white space. Above the text is a tab labeled Blink

Verify / Compile

Let's keep going! 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 spell-checking or grammatical editing) and then translate it into an app that is compatible with the Arduino hardware.

Verify: Like having a friend look over your homework essay before handing it in, verifying means the Arduino software will check over and look for typos, common errors - it can't catch all errors, just like a spellcheck wont be able to tell that you spelled "bear" like "bare" by accident since both are proper words

Compile: check your music player and you'll probably find you own at least one compilation, which means a collection that someone put together in a specific order. When Arduino compiles your sketch, it is putting/arranging it together into the right order for your Arduino hardware board to be able to run

While in theory you could have Arduino do each one separately, it's faster to just have it do both at the same time

You can start the action via the Sketch menu

After a few seconds, you should see the message Done compiling. in the Status Bar and Sketch uses ... bytes (x%) of program storage space (or something similar) in the Program Notification Area.

This means the sketch was well-written and is ready for uploading to the Arduino board!

Upload

Ready for the moment of truth? Now it's time to upload your very first sketch. Make sure the Arduino is plugged in, the green light is on and the correct board and Serial Port is selected.

Select Upload from the Sketch menu

After a few seconds you should get this screen, with the message Done uploading. in the status bar.

Things That Can Go Wrong...

Arduino bootloader doesn't respond

If you get the following error message avrdude: stk500_getsync(): not in sync or avrdude: stk500_recv(): programmer is not responding that means that the Arduino bootloader is not responding

This error can be caused by a lot of issues. Check the following:

  • Is the correct Arduino Board selected?
  • Is the correct Serial Port selected?
  • Is the correct driver installed?
  • Is something connected to the Reset pin or pressing the reset button?
  • Try disconnecting all connected shields, jumper wires and components
  • 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)

You can also check Lesson #0 on how to verify if the bootloader is installed

Can't open serial port device

If you get an error like avrdude: ser_open(): can't open device it likely means your Arduino got disconnected from USB somehow

This error can be caused by a few possible issues. Check the following:

  • Is the correct Serial Port selected?
  • Is the correct driver installed?
  • Try unplugging/replugging the USB cable
  • Try another USB cable or USB port
  • Your computer's USB system may have crashed. Shutdown your computer, disconnect power, wait 3 minutes then restart it

Video of all steps

Here is a video showing the timing of the steps described so far, opening the Blink sketch and setting the board and serial port.

Watch!

If you have a UNO Arduino, the upload process is quite fast: Once you click Upload from the software the IDE will ask the Arduino to reset itself into the bootloader and immediately start uploading the blink sketch. After uploading, the sketch is quickly verified - the IDE asks the Arduino 'please repeat back what I just asked to you to do' - and reset again to start running the sketch.

The little translucent L LED will start blinking on and off, a second on and a second off.

Here's a looping animation showing upload and then 3 blinks: notice the RX and TX LEDs blink during upload, but it happens very fast!

Last updated on 2016-09-01 at 07.36.45 PM Published on 2016-09-01 at 11.27.37 AM