Friday, March 2, 2012

Using CMAKE with Arduino

In the last posting I talked about exploring other development environments for use besides just Arduino IDE. This led to Eclipse and a cmake configuration files. In this post, I overview converting the previous LED experiment to the new build environment. First, grab a copy of the tree. Since we are using cmake, the best bet is to set things up with a parallel source and build set of directories. Make sure you have git installed (prompt$ sudo port install git):

yoshi:swdev mstevens$ mkdir ardadv 
yoshi:swdev mstevens$ git clone git@github.com:mark-r-stevens/Ardadv.git source 
Cloning into source...
After that is done, make sure you have cmake installed on your system and in your path (prompt$ sudo port install cmake). To simplify the building I have created a top level configure script that will run cmake and generate the eclipse specific build files. This script should be run from the source directory:

yoshi:ardadv mstevens$ cd source/ 
yoshi:source mstevens$ ls 
CMakeLists.txt Configure.sh License.txt ReadMe.txt Test actuators cmake 
yoshi:source mstevens$ source Configure.sh  
-- The C compiler identification is GNU-- The CXX compiler identification is GNU
This should also trigger the build of the tree. I have also refactored the LED example. It is now located in the source/actuators/button/test/Test.cpp file. I also pulled out the button state code and put that into a separate library class that checks the button status. First you need to import the project. This is done under the eclipse menu File->Import and then select import existing eclipse project. This should load up the project with access to the source code and the make targets so you can build the code (and download the firmware).

The library located in sensors/button contains a class called Button. This has two methods:

        void Button::setPin(int pin);
        Event Button::check();

That you call from setup (to set the pin of the button) and check which is called from loop to see if the button was pressed, released, or not changed. The Arduino cmake file (located in sensors/button/test/CmakeLists.txt) lets you set the port to upload the firmware. You can then type:

yoshi:test mstevens$ make Test-upload
[ 90%] Built target uno_CORE
[ 95%] Built target Button
[100%] Built target Test
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: reading input file "Test.hex"
avrdude: input file Test.hex auto detected as Intel Hex
avrdude: writing flash (3506 bytes):
Writing | ################################################## | 100% 0.64s
avrdude: 3506 bytes of flash written
avrdude: safemode: Fuses OK
avrdude done.  Thank you.
[100%] Built target Test-upload
The wiring diagram for this layout is now:


With the actual picture:




This is a much more familiar build environment. Next up, onto accelerometers!


No comments:

Post a Comment