Cabbage Logo
Back to Cabbage Site

How can I use the Serial Opcode to trigger a sound from an Arduino?

I agree. I would definitely recommend the use of MIDI here too.

Just letting you know I have a leonardo showing up as a midi human interface device with my code flashed. You have to include some dependencies for it to work, at first my code built and flashed but didnā€™t show up as a midi HID, then I fiddled about a bit, then the problem below came and bit me, then it worked and I have

[lorien@h2 ~]$ aseqdump -l
 Port    Client name                      Port name
  0:0    System                           Timer
  0:1    System                           Announce
 14:0    Midi Through                     Midi Through Port-0
 20:0    Arduino Leonardo                 Arduino Leonardo MIDI 1

My advice is be careful with leonardos though, instead of having separate chips for USB and micro-controller itā€™s one chip for both. All sorts of craziness to do with permissions, the only way I can flash the bloody thing from linux is running the arduino ide as root, because it has to reset the leonardo prior to an upload, and during those instants after a reset the permissions change- changing the serial port permissions does nothing because they change again anyway in the moments before a reflash. No option but flash as root.

Anyway Iā€™ll make another topic once Iā€™ve sorted it all out a bit more.

1 Like

@rorywalsh this is re-written after figuring out why nothing was working.

The midi library depends on one called USB-MIDI as a transport layer, which in turn depends on MIDIUSB, the official arduino library. When I linked MIDIUSB the device shows up as a midi HID. But it doesnā€™t actually send any midi messages at all. Itā€™s a horrible and confusing mess thatā€™s totally locked up my machine repeatedly as Iā€™ve fiddled.

Turns out what you need to do is use another macro to create the midi port. It looks like this

#include <MIDIUSB.h>
#include <USB-MIDI.h>
#include <MIDI.h>

/*other code*/

USBMIDI_CREATE_DEFAULT_INSTANCE();

I was creating the wrong kind of midi port by using MIDI_CREATE_DEFAULT_INSTANCE so it wasnā€™t sending any messages via usb.

I have a working footpedal now :smiley:

Later edit: and having wires soldered straight to the leonardo which is enclosed in a grounded steel case thereā€™s FAR less noise in the system, the pot is behaving way better than on prototyping board, after tweaking those template params a little Iā€™m getting full 10-bit resolution whilst sampling at 500Hz with barely any chatter.

Nice one. Iā€™ve a feeling Iā€™ll be returning to this next semester in my interactive systems class :slight_smile: