Arduino MIDI Library – QA round up

If you use the Arduino MIDI Library, and have found a bug or want to request a feature to be added, please do so in the GitHub issue tracker.

I’m currently rounding up the bugs, importing the old tickets from SourceForge, Twitter feed and e-mail sources, so that I can track them more efficiently, since the tracker on GitHub is really powerful and well integrated with Git.

In the next days/weeks I’ll be working on addressing most of these issues for the v4.2 release. Then v4.3 will be on its way with some changes on the settings system, which will allow for the same flexibility without the need to modify anything in the library files.

Thanks !

Arduino MIDI Library v4.0 is out !

The release v4.0 of the Arduino MIDI Library is now out !

You can find the changelog and download link here:
https://github.com/FortySevenEffects/arduino_midi_library/releases/tag/4.0

The documentation is available here:
http://arduinomidilib.fortyseveneffects.com

The Arduino Playground page has also been updated:
http://playground.arduino.cc/Main/MIDILibrary

Building avr-gcc for C++11 on Mac OS

Yesterday I saw that the support of C++11 has been added in GCC 4.7. Since avr-gcc is just a special configuration of gcc itself, it is then possible to build AVR programs using C++11. Of course, the standard library will not be available, but the language itself has some interesting features.

Since I don’t have the latest avr-gcc on Mac OS, I confirmed the theory by building a test program on the Raspberry Pi (equipped with avr-gcc 4.7.0). Yup, it works.

The latest available version of avr-gcc on Mac OS 10.6 is either 4.5.1 (using CrossPack) or 4.7.0 (using MacPorts). I could use MacPorts, but I don’t like the fact they install everything into /opt/local, it doubles up with the /usr/local directory where I usually install cross-compilers etc. If you want the easy version, go for the MacPorts solution. Otherwise, read on and hold tight..

Building the AVR toolchain from scratch on Mac OS

The complete toolchain is composed of three parts:

  • The compilers (avr-gcc, avr-c++ etc)
  • The binutils (avr-size, avr-objcopy etc)
  • The C library (avr-libc containing all the includes and precompiled libraries

The installation process in described on the avr-libc webpage.

Prerequisites

I’m assuming you have the following tools installed on your machine:

  • Xcode development tools (my version is 3.2.6)
  • MacPorts (to fetch the libraries we need to build gcc)

Getting the sources

The gcc sources are hosted on FTP servers, which can be quite slow. I used SVN instead, with the following command:

svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_4_7_2_release

The sources for the binutils can be found here, and the sources for the avr-libc can be found here.

Building the binutils

Before building the binutils, you will need to apply a patch to add AVR support to the avr-size tool. Here is the patch released by Atmel, however it failed to build on my machine, and I had to apply another one.

Requirements for the compilers

To build gcc, you will need the following libraries (for floating-point math):

  • gmp
  • mpfr
  • libmpc (be carefull not to install mpc like I did, it’s not the same thing)

That can be done with the following command:

sudo port install gmp mpfr libmpc

You will also need the iconv library, but the MacPorts version did not seem to work, so you’ll have to build it manually, from the sources. You will also need to copy this patch file to the libiconv-1.14 directory (or whatever version you download).

cd libiconv-1.14
mkdir build && cd build
../configure --prefix=/usr/local/temp/iconv
cd ..
patch --input libiconv_patch_gcc_4.7.2.txt
# when prompted for file to patch, enter build/include/iconv.h
cd build
make
make install

Here I install it into a temporary directory, since I might not need it later.

Building the compilers

To build GCC, we need to tell it where to look for the gmp, mpfr, mpc and iconv libraries. Make sure you don’t have the iconv library installed with MacPorts, as it will override the one you just built in /usr/local/temp/iconv.

cd gcc_4_7_2_release/
mkdir obj-avr && cd obj-avr
../configure --prefix=/usr/local/avr --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2 --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-libiconv-prefix=/usr/local/temp/iconv
make
make install

Building the C library

If you had an older version of avr-gcc installed, now might be the time to remove it (or at least to remove its path from $PATH), so you can build the avr-libc using your shiny new compiler.

This step is quite straightforward, just follow the instructions and you should be fine.

Building a test program

In order to enable C++11 features, you’ll have to pass the following flag to the compiler:

-std=c++11
Now try the following program, demoing the auto variables and range-based for loop:
int main()
{
    const char foo[] = "Hello, World!";
    char bar[14] = { 0 };
    auto i = 0;

    for (auto baz: foo)
    {
         bar[i++] = baz;
    }
    return 0;
}

You will notice that we’re returning from main, although it’s considered to be a blasphemy by some embedded developers, what it will do is only continuing executing empty instructions until looping back to the reset point. Anyway, this would not be worth much uploading onto a chip, since there would be no way to check that bar contains “Hello, World!” after execution..

Review of devboards and tools

Boarduino by LadyAda / Adafruit.

My first Arduino-compatible board. It’s the clone of the old Arduino Diecimila (with an ATmega 168P), in a breadboard-friendly format. It’s ideal to start with hardware computing and the breadboard format helps interfacing it with sensors and other circuits.

 

Sanguino by Zach “Hoeken” Smith

I needed more memory and pins than the usual 168P,  so I started using the 644P in the Sanguino, and made it a basis for most of my projects. It has been my main devboard for quite some time, before I made the Mobius Modular board.

 

Teensy 2.0 by Paul Stoffregen

Graciously donated by Paul for the purpose of developing the MIDI library on the Teensy, I’ve been using it mainly for this purpose. It has the same chip as the Arduino Leonardo, meaning it has native USB HID support.

 

Teensy 3.0 by Paul Stoffregen

One of my last acquisitions. ARM M4-powered, this little board can be one of the next big things in the ARM devboard race. I don’t think it might be powerful enough to run an OS “comfortably” like the Rasberry Pi, but a small RTOS should not be a problem.Detailed review here.

 

Arduino Leonardo

I currently use it as a unit test platform for the MIDI Library. The native USB driver in the ATmega32U4 makes it a good board to experiment with native MIDI USB, to create plug and play MIDI controllers and synths.

 

Mobius Modular Motherboard

I made this board to simplify the prototyping of MIDI devices and to be the heart and mind of my Mobius project. It’s using an ATmega 644P and features an IO expander for an LCD screen, as well as a hardware switch debouncer. The central connector breaks out access to 10 GPIO pins.

 

Raspberry Pi

I feel a bit guilty of using it only as a Git/Web home server, but it’s doing the job quite well. It’s running the Wheezy distro without many modifications. I might give a try to the Adafruit Occidentalis distro to play with the GPIO.

 

Texas Instruments Stellaris LaunchPad

The cheapest ARM board I’ve ever seen ($4.99 including worldwide shipping), but comes with limitations, as it’s only a demo board. Still, for that price, you get two ARM M4 chips.

Review here.

 

 Tools

Open Workbench Logic Sniffer by Dangerous Prototypes

Logic Sniffers are useful when debugging digital circuits, but also for firmware debugging: toggle pins when you enter and leave a function to check how much time you spent inside it! It can also analyse most serial transmissions (when setup correctly, took me some time to get it right).

Bus Pirate by Dangerous Prototypes

Very useful little tool to control almost everything that talks a serial language. Scriptable in Python, so with PySide you can make nice interfaces to analyse, control and hack the world. Note: If you plan to use it as an AVR programmer, prefer an USBtiny or something similar, it’s damn too slow.