Pages: [1]   Go Down
Author Topic: Noob's Guide To Setting Up Codeblocks for Arduino Uno on Windows 7  (Read 8569 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everybody. I am new to Arduino and new to c++. I wanted to move from the Arduino development environment for a variety of reasons. Based on what I read, and, in particular from this post http://arduino.cc/forum/index.php/topic,37631.0.html I spend about 4 days figuring out how to do it. I succeeded.

I think the problem is that some of the information is dated, or not directly relevant to my platform. I gave up trying to figure out why, but I ran into all kinds of problems which led me to new problems. Thanks to Google, and the fact I am stuck in a wheelchair for a few weeks, I was able to get, step by step, to the point where it all works. I am sure this is easy for a lot of people, but I'm an old guy and having slung code for a long time. I carefully (I hope) documented the process. I present it here for posterity. If anybody tries this and finds a problem, please let me know.

Here goes

General Warnings
I’m going to pretend your Windows 7 user name is mingy_desktop, but you;ll have to change it as needed.

Make sure you do not have a user name with an embedded space eg: mingy_desktop is, mingy desktop is not.
Unhide the C:\Users\mingy_desktop\AppData directory. I did this through the command prompt: Go to c:\users\mingy_desktop and type appdata attrib -H

If at some point you are trying again or ‘stuck’ uninstall CodeBlocks and delete all relevant associated data, which is found in C:\Users\mingy_desktop\AppData\Roaming\codeblocks. Remove the directory

Understand that every time you modify ArduinoProject.cbp, you have to close the project and create a new one. CodeBlocks will not recognize those project changes on an existing project.

1 )   Start Arduino and compile a simple sketch, like blink. Without closing Arduino, open Explorer and search for ‘core.a’. Make a folder C:\arduino-022\libArduinoCoreAT328p and copy core.a to that folder. Arduino core.a when it closes, so it can bet tricky to find. Mine was in C:\Users\mingy_desktop\Local\Temp\build7176365035724894050.tmp

2 )   Install WinAVR

3 )   Install Codeblocks

4 )   Run Codeblocks
         a.   Set GNU AVR GCC compiler as your default compiler
         b.   File New Project - AVR Project
         c.   Make sure C:\WINAVR-20100100\avr\include is in your search directories (Complier and debugger setting) (or wherever your winavr include directory is)
         d.   May as well make sure C:\arduino-022\hardware\arduinocores\arduino is in your search directories (You’ll need to add a bunch more of these as you develop more and more code)
         e.   File Save Project as Template and name it ArduinoProject

5 )   Close Codeblocks

6 )   Find the Codeblocks User Templates. Mine were in C:\Users\mingy_desktop\AppData\Roaming\codeblocks\UserTemplates\ArduinoProject

7 )   Copy the attached file start.cpp to (eg) C:\Users\mingy_desktop\AppData\Roaming\codeblocks\UserTemplates\ArduinoProject\start.cpp

8 )   Copy the attached ArduinoProject.cbp C:\Users\mingy_desktop\AppData\Roaming\codeblocks\UserTemplates\ArduinoProject\ArduinoProject.cbp

9 )   Note that the ArduinoProject.cbp file may have to be modified in that your COM port may not be COM3 (check in Arduino or the device manager and avrdude.exe may be elsewhere. I believe the one which comes with Arduino is out of date, thats why I use the version which comes with WinAVR

10)   Now, run CodeBlocks and File New FromTemplate User Templates Arduino Project. Tell it to create the project in a folder with no spaces in the name like AVRTest and with a name with no spaces like ArduinoProject.

11)   Select Build Target Debug and build the project. Most errors are because the Settings Compiler and Debugger Search Directories need to be filled in. Note that if you save source files like start.cpp from CodeBlocks, they’ll be saved to the project directory, not the templates directory, so use notepad or something to edit them in the templates directory.

12)   Make sure Arduino is closed, plug in your Arduino Uno, Select Build Target Release and build the project. You should compile fine because you have already tested that, however you may have problems with the programmer. If that happens, copy the command line which gets echoed in the CodeBlocks Log & Others window at the bottom of the screen. Open a DOS shell and past that line into the command line.

      C:\WinAVR-20100110\bin\avrdude.exe -CC:\WinAVR-20100110\bin\avrdude.conf -V -F -c arduino -pm328p -P COM3 -U flash:w:D:\TempAVR\bin\Release\ArduinoProject.elf.hex:a

It is easier to figure out what is wrong from the DOS command line because you can edit the line over and over. You can you a working command line as a prototype for the ArduinProject.cpb line.

13)   If everything works ok you should get a message like
                 avrdude.exe: 13294 bytes of flash written
                 avrdude.exe done.  Thank you.
                 Process terminated with status 0 (0 minutes, 3 seconds)
                 0 errors, 0 warnings

        If you get some sort of synch or protocol error, check to make sure your com port settings agree with the ArduinoProject.cbp settings you made. Baud rate doesn't seem to matter

14)   Open the Arduino serial port monitor. You should see a message
                 Hello from Arduino Code::Blocks template


Thats it!

I hope this proves to be of some use to someone!

Good Luck

* start.cpp (0.23 KB - downloaded 78 times.)
* ArduinoProject.cbp (2.45 KB - downloaded 70 times.)
Logged

Pages: [1]   Go Up
Jump to: