Setting up code blocks for AVR on Ubuntu

Code Blocks is a cross platform free and open source IDE developed for C, C++ and Fotran.  This light weight IDE can be used to program AVR microcontrollers also. This tutorial is about how to install and configure Code Blocks (CB) on Ubuntu in order to program Atmel AVR microcontrollers.

Step1 – Install required AVR development tools

You can refer my previous post on how to program avr on ubuntu for beginers for completing this section.

Step2 – Add third party repository to  your Ubuntu source list

Here we are going to use private debian repository maintain by Jens. More details on his work can be found in http://apt.jenslody.de/

Open source.list file using following command

sudo nano /etc/apt/sources.list

Then you you will be able to see a longer file with all your repositories. Then append following two lines to that file

deb http://apt.jenslody.de/stable stable main
deb-src http://apt.jenslody.de/stable stable main

Save file using [CTRL] + [x] followed by [y]

Step 3 – Installing Code Blocks

The execute following commands on the terminal

sudo apt-get update
sudo apt-get install jens-lody-debian-keyring

Step 3b – Additional step

If you are using x64 installation, use following command as well

sudo apt-get install libc6-dev-i386

Step  4 – Creating a new project

  1. Open Code Blocks IDE and go to menu File->New->project
  2. Choose “AVR project” from the dialog box
  3. Follow the wizard and create the project
  4. From the main menu, select Project->built options …
  5. Select “pre/post built” tab from the “Project build option” dialog box
  6. Note there are three options <your project name>, release and debug
  7. Click on <your project name> and CUT the content in that “post build steps” texbox on your right
  8. PAST the text which was CUT in the previous step to  “post build steps” text boxes appear when you click “release” and “debug” items on your left. (You should copy the same in both of them)
  9.   Append following line to the “post build steps” textbox when you see upon clicking “release” on your left
  10. sudo avrdude -p m32 -c usbasp -P usb -U flash:w:$(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hex
sudo avrdude -p m32 -c usbasp -P usb -U flash:w:$(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hex

Then your project build option dialog box should looks like as follows. N.B. Following screen shots are generated when Debug and Release texts were selected in left section

debug

debug

Congratulations !!!!! You are ready use Code Blocks IDE on Ubuntu for programing AVR microcontrollers

N.B. if you are