Software and Multimedia R&D.

Neurogami ®

Dance Noise.
Out now.

Get it here ...

Getting an Arduino Flora to do MIDI

A little over a year ago I (James) ordered an Arduino Flora board from Adafruit. The board had recently been released and as a fan of wearable computing I wanted to play around with one. It looked very much like the existing Lilypad board but with a few extra touches.

For one, it had a built-in slot for attaching a battery. It also had a built-in mini-B USB connector. Best of all, it was described as being able to HID USB, including HID MIDI.

If you looked at that Flora product page you might notice that there is no mention of MIDI. Yeah, that part is gone. This is a fairly recent change. That same claim used to be on the getting started page but is now gone. But if you Google about you can find promo blurbs on other sites that copied from the early Adafruit promotional content, and they refer to HID MIDI. (For example. Also Google cache)

But why the change? And why did I just notice? For all sorts of reasons I never got around to actually working with my Flora until about a week ago. I assume I’ve been distracted by yet newer and shinier toys. Or it got buried in the pile of “get to” boxes. In any event I had the board out and was trying a few things and recalled that it was supposed to do HID MIDI so I set off to have the Flora drive some MIDI programs.

I went looking for an example but could find nothing.

If you’ve used a Teensy board you might hope that MIDI with the Flora would be as simple. But no. And the reason is because the Flora, contrary to the original claims, does not actually do HID MIDI. At least not as-is out-of-the-box.

But it is (sort of) possible with a bit of hackery.

Note

While writing this up there was a new comment made on that Adafruit forum topic. Please read it. Paul Stoffregen, the creator of the Teensy, explains the differences between HID and MIDI and why claiming “HID MIDI” would make little technical sense.

Flora is Leonardo

If you read that forum thread you’ll find that the Flora is a variant of a Leonardo board.

Same chip. The links provided in that thread cover a variety of options for getting a Leonardo (and therefor, hopefully, a Flora) to do HID MIDI. None of them are as simple as “load this sketch and behold the magic.” But one of them, arcore, looked at least fairly easy to try.

The first attempt was done on my Windows 7 laptop. I copied the git repo into the hardware folder of an installation of the 1.5.6-r2 Arduino IDE. The tl;dr: It almost but not really worked. Though I was using a Flora, I set the “board” option to “Arduino Leonardo (arcore)”. I then loaded a MIDI sketch. The loading worked. The device manager no longer listed the Flora as a COM port device; I now had an unknown USB device. However, it was not recognized as a MIDI device by Renoise (my preferred music program).

Still, this was somewhat encouraging. It was a USB something.

When I restarted the IDE, though, the Flora was not detected. Makes sense; it was no longer a COM port but a USB thingy. To get a new sketch onto the board I had to press the board’s reset button and then immediately start the sketch upload. (This seemed to work; I wasn’t taking notes at the time. As you’ll see this may have been a fluke.)

Attempt number two

I had already spent a fair part of the day trying to see if a) the Flora could even do MIDI, and b) how that might be possible, and after the Windows experiment I called it quits. The next day I booted up my Ubuntu install and decide to give it another shot.
Since the Adafruit info about the Flora now only mentioned mouse and keyboard HID I though I would see if could get that working. There’s a tutorial for the Leonardo that has some examples. The keyboard example can be loaded onto a Flora and it works fine.

Not wanting to wire-up any sensors I changed the loop to always send keyboard commands. Word of warning: once the sketch is loaded it starts typing stuff right away. But it works.

Since I was using Ubuntu thought I should try arcore again. First attempt I got the same results as I did on Windows. Then I remembered something about how the IDE works.

When I first tried using the Flora I read the Getting Started thing and it had instructions for Windows and OSX but not for Ubuntu. Doing some research I found that what made their custom IDE special was the addition of some files and board descriptions.

If you download the IDE installer and extract the files you can manually update an existing IDE installation. If you are on Ubuntu this is what you have to do.

The arcore instructions say you need to use the latest IDE. I’ve been using 1.0.5. That’s the version you get if you run the custom Flora-tweaked IDE on Windows. (Side note: You can run multiple versions of the Arduino IDE on the same machine. On Windows there’s the likelihood that using an installer program will tell Windows to make an automatic file association with that specific version, but if you just extract the files you can run a version of the IDE from wherever you put it.)

I had tweaked my Ubuntu installation of the IDE to handle the Flora. I had to install the 1.5 IDE to use arcore. That version already had a boards.txt entry for the Flora. But there was a special section for boards to work with arcore. That’s where it listed the Leonardo; the Flora entry was in a separate section. Looking at the board entries I noticed that those in the arcore section had a few crucial differences.

The Flora is not in fact a Leonardo. It’s more of a “Like-onardo.” It occurred to me that the IDE specifications for the two boards might be different enough in some critical way that, while still allowing me to upload a sketch, did not do so quite correctly.

I looked at the boards.txt entry for the Flora and used it to make an entry similar to the “Arduino Leonardo (arcore)” entry.

The key differences:

    flora.build.core=arcore
    flora.build.variant=arduino:flora
    flora.build.extra_flags={build.usb_flags}

You can see my complete Flora entry here.

I also had to copy over the hardware/arduino/variants/flora directory so as to make pins_arduino.h available. (It gets copied to hardware/arduino/avr/variants/ for the 1.5.n IDE.)

Now I was able to use the arcore-ified IDE and select the proper board. I loaded up a simple MIDI example similar to the keyboard example. All it did was loop and send a note on, then a note off, with some short delays. MIDI ping.

It loaded fine, and when I started up Renoise I was able to select the Flora as a MIDI input. (The actual name of the MIDI device was “USB IO Board MIDI 1”, something I would really like to change.)

One thing I noticed when doing all this was that once I turned the Flora into a USB device the IDE no longer found the board. I would see this error:

    Connecting to programmer: .avrdude: Send: . [1b] 
    avrdude: Send: S [53] 
    avrdude: ser_recv(): programmer is not responding
    avrdude: butterfly_recv(): programmer is not responding

It was looking for it at /dev/ttyACM0 and that simply failed. To load a sketch I would have to press the reset button on the Flora and then start the sketch upload.

Meanwhile, back on Windows 7 …

With this success I decided to try again on Windows 7. I updated the boards.txt file used by arcore in the 1.5 IDE and copied over the variant folder. The Flora still had the MIDI sketch from before which seemed to now be causing trouble.

Device Manager showed the Flora as a COM port (“Adafruit Flora (COM 27)”) which was encouraging, but I also had new entry under “Sound,video and games controllers” (they’re missing the Oxford comma): “USB IO Board”. With one of those yellow warning triangles.

I tried to upload a sketch and while it seemed like it was going to work I eventually got this error:

avrdude: error: buffered memory access not supported. Maybe it isn't a butterfly/AVR109 but a AVR910 device?

The “press reset and then upload” dance wasn’t working.

Some Googling lead me to an Adafruit support post.

I tried using a different USB port and Device Manager now told me I had a Teensy USB Serial attached on COM31.

I was doing this on a Lenovo Thinkpad W500. The same hardware as used with Ubuntu; I just swap hard drives to change operating systems. The W500 has three USB ports. There is a gap between the second and third port, which for whatever reason I always assumed meant the ports were different (i.e. 2.0 and 3.0). I looked up the specs for the machine, though, and (sadly) they are all USB 2.0. (For what it’s worth I have, with a few other things, had different behavior with USB devices depending on what port was used and what other devices if any were also in use. Changing ports was not total voodoo but not precise science either.)

It doesn’t help that when you press the Arduino reset button the COM port entry in Device Manager goes away for a bit and then returns with possibly a different value.

I decided to try a different approach. Pick a different board, a non-arcore. First attempt failed because the MIDI sketch made use of datatypes not available outside of the arcore code. I opened up a simple blink sketch and selected the “Leonardo” board. For whatever reason there was no standard “Flora” option in the boards list. Nonetheless the sketch (seemingly) loaded. (I then went and corrected this omission in boards.txt).

I also got a Windows error message about an unrecognized USB device. And Device Manager did not show the Flora under Ports.

I took a shot using the Floradized IDE. I had to do the reset-upload jig again. However, the COM port device listing would vanish before the sketch was uploaded.

In fact, the COM port listing would change while the sketch was being uploaded.

What a major pain in the ass.

I had reached the point where frustration was pushing me to just try anything while not keeping careful notes of what in fact I was doing.

At least right now the device was only recognized as a COM port device, and nothing was appearing in the USB section if I removed and reattached the Flora.

I unplugged the Flora, shut down the IDE, making sure all its windows were closed. I reattached the Flora, started again the Floradized IDE, and this time it worked. I was able to upload a blink example.

BUT WHAT ABOUT MIDI?

So, yeah, what about MIDI? The real question was could I do HID MIDI stuff on Windows and reload sketches without getting enraged. I needed to see if I could use the arcore IDE to upload a MIDI sketch, and then upload a more conventional no-arcore Flora sketch. Was my voodoo repeatable?

A few thoughts were going through my mind. First, screw this, I’m going to just use the Teensy. Second, I may, in my frustration and annoyance, be doing something quite wrong and.or stupid. If that’s the case I hope someone clues me in.

I have to say that even if HID MIDI is technically doable on a Flora the hoop-jumping gets tiresome real fast. There are things I like about the Flora (the battery plug for one), and my Teensy seems to get much hotter than the Flora, but having to bounce among IDEs and numerous resets may be a deal-breaker.

So just how hard is this on Windows 7?

With the Flora in what I hope is its default state I bring up the arcore IDE and upload my “MIDI ping” sketch.

It seemed to take forever.

Then this crap:

avrdude: error: buffered memory access not supported. Maybe it isn't a butterfly/AVR109 but a AVR910 device?

I try the reset/upload dance. No luck.

I give up.

Actually, I then tried to get something going on a VirtualBox VM running Ubuntu. Then I gave up, after much the same frustration.

Meanwhile back on the other OS …

It worried me that my attempts on Windows may have borked the Flora. I booted back into Ubuntu and tried again to load assorted sketches, avcore and not, onto the board. No problem. I pretty much have to press the reset button every time I load a sketch but it seems to be a reliable process. A minor victory.

So what’s the takeaway here?

If you want a small board primarily to do MIDI, get a Teensy. It’s just way simpler. The Flora is likely easier to work with as a wearable device (it’s clearly easier to sew into stuff) and I have no idea how a Teensy might hold up if you washed it. I don’t see that alone as a major issue; design the piece so that the Teensy board is removable.

If the wash-n-wear aspect is not important (because you’re building a controller to mount on your wrist or on a guitar or someplace where it’s no more likely to get wet than any other piece of hardware) than the Teensy looks to beat the Flora on just basic specs.

Further, if you’re looking for a small board to do music stuff the Teensy is a good candidate for using OSC. as well.

Final thoughts

I haven’t tried anything on OSX. Not a fan of Apple products, tend to only use my Mac for certain audio/visual applications. For my usage there’s no gain, since I can at least work with the Flora+MIDI on Ubuntu. If you’re curious I suggest trying the steps I described here. They might work.

I am well aware that I may have been hasty or overlooked something obvious and completely missed the boat on how to handle the problems on Windows, and if anyone has any pointers on what I should try I’d love to hear them.

Listen




Love me on Spotify!11!1