noobs guide on setting up code::blocks for arduino uno on linux (kubuntu)

noobs guide on setting up code::blocks for arduino uno on linux (kubuntu)

I assume linux OS, arduino uno atmega 328P, and quite some mileage in code::blocks

1 - create project folder: /home/me/AvrProject_2018

2 - install code::blocks

3 - install arduino IDE

4 - install avr-gcc and avrdude toolchain: ~$apt-get install avrdude binutils-avr gcc-avr avr-libc gdb-avr

5 - open arduino IDE, compile a basic blink sketch selecting the correct arduino avr chip, find the temp .o file (called core.o), rename this file to lib_atmega328P-core.o, copy this file to /home/me/AvrProject_2018/arduino

6 - find the arduino header files, usually situated in arduino-installation-directory/hardware/arduino/avr/cores/arduino/ and copy all .h files into /home/me/AvrProject_2018/arduino, don't foget the pins_arduino.h in arduino-installation-directory/hardware/arduino/avr/variants/standard/

7 - Run Codeblocks

8 - top menu -> settings -> global compiler settings -> set to "GNU AVR GCC compiler", DON"T FORGET to also, in the "search directories" subtab of this menu ->

  • Compiler: add "/usr/lib/avr/include"
  • linker: add "usr/lib/avr/lib"

9 - codeblocks -> new project -> AVR -> select folder /home/me/AvrProject_2018 and create project ArduinoUnoProject -> Debug and Release is OK -> atmega 328p and only select F_CPU define and create hex files -> done

10 - right click ArduinoUnoProject and go to build options

  • in master tab (on left) -> linker settings -> link library -> add -> find -> /home/me/AvrProject_2018/arduinolib_atmega328P-core.o -> OK
  • in debug tab -> pre/post build steps- > post build steps- > add
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).eep
  • release tab -> pre/post build steps- > post build steps- > add
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).eep
avrdude -v -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hex

11 - right click ArduinoUnoProject and add files recursively form folder /home/me/AvrProject_2018/arduino

12 - open main.c file in your project and C-V below code

#include "arduino/Arduino.h"

int main(){

    init(); //Don't forget this!

    pinMode(13,OUTPUT);



    while(1){

    digitalWrite(13,HIGH);

    delay(50);

    digitalWrite(13,LOW);

    delay(1700);

    }

}

13 - save -> debug build -> sort out errors and warnings and typo's and c-v errors and stuff -> repeat 13 till 'process terminated with status 0'

14 - save -> plug arduino uno into USB and check if correct port is used in your avrdudu release post build steps! -> relase build -> sort out errors and warnings and typo's and c-v errors and stuff -> repeat 13 till 'process terminated with status 0'

15 - your uno should blink fraction of a second, like it is in standby :slight_smile:

interesting info here:
arduino avr Eclipse setup
arduino avr codeblocks programmer
avrfreaks codeblocks setup avrdude