Piano HAT on PiZero as USB MidiGadget

I have a Blokas PiSound on my RPI3 which accepts USB Midi devices. I have my piZero set up as a USB Midi gadget on which I have my Piano HAT. Any ideas as to how to get it the PianoHAT to send Midi messages to the PiSound. I have previously sucessfully used midi-piano.py on the Piano HAT using Yoshimi but now I need to send midi from my PiZero to Sonic Pi running on my RPi3 ? Once I;ve done this I want to d the same with the Drum HAT on a different PiZero.

You’ll need to use the configfs method of setting up USB on the Pi Zero in order to use MIDI. There’s a good guide to it which got me up and running here: http://andrewnicolaou.co.uk/posts/2016/pi-zero-midi-3-two-things-at-once

It’s actually quite a discoverable interface once you get started with it.

I had a Piano HAT midi controller set up recently, and I remember just opening the /dev/midi device like it were a file and simply writing regular MIDI messages out to it. I seem to have lost the code that I used to accomplish this, but I’ll post it here if I find it.

I pretty much just read the MIDI spec- which is super simple- from here: https://ccrma.stanford.edu/~craig/articles/linuxmidi/misc/essenmidi.html

And then wrote the relevant MIDI commands to the opened file.

The result: