The Raspberry Pi Zero W (rpi0w) has a lot of properties to make it a great musical instrument (CPU power, affordability, portability, power demands). First thing on my list is serial MIDI in, to hook up my octatrack. I compiled the following guide to equip the rpi0w with MIDI in.
- Install Rasbian (my version is 2017-04-10)
- Midi requires the serial device “/dev/ttyAMA0” to be exposed through the rpi0w’s header pins. Unfortunately, the bluetooth service is internally connected to this serial device and only the “/dev/ttyS0” soft serial device is available through the GPIO. Lets change this:
- Disable bluetooth: “sudo systemctl disable bluetooth.service”
- Add “enable_uart=1” and “dtoverlay=pi3-disable-bt” to /boot/config.txt
- Remove “console=serial0,115200” from /boot/cmdline.txt
- Midi has a typical baudrate of 31250, a non supported one by the rpi0w. Let’s reprogram the 38400 rate to behave like a 31250 one.
- Add “init_uart_clock=2441000”, “init_uart_baud=38400, and “dtparam=uart0_clkrate=3000000” to /boot/config.txt (each on its own line, do not add the double quotes). The 38400 baud rate will now operate at 31250 baud.
The last lines of your config.txt will look something like this:
Reboot your rpi0w to make the changes effective.
Upon login, install “wiringpi” to check the configuration of the GPIO. Issue a “gpio readall”. Physical GPIO pins 8 and 10 should display an ALT0 mode:
The configuration of your rpi0w is good to go!
On the hardware side, I followed Joseph’s instructions on SamplerBox, using this schematic:
Run the python program supplied on the SamplerBox page to test the Midi in. The python program should output “note on, note off” messages upon incoming midi notes.
Midi & Alsa
To hook up the midi input to the Alsa audio system, I’m using ttymidi. To install ttymidi, you have to make a small change in the Makefile.
- Download ttymidi with “wget http://www.varal.org/ttymidi/ttymidi.tar.gz”
- Untar and edit the toplevel Makefile, add “-lpthread” to the all: statement.
- Make and sudo make install
- Run with: “ttymidi -s /dev/ttyAMA0 -b 38400 -v”