A mention on the Pragmatic Programmer
I was looking at my Google Analytics and noticed I was getting referrals from the Pragmatic Programmer site, specifically from an article in the April magazine issue entitled Advanced Arduino Hacking. Turns out they were using my Makefile.master as the basis of their article, which describes how to use the Arduino platform without having to use the not-very-good Arduino IDE. OK, I suppose that's a little unfair - the IDE is clearly meant for beginners but if you are an experienced developer or are working on more complex projects it becomes very limiting very quickly, as noted in the article.
There are a number of copies of my Makefile.master floating around, but I'm updating it fairly regularly, so I recommend you grab the original version. Compared to the version on the PragProg site, the current version (at time of writing) has the following improvements:
- The only really platform-specific parts of the Makefile are those that deal with running the serial monitor used to connect to the Arduino. On Solaris I use tip whereas on Linux you'd probably want to use something such as screen. I've therefore added platform-specific sections to configure the serial monitor commands to the Makefile.master. I don't currently have settings for MacOS, if someone wants to provide some suggestions, I'll add them in.
- I hit a linker bug when using the avr-libc floating-point library, the workaround being to specify
-lmboth first and last in the linker command-line arguments. - An optional
EXTRA_FLAGSmacro that can be used to specify any additional flags that you want passed to gcc/g++. I use this for enabling/disabling debugging, e.g.EXTRA_FLAGS=-DDEBUGin my project Makefile. - The automatic tracking of
#includedependencies was being done via a separate invocation of the compiler, this has been collapsed into the main compilation step, thus halving the number of times the compiler is invoked. If you don't know what automatic dependency checking is, there's a good explanation here and also in the GNU make documentation. - The generated dependency files are stored in the
buildsubdirectory of the project, but they do tend to clutter things up. I've therefore moved them all into hidden (dot) files.
One final note, the PragProg Makefile.master uses stty -f $(PORT) hupcl to trigger a reset on the arduino before uploading the hex image to it. Not only is that platform-specific, it's also unnecessary if you are using a recent-ish version of avrdude which will do the reset for you if you specify a programmer type of arduino rather than stk500.
ATMega registers and memory ranges
The AVR family has a reasonably complex register and memory architecture, with:
- Multiple address spaces
- Registers that can be accessed directly and via the memory address space
- Register pairs that are used as memory indexes
- Restrictions on which registers can be loaded directly with constant values
- Some IO ports that appear in both the memory and IO address spaces, but with different addresses in each
- Some IO ports that are only accessible via the memory address space
In addition, the gcc compiler has conventions governing which registers it uses for what purpose, for example:
- Which registers it uses for purposes such as storing temporary values and zero
- Which registers it uses for passing and returning arguments
- Which registers it uses as a stack frame pointer
- Which registers are saved by the caller on entry to a subroutine and which ones have to be saved by the callee
When I'm reading the assembler output of gcc I find it helpful to have a table to remind me which registers are being used for what, and why. The information is not exactly well-explained in the AVR documentation and I've not been able to find all the information in once place on the Internet, so I've drawn up the following quick-reference table to remind me of what goes where:
Click on the image for a PDF copy of the table. I hope you find this useful, corrections and suggestions welcome - please leave a comment below!
References
EletroAxé with Carlinhos Brown
Carlinhos Brown is a colossus in Brazilian music, known not only for his solo musical career but also for the founding of Timbalada and for reviving the use of the Timbau, one of the instruments I (try to!) play. As part of this year's carnival in Salvador, Kyle McDonald and Lucas Werthein built him a drum suit, with a series of drum triggers linked up to an Arduino and then via wireless to a PC to allow Carlinhos to trigger drum samples by tapping on the pads on the suits. It's a cool project, see the video below and the project page on Lucas's site for the full details.
The very first version of my wireless-controlled LED system was intended to be used on drums, so the EletroAxé project is based on a similar concept. In my case I built a prototype using a vibration sensor mounted on one of the Alfaias that we play in Juba do Leão, the Maracatu group I'm a member of. It worked fine, but then the folks from the Travelling Light Circus came along with their proposal, and the idea of mounting the strips on drums got shelved. However it would be pretty cool to link up something like that suit to the LED system. and as both are arduino-based, it wouldn't be particularly hard either. I have mad visions of this bunch playing at night, all lit up with radio-synchronised LED strips :-)
Sprung
Spring seems to have appeared with a real rush this year - all of a sudden everything seems to have popped into life. Here's hoping for a good summer to follow :-)
The world's most awesome MIDI instrument
This is a Tesla coil that can be played as a musical instrument. According to the information on the supplier's website it can be driven directly by audio or as a MIDI instrument. The tune is being played by the arcs themselves; by switching them at the appropriate frequency the corresponding musical note is produced. Awesome :-)
Chris at work pointed me at this one as well. Like :-)
