Archive for the ‘embedded software’ Category

Arduino Part 3

In embedded software on February 19, 2011 at 8:10 pm

Learning More–getting ready for the class

I’ve learned a bit more about the Arduino in the last couple of weeks, since my last Arduino post. Most of the information has been about using Eclipse and the Arduino Uno. The basic project I completed last time was the simple blinking example on the Decimilia board. This is an ATmega168 processor and runs just fine. However, when you go to Eclipse, you need to make sure that you set the clock frequency to 16000000 and not 1000000 as in some of the documents. Other than that, everything works just great.

Enter the Uno

The Arduino Uno is the latest version of the Arduino. I ordered a starter kit from Amazon. It was a duemilanove kit, but shipped with the Uno. It has the ATmega328p processor. It worked just fine with the Arduino IDE, but when I tried to duplicate the steps to get it working with Eclipse, I failed miserably. It’s taken a while to track things down, but I think I’ve got it pretty much sorted out now.Here are some of the things that I’ve found helpful.

  1. When you set up the AVRDude configuration for the Uno, the baudrate should be 115200 instead of 57600 as some of the documents indicate. This will get rid of the annoying “stk500_recv(): programmer is not responding” message when AVRDude runs.
  2. In order to see what’s going on with the Arduino IDE, you can modify the preferences.txt file to add some verbose options. The file is in the Library/Arduino directory under my home directory on the Mac. A couple of the useful things I’ve found are adding the following lines:
    • upload.verbose displays the command line used for invoking AVRDude.
    • build.verbose=true displays the output of the build process.
  3. I’ve copied the Uno core.a library created by the Arduino IDE and am going to just use it rather than trying to create an Eclipse project for building such a library like I did for the Diecimilia. This will reduce the number of things I have to work with and it is the preferred way of getting the library according to the installation. One of the problems is finding the library on the system on the Mac. The location of the libraries is specified for other platforms in the Eclipse installation instructions from the Arduino playground. It took a little while, but after putting in the “build.verbose” file in the Arduino IDE’s preferences.txt file, I found the directory. It was in /var/folders/7A/… . Not the most obvious place. I moved this into my a lib/arduino directory in my home directory.

After all of this, I still am not getting the program to execute. It compiles, loads, but does not run on the Uno.

Finally: Success

So, it was back to the drawing board. I went back and recreated a separate project for the Uno core library. Then I compiled that and created a new project for the Uno blink program, and it worked. It’s still not the easiest thing to make sure you get all of the settings correct, but it is nice to see the light blink.

Next, I think I’ll work on building the project in a more simple environment, like a text editor, command line compilation, and make.

First, it’s probably worth recording the settings I’ve got on the two projects.

Uno Core Library Project

I simply copied all of the sources from the …/cores/arduino directory to the top level of this project. I deleted the main.cpp as the Eclipse installation directions said. Next, I followed the directions from the Eclipse installation page exactly. The relevant preferences settings for the project are:

  • AVR>Target Hardware: ATmega328p, 16000000 MHz.
  • C/C++ Build>Seettings: no debugging information, and optimize for size on both compilers (C and C++). Also, the other optimization flags for the C++ compiler are”-ffunction-sections -fdata-sections -Wl,–gc-sections”.

I have both the debugging and release configurations set for this, but it only needs release. We’re not really worrying about debug configurations at all here.

The Uno Blink Project

Again I followed the instructions in the Eclipse installation directions. There was one thing not covered which got the library included in the linking. Here are my settings:

  • AVR>AVRDude: Uno programmer configuration. No switches set under Advanced tab.
  • AVR>Target Hardware: same as above.
  • C/C++ Build>Settings
    • Additional Tools in Toolchain: Generate Hex Files for Flash Memory and Print Size are checked.
    • AVR Compiler>Directories: “${workspace_loc:/UnoCore}”, where UnoCore is the name of my Uno core library project.
    • For both compilers (C and C++), no debugging and size optimizations.
    • AVR C++ Compiler>Directories: same as for the AVR Compiler.
    • AVR C++ Compiler>Optimization: -ffunction-sections -fdata-sections -Wl,–gc-sections
    • AVR C++ Linker>Libraries: Libraries (top): UnoCore, which is the name of my library for the Uno core. Libraries Path (bottom): “${workspace_loc:/UnoCore/Release}”.

Arduino Part 2

In embedded software, testing on January 31, 2011 at 2:22 am

Processing Not C

Upon first look, I thought that the Arduino IDE supported C and C++. It actually looks like it. But after reading the first couple of chapters of Getting Started With Arduino, I learned that it actually supports a variant of the Processing language. This is nice for getting started quickly; unfortunately, it does not necessarily allow the incorporation of testing frameworks like Unity and CppUnit. So my next task is to get Eclipse configured for the Arduino. The starting point for this exploration is in the Arduino playground pages on Eclipse. It seems like the instructions are quite straight forward.

The way the Arduino IDE works is that it translates the source to C and then passes it to gcc. I may be able to integrate one of the unit testing harnesses with this, but not for the initial class since the first group is a set of developers who are programming in C and C++. One of the requirements of the class is that we use these languages as much as possible. I will, however, try to introduce domain specific languages for testing as part of the course content.

Starting with Eclipse

I might as well jump right it. I’ve already got Eclipse set up for the AVR processors on my Mac. This required first installing the CrossPack tool chain. This installs the AVR gcc compiler and other AVR development tools. There are other tools required for Windows and Linux. These are identified in the Arduino playground.

After a couple of hours of reading and hacking, I have a blink program written using Eclipse and running on the Arduino. Here’s what I ended up doing. Most of the information comes from the Arduino playground – Eclipse page already mentioned. The specific things I did were:

  1. Compiled my own static library for the diecimilia board. I called this libDiecimiliaCore.a. I’ll have to compile another one for the Uno.
  2. Created my first project for the Arduino. It references the header files in the library project and includes the static library when linking.
  3. Copied the main.cxx to the project and renamed it main.c since this is simple C code.
  4. Wrote the “blink” application from the Arduino IDE. I simply copied it. Now, the interesting thing is that the delay is over an order of magnitude faster than with the Arduino IDE. I think one of the tasks for the class will be to calibrate the delay loop. This is a good test to start with.

The instructions for doing this are quite clear. It is fairly tedious and time consuming to get this workiong the first time. Next up is making a template / configuration so I don’t have to go through all of the settings every time. At least I’m seeing some progress.

Arduino Part 1

In embedded software, testing on January 29, 2011 at 2:25 am

So, I received my Arduino Starter Kit today and want to get started understanding it so I can build enough examples and exercises for the Testing Embedded Software for Developers class. The Arduino is much more low level than the Neuron Robotics DyIO, but it’s much less expensive and there’s more documentation available right now. Of course I’ve got the folks from Neuron Robotics available on campus and nearby to help me figure out what’s happening. But, I think it’s about time for me to dive in and figure out some low level concepts. Later on, possibly in future offerings, I can add the DyIO to the course.

You have to realize that I’m very hardware-phobic and really get nervous when I have to touch hardware. It stems from an experience I had building an 8-bit computer in the late 1970s. I reversed polarity on the board and all of the diodes exploded. It cost more to get that fixed than most PCs cost today. Ever since, I’ve always feared damaging components beyond repair. Luckily the Arduino isn’t that expensive and I don’t think it’s going to surge back to my laptop.

I had an Arduino Diecimila that someone gave me to play with. The starter kit came with the Arduino UNO so I’ve at least got two systems in case I blow one out. This could be interesting.

Anyway, I’ve loaded performed the Getting Started with Arduino on MacOSX. It went really smoothly. It took about 15 minutes from starting to download the Arduino IDE to getting the blinking LED. Nice and easy and I didn’t break anything. That certainly builds confidence. I do, however, want to use the Eclipse environment with the AVR plug-in for the class. I think it will make some of the testing easier, but I’m not sure about that yet.

Now I’m going to start reading some of the tutorials and play around with the board. It looks like you build libraries for use with the Arduino and IDE in C++. This is cool. But it also means that there’s an awful lot to learn in a short time. I’m not sure which things are critical. If anyone has any ideas on what would be the most useful, please let me know. Post a comment here.

Getting ready for testing embedded software for developers

In embedded software, Teaching, testing on January 26, 2011 at 8:57 pm

After a couple of months of reading about embedded systems on-an-off and how to go about testing them, I’m finally done procrastinating and putting together the course (with a whole two months to spare). This should be fun, and a good course that we can build upon. This particular one is specifically for corporate education at WPI. There are companies out there who are really eager to get their developers trained in testing techniques for the systems they’re building. I think it will be fun, and it will also help me improve the standard testing course that I’ve offered a couple of times.

I’ve chosen a couple of good books for this course, which is a graduate-level course. The first is Introduction to Software Testing by Ammann and Offutt. This is a really nice book that covers testing with just enough theory and a lot of practical advice. I think it will appeal to developers quite nicely.

Cover of the text book


The second book is Test Driven Development for Embedded C by Jim Grenning. This is the book that I’m learning a lot about embedded systems development. Combining this with the previous book should make for a great course. Of course, I need to go back and remember some of the dirty little corners of C and C++, but it should be fun.

Cover of Test Driven Development for Embedded C


The course will not be simply learning the theory and practice, but putting the knowledge to work by working on projects. Projects make things interesting, but somewhat difficult for a course like this. The students will be practicing software engineers who are already working on embedded code so the challenge will be to try and simulate enough of a real system without the complexity and size of industrial systems. I’m not sure how this will work, but I think it’s possible to make interesting and reasonably challenging problems.

I’ve decided for the first offering to use the Arduino board for the main development hardware. I’d like to incorporate different things like Sun SPOTs and the Neuron Robotics DyIO, but not right now. Maybe these will go into a future offering.


The hardware

The other challenge is how I’m going to talk and keep a class interested for four hours at a clip. I’d rather two days a week, but that’s not possible right now. The last time I did a four hour course was one summer teaching foundations of computer science. I bored myself to death.