ic Handbag Project

getting your stuff from a PC to Gemma ...

Uploading code to Gemma (from a Windows PC)

project guide showcase starter kit coding

Step 1. Check the code compiles correctly.

You have written your code in a high-level language (or copied code that was so written). By this we mean that it is written in a way that you find relatively easy to understand. Gemma however needs a lower level version which it finds easier to turn into actions (such as flashing an LED).

Opposite is a basic 'blink' program. It flashes the red LED on the Gemma (not one external to the Gemma). It turns it on for 4 seconds then off for 8, and so on.

When the button with the tick on the top left of the Arduino screen ('Verify') is clicked it says 'compiling sketch' and then 'done compiling'. If there is a problem it will let you know - probably by flashing a red bar and showing lots of 'red ink' on the bottom screen.

Note that Verify cannot say that your code will work, or do what you think it should. It just points out things that are obviously wrong (like a pedantic teacher telling you off about spelling and grammar).

basic blink code example for Gemma

Step 2. Prepare to upload the code.

Do some basic checks first. This is to avoid some of the more obvious mistakes.

a) USB Connection. Is Gemma connected by USB cable to your PC?

b) Windows driver. Do you have the Windows driver correctly installed on this PC? You can go to the Device Manager to check.

c) Bootloader available. When you press and release the little button on the Gemma between the red and green LEDs on Gemma, does the red light flash quickly (several times a second). If so, that is the bootloader listening for new code - if it does not get any it will go back to running the code that Gemma already has installed on it, whatever that is.
NB One reason that this step might not work is if you have Gemma already in a circuit, for example to do our Workshop 1 Activity 1. If there is a problem or short-circuit in what you are doing it will stop Gemma from listening for new code. Simply disconnect any crocodile clips or sewable snaps so that Gemma is no longer connected to a circuit.

d) Arduino Options. Ensure that on the Arduino software: i) Board is set to Gemma; ii) Programmer is set to USBtinyISP; iii) 'Verbose output during upload' is ticked.

e) Arduino Window. When you are happy with your sketch, stretch the Window it is shown in to max depth and ensure that the black area at the bottom is as deep as possible - it is there that you will get messages about your upload.

f) Recognizing Success. Check that your new sketch does something different to the one that is already running on the Gemma. Otherwise you'll never know you succeeded (or failed). That is, if the red light is already blinking 4 on 8 off then change the code to be 2 on 10 off. It may sound silly but sometimes the Arduino software's final message can imply a problem, but it has actually already uploaded new code successfully.

Step 3. Upload the code.

This requires you to do two things in synchronisation (almost). The challenge is to coordinate the Arduino starting to upload with the bootloader's red light flashing rapidly.

1. UPLOAD COMPILED SKETCH. Click the Upload button at the top left of the Arduino software (a right arrow). If your sketch is small and your computer is fast it will say 'compiling sketch' very quickly and then try to upload.

On the other hand, if your computer is slow or your sketch is large or complex, your computer will seem to take forever (well, maybe a minute) 'compiling sketch' and only then try to upload. Sometimes the time it takes will seem to vary randomly.

2. START BOOTLOADER. Press the small button on Gemma that makes the red light flash rapidly.

Situation 1. A successful upload.

Don't worry that it is red. The important thing is that you see lots of blocks of 'hex' code scrolling (a line is something like CMD: [4c 01 20 00] [00 00 10 00].

At the end of that it says something like: avrdude 832 bytes of code verified, thank you. This should mean that your code has uploaded successfully, and that even if you turn the power off and on it will still run. Well done.

verbose output from successful Gemma upload
Note also that if you scroll up above this code you get lots of useful information as follows (if not, you forgot to put 'verbose mode' on in Preferences in Arduino).
verbose output from successful Gemma upload inc Chip Erase Delay time
Note that it tells you the all important (for trouble-shooting) info about where the avrdude.conf file that you are using is located. Also the Chip Erase Delay time (here 400000. If your entry says 90000 and you are having problems, see here.
Situation 2. Upload fail - could not find USB tiny device

This is a really unhelpful message. It can be generated by several situations. If you have done all of the pre-checks suggested above then it probably means that you did not co-ordinate the upload with pressing the bootloader button (see Step 3 above). We generated this example message by simply uploading without bothering to press the bootloader button on Gemma at all.

You can also get it if you disconnect the Gemma altogether from the PC. Also if you have not managed to install the Windows driver correctly.

Anyway, try and try again to coordinate the bootloader and the upload before concluding you have a more serious problem. Then double check the pre-checks and try again.

Could not find USB tiny device Gemma Arduino error message