Re: GPIO to alsa

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 28 Feb 2016, Raphaël Mouneyres wrote:

Having some bare keyboards and raspberry-sortof boards, I'd be interested in connecting both of them without using a midi interface, but only the available GPIO pins available on the board. This is as well to save external components and as a programming exercise.

Sort of in the same boat... I have a RPi on order and wish to use it as the core of a MIDI/OSC/possibly OCA controller. I am using as a control surface with buttons and encoders in the form of a mixer.

I want it to be cheap as in cost only a little and am finding it less expensive to buy things than parts. For example, I want displays for mettering, for encoder values, for switch value. look up encoder rings, look up the supporting circuitry... not cheap, so I thought I can get a 7inch touch screen to put all that on that will plug right into the Rpi pretty much $100CAD, but I was able to get a new android 9 inch tablet for $70CAD which can act as a network teather device over USB. As a bonus, the same sw I will have to develop to use it, will allow it to be used wirelessly too.

Switches are also not cheap. even membrane switches end up costing more than $1 each. I find this mind blowing when I paid $3 at the dollar store for a keyboard with over 100 switches that comes with a controller built in. Out of which I built this:
http://www.ovenwerks.net/hardware/3dollarcontrolsurface.html
The SW is user space and talks to Jack MIDI rather than ALSA.. I'll talk more about that below.

I don't like membrane switches. However I can get a keyboard with cherry mechanical switches for under $100 with no ledgend on them. (quite a lot less for Cherry black, not so much less for Cherry Brown) Some of them even have a LED per key (but not so much an individual method of driving them I think)

I was originally planning to take my $3 keyboard and cut it up into 4 switch rows and rewire it, and plug the USB into into my RPi... done, I have the SW to compile on the rpi already to go :) The "rollover" is only 4 and it would probably be nice to have more, but a lot of the mechanical KB have "n rollover" if they are used with PS2. So I am going to see if I can set up one of the RPi serial lines to deal with that.

After searching for information, nothing revelant was found, except a experimental python script to read gpio and using the mididings library to output messages.

What kind of a keyboard for what use? If you mean a piano style keyboard then latency becomes more important. I would suggest script may not be the best way to go. c or c++ makes more sense.

Is there a existing project which would scan rows/colums of a keyboard from the designated(configured) gpios, and throw midi message to an alsa midi port ?

My next phase for midikb (the SW I used above) is to add ALSA MIDI to the mix. However, have you looked at:
http://ucapps.de/
http://wiki.midibox.org/
They do not use the RPi mostly because this project has been around longer than the RPi.

Would such a program better be a kernel module or a userland program ?

Personally I would like to get my project out of userland. Right now I am using Jack so user land it is. But that means I have to give the user access to the /dev/input/* files which are normally system. This does lend itself to a possible security problem. (though the same thing may be possible at the user level in X or whatever session manager is used. So I would like to move to ALSA because it seems ALSA midi can deal with midi ports across users (someone correct me if I am wrong). It looks (so far) easier to run a system service tha "grabs" a keyboard (or the output of a keyboard scanner) and just outputs MIDI to the ALSA sequencer ports. It is still possible to tell ALSA "this is a HW device" from there. So that is the next step in my audio SW training :) Making a kernel module/patch is at another level of programming which i may attempt some day by starting with the snd-serial-u16550 or mpu401 code.

In your case you need to learn about the scanning part first. This is pretty much straight bit bang stuff. If you happen to have a set of address lines, set to 0x01 output. then input data or input bit at a time. Then shift left and input again. Not hard. Placement of diodes on switches is important to allow chording (more than one switch at a time). After you have this input you will want to do some debounce. Then you have a list of keys that are down. What you do with them from there is up to you, some kind of a lookup table to convert from key to MIDI note... 8 address by 8 data lines will give you 64 keys. Thats 16 GPIO lines for no external circuitry. The RPi is not overflowing with gpio that are not multipurpose... so maybe try this:
http://pi.gadgetoid.com/article/building-the-pico-piduino
or this:
http://www.hardkernel.com/main/products/prdt_info.php?g_code=G135390529643

Not very comprehensive for sure. However, that is what DIY is all about, Take the bits, do research, make something new.

Enjoy.

--
Len Ovens
www.ovenwerks.net
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/listinfo/linux-audio-user

[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux