Why choose SPI over UART?

I currently checking out patchbox OS since I’m interested in doing audio related stuff. Also I’m thinking about getting that pisound.
And one big question keeps popping up in my mind: why did you choose spi for MIDI when the Pi’s UART could to that job?

That’s a good question. While UART pins on the Pi’s GPIO theoretically could be used for direct communication with MIDI devices, in practice, it’s not that convenient and stable, because:

  1. 31250 baud rate is not supported out of the box, tweaking the CPU frequency is required
  2. CPU scaling would have to be disabled, as its clock depends on the current CPU frequency
  3. New Pi versions may require different tweaks.
  4. Those said tweaks could interfere with whatever a user may be trying to do with their system
  5. The tweaks must be done in the config files, so the Hat couldn’t be just mounted and be expected to work.

So a synchronized communication method, which is immune to system clock changes, and a dedicated chip for translating the data to MIDI is the most foolproof way of doing MIDI on Raspberry Pi. :slight_smile:

See https://blokas.io/pisound/docs/midi/ for more information on Pisound’s MIDI implementation.

Hi there . I was having troubles getting midi uart0 to work , but is working really well not with ttymidi and de config change dt-overlay=midi-uart0 (this sets the baudrate to 31250 when using 38400)
Working like a charm , the only problem is that I must use an aditional command If I want system messages to be read ( a2jmidid ) , with regular ALSA midi port works too , but system messages weren’t getting through for some reason.

So in my use case it is working perfectly now .

Would love to see what others have experienced about this . In case all of the rpi models have this option and its working , I will joyfully put together some installation scripts to make a module perhaps ? MIDI-UART0 . Since I communicate to other 3.3v devices I’m not using an octocoupler . Should I add a resistor on RX btw ?

Thanks

A guide for it would be great. :slight_smile: I’d recommend building the circuit for input and output using the 3.3V electrical MIDI specification.

The resistors on the output limit the current, so the pins are protected from shorts or connected device issues. The optocoupler and the diode on the input helps prevent possible ground loop effects in the audio and also protects from reverse voltage.

Im slowly trying to verify that all this steps work, is really all about this lines

sudo nano /boot/config.txt

    enable_uart=1    
   
    dtoverlay=midi-uart0

Then when using ttymidi or alikes , setting 38400 baud will use 31250 ( as per in kernel notes). I tested it and works surprisingly well. The only strange thing I noticed , Is that when using ALSA midi , I cant get System messages through well .So I instantiate an a2jmidid, use it through jack midi and works like a charm.

About the DIN circuit , I will simply add those resistors and diode as shown but going to skip the octocoupler for now , My tests are with teensy 3.6 and axoloti at the moment ,both should be ok with the voltage and adding those components will make it safer for sure

1 Like

Could you share the ttymidi or a2jmidid command lines you’re using?

ttymidi -s /dev/ttyAMA0 -b 38400 -v & 

starts midi ad 31250 baud rate if changes made to /boot/config & cmdline
I was using aconnect then Puredata_MidiOut:ttymidi in .
a2jmidid I used it later to be able to have Midi clock messages ( I wasnt getting them with aconnect + ttymidi )

I run a2jmidid and then used pathbox’s midi ports UI to connect them between jack ports , pd jack out-> ttymidi jack out

I will confirm them again here once I test again , now Im dealing with orac not wanting to behave and my OS getting super lag on ssh all of a sudden, but will report back

1 Like