Uninstall MIDI in order to use hardware SPI?


I’m currently interested in trying to use potentiometers connected to my Raspberry Pi via an MCP3008 ADC chip, and using them to control Pure Data. Up until now I’ve been using them through a Teensy micro controller programmed to function as a USB MIDI device - this works exactly as it should, but I’m limited to MIDI resolution of 128 steps. For my current project I’m hoping for finer grain resolution, and am thus hoping to use the 10-bit ADC.

I’m aware that I can use Wiring Pi to accomplish this, however I am running into problems that I think are related to using a pisound, which uses SPI for MIDI. The pisound install is (I believe) blocking my ability to use the SPI for connected the ADC and sending my potentiometer data into PD.

I’m not using the pisound MIDI ports, so I wonder if it is possible to uninstall the MIDI part of the software only, and therefore free up the SPI for me to use with my ADC and Wiring Pi.

Does this make sense? Is it possible?

Hey, what are you controlling with MIDI CC? If it’s something you’re developing on your own, and the MIDI controller you’re using is your own, you could adopt using NRPN messages with 0 - 16383 possible values.

In theory, SPI should be shareable with more than one device, however, I haven’t tried that in practice with Linux. Pisound is using CE0 pin for the ‘chip select’ pin, CE1 should allow using other SPI devices.

To get rid of MIDI part of Pisound together with its SPI usage, a custom kernel module should be built, as well as device tree overlay in hat EEPROM should be disabled, and a custom one used. If NRPN messages won’t work for you, I’ll write a guide on how to cut SPI out, but it will require more maintenance by the user, as every kernel version update will override the custom built module with the latest official version.

Oh wow I didn’t know about NRPN! That sounds super interesting and has a pretty decent resolution :D. Yes the MIDI controllers are of my own making, using Teensy micro controllers. I’ll have to look into whether it is possible to use NRPN with them.

I must admit that I don’t fully understand SPI, but I think the problem is really specific to using Wiring Pi, as it seems to require the first CPI pin in order to work. I’ve tried making it specifically read CE1 but it doesn’t seem to like that for whatever reason.

I think I’ll avoid the whole custom kernel approach, as in this case it isn’t worth the effort. I’m managing to get some nice results already, so I’ll just look into NRPN or try to find another solution before giving up and making do with what I’ve got.


1 Like

You don’t have to follow NRPN to the letter, simply using two CC values, one for the MSB 7 bits (coarse value), and another value for the LSB 7 bits (fine value). This would be easier to do, especially if all the parts involved are developed by yourself. This is similar to how modulation wheel is implemented in MIDI.

I think I’ve (mostly) got it! I’m ‘only’ getting 0-1023 values, maybe because of the limitations of the Teensy? But that’s more than enough for me for the moment. thanks so much for the tip! I’ll post a link to code and stuff once it’s more organised in case anyone else runs into this (very specific) problem.

Great! Yeah, 0 - 1023 sounds like 10 bit precision. If you’d have to get this into something requiring 14 bits of precision (like NRPN messages), you’d simply shift your value left by 4 bits (in other words, multiply by 16).

The default for the Arduino Analog read (assuming that’s how you’re programming the Teensy) is 10 bit. If you need more precision you could get a higher resolution ADC hooked up to the Teensy via SPI.