Arduino Forum

Using Arduino => Audio => Topic started by: SotosAle on Jul 28, 2012, 09:42 pm

Title: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Jul 28, 2012, 09:42 pm
Hi there,
lately I've been thinking to build a 72-key Arduino Piano. I had searched a lot, until I bumped into this guy's site: http://midikits.net23.net/midi_8x9_keys/midi_8x9_keys.htm
I first thought he was selling the circuit, but then, as I was scrolling down the page, I found out some circuit diagrams: http://midikits.net23.net/midi_8x9_keys/keys_8x9_switches.gif
"OK, now I know exactly how to organise all those switches in a matrix", I thought. But the problem is that I have no idea how to program my Arduino UNO R3, so that it transforms the signals received to sound. I guess I' ll have to connect the MIDI 5-pin socket to some kind of device, but I thought of an alternative. What if I sent the information received by the Arduino over to my PC and then convert it to sound, which will be produced by my PC's speakers? In that way I think that I could program my PC to produce different sounds for each key pressed; just like an ordinary keyboard, which can play different instruments.
Yesterday I sent an e-mail to the creator of the site but he said that the source code isn't available, but he can sell an Arduino compatible, pre-programmed chip for 9 Euros (about 9 Dollars)! It was clear that he is trying to make a profit out of it! Those people totally piss me off!
Can anybody help me with this project? I would really apreciate it! Keep in mind that I want to be able to play chords (press two or more keys simultaneously) and I also want to hear the note produced for as long as I keep the key pressed, but fading a little bit as time passes.
Thank in advance for your answers!
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: el_supremo on Jul 28, 2012, 10:09 pm
Quote
pre-programmed chip for 9 Euros (about 9 Dollars)! It was clear that he is trying to make a profit out of it! Those people totally piss me off!

There's nothing stopping you doing it and then sending pre-programmed chips for free to anyone who asks for one. That would really eat into his obscene profits.
Oh wait.
You can't.
You don't know how to do it.

Pete
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Jul 29, 2012, 01:17 am
Not of much help...
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: Magician on Jul 29, 2012, 01:36 am
I think, there are 2 questions:  keyboard and midi synthesis.
For first one, search multiplexing, there are bunch of examples, including arduino codes:
http://arduino.cc/playground/Main/InterfacingWithHardware#InputTOC (http://arduino.cc/playground/Main/InterfacingWithHardware#InputTOC)
http://arduino.cc/playground/Main/InterfacingWithHardware#keyb (http://arduino.cc/playground/Main/InterfacingWithHardware#keyb)
For second, midi synthesis, there are special midi shields based on 40 polyphony IC:
https://www.sparkfun.com/products/8953 (https://www.sparkfun.com/products/8953)
Of course, you can do synthesis on PC, there are open source / free software available on-line.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Jul 29, 2012, 02:48 am
Thank you for answering! The links provided seem to be useful, but I'm too newbie to find the information I want.
Firstly, I intend to build the switch matrix. Then I will make all the necessary connections, and I will connect the MIDI OUT to a MIDI to USB converter (yeah! I've just found out that there's such a thing!). A USB port on my computer will be used to receive the binary information; that means that I need special software to covert the signals to sound, aren't I? As far as the multiplexing is concerned, I don't think that it is essential. This schematic requires 18 I/O pins on the Arduino, so there is no problem.

So, the problems are the following:
1.Do I need to download the MIDI library for the Arduino? If yes, how do I install it?
2.How can the signals from the 72 keys be converted to MIDI signals? What is the source code for this purpose? (I don't expect anybody to sit and write the whole code for me. That would be called "audacity". I just need some information, in order to learn how to do it on my own. Of course, I would refuse to accept any code...)
3.Is it possible to just convert MIDI to USB, without using any extra equipment? This site: http://arduino.cc/en/Hacking/MidiWith8U2Firmware put thoughts into my mind...

And I said previously: "Keep in mind that I want to be able to play chords (press two or more keys simultaneously) and I also want to hear the note produced for as long as I keep the key pressed, but fading a little bit as time passes" (this probably has to do with the source code - part)
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Jul 29, 2012, 02:57 am
About the MIDI to USB converter, I' ve found this: http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html
Is it fine?

P.S.: I don't intend to spend any extra money on bying more circuits. It's OK to build my own, but not buy already-done ones. Those are far more expensive, than handmade.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: sammyg on Aug 03, 2012, 10:36 am
I'm actually just about to start a similar project to convert an old organ console into a MIDI controller for my computer. Magician is right; you have two problems to tackle here: the (hardware) controller and the synthesis. Disclaimer: I'm also a complete newbie to Arduino, but I've done a fair bit of programming and I'm currently studying audio engineering.

Outputting MIDI via USB on the Arduino itself seems perfectly plausible, and also more sensible than wasting serial pins when you're already gifted with USB output :) That SpikenzieLabs link looks like it could already have it sorted for you...

There is a library that reads switch matrices here: http://arduino.cc/playground/Code/Keypad and it comes with its own tutorial: http://arduino.cc/playground/Main/KeypadTutorial#Notes. It may need a little modification to handle large matrices (I need to read in 200 odd switch inputs!) but it looks like a very good start. The Arduino MIDI libraries look like they can handle all the MIDI output needs you'd ever want, so all you'd need to write is some code to map the output returned by the Keypad library into input for the MIDI library. The Keypad library has both key press and key release handling which you'd use to send your note-on and note-off messages. Handily, there's a built in event listener, which you'd probably want to use to call your own code.

Let me know how you get on; if I come up with anything handy, I'll be sure to stick it up on the Playground.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Aug 04, 2012, 11:45 pm
Well, I'm not sure that downloading Keypad Libraries would help me. So, let me make more clear  :)
As I told in a previous post I found this wiring diagram ---> http://midikits.net23.net/midi_8x9_keys/keys_8x9_switches.gif
and I think its ideal. It is really easy for me to make so this would be the one I am considering to use (unless sb has a better solution). The hardware issue is really sorted out! My only problem is how I' m going to make the Arduino to translate the short of two pins to binary information ready to be read by a midi software. This my plan:
1. I Press a key.
2. A switch creates a closed circuit between 2 Arduino pins.
3. The Arduino "senses" that.
4. And begins the "translation" process.
5. Then it sends out a signal to the MIDI connector.
6. The signal then is read by a MIDI device (which in my case would be the computer).

I have figured out steps 1, 2 and 6, but I have no idea what to do for steps 3 to 5. Keep in my mind that I'm not sure if this is the process required in order to output a MIDI signal, but I believe that you will understand what my point is.

Thank you for all your answers and help  :)
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: sammyg on Aug 05, 2012, 07:53 am
This is precisely what the Keypad library does :) - take a look at the tutorial. The wiring diagram you posted is a keyboard matrix, which significantly reduces the number of required IO pins. To achieve step 3, you need matrix scanning code (which is what the Keypad library is). As a bonus, the way it is written eliminates the need for the diodes in your wiring diagram, hence the simpler diagram: http://arduino.cc/playground/uploads/Main/keypad_pin_diagram.png Of course, instead of a keypad, you have a musical keyboard, but the principle is exactly the same, just with all the keys laid out in a single line instead of rows. There is plenty of info about scanning keyboard matrices on the web, but I suspect it'll just show you that using pre-built Arduino libraries will make life much easier :)

Step 4 will be your own code to define which midi signals are sent out for which keys.

Step 5 MIDI signals themselves are dealt with by the MIDI library and whichever USB MIDI solution you choose to use. (Suggest you get it working on normal MIDI first, before getting caught up in USB MIDI stuff...)
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: sammyg on Aug 05, 2012, 08:48 pm
If you *really* want all the details about scanning key matrices:
http://www.openmusiclabs.com/learning/digital/input-matrix-scanning/

(Convinced me pretty thoroughly that Arduino was the way to go, but it brings up some interesting stuff nonetheless...)
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: mstanley on Aug 08, 2012, 06:56 pm

To achieve step 3, you need matrix scanning code (which is what the Keypad library is). As a bonus, the way it is written eliminates the need for the diodes in your wiring diagram, hence the simpler
sammyg, you are correct that the diodes are not required for preventing shorts between keys on keypads and keyboards.  But there is another problem called shadowing where some combinations of multiple keypresses will cause the keyboard driver to think that an extra key is being pressed when it is not.  That would mean an extra note would be added to the chord.  The solution is to place a diode across every key.  All midi keyboards should already have the diodes but if op builds his own he should add them.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: sammyg on Aug 10, 2012, 06:11 pm
Ah, indeed; rather a large oversight on my part. Thank you for pointing this out mstanley and of course, thanks for writing such a useful library :)
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: ypelletier on Aug 11, 2012, 02:47 pm
I built a MIDI controller with an old organ keyboard, an Arduino and two hc595 shift registers.  It is documented in my blog (it's written in french, but maybe the sketch and schematics will be of some help?)

Scanning the keyboard and displaying the result on the serial monitor:
http://electroniqueamateur.blogspot.ca/2012/05/decodage-dun-clavier-dorgue-par-un.html (http://electroniqueamateur.blogspot.ca/2012/05/decodage-dun-clavier-dorgue-par-un.html)

And then sending out MIDI messages:
http://electroniqueamateur.blogspot.ca/2012/05/clavier-midi-base-darduino.html (http://electroniqueamateur.blogspot.ca/2012/05/clavier-midi-base-darduino.html)
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Aug 17, 2012, 04:04 pm
:~ Hmmmm... All those tutorials confused me... The last one seemed to be the best, but unfortunately it is in French and I couldn't understand what's going on! I downloaded the Keypad and MIDI Libraries and installed them, but I really need some guidance for the code. As I've already mentioned I couldn't figure it out... I suppose that the given codes in the links need to be modified in order to work with my switch setup, which by the way I've built. I used these switches ---> http://www.superdroidrobots.com/images/TE-044-000.jpg and I also used 1N4148 diodes just in case. I installed them on a wooden structure but there  are not any keys yet. These will be made later. Anyway...  I know that I asked for instructions, but that doesn't obviously work... So, would anyone be kind enough to write the code for me, or give me some clear instructions on how to write the code on my own (don't forget that I want the code to co-operate with the swtitch setup I made).
Sorry for being such a newbie, but I really need to complete this project.
Thanks in advance...
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Aug 26, 2012, 01:20 pm
Come on.... Somebody! I' ve already invested money in this project. It would be such a pity if I gave up!
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: iyahdub on Aug 30, 2012, 08:20 am
It seems its too big a task for you, as you said yourself...So why dont you start with simpler things instead of expecting someone to do it for you ?!?
Above you have enough information and examples to guide you in your quest... But problem is you dont have the knowledge !! So, start researching and start doing things by steps !! You will get there in the end !!
No need to give up !!
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: xray303 on Aug 31, 2012, 10:45 pm
I would say the same as iyahdub, start with very basic thing and only after that, try to integrate more difficult ones.
It will be very difficult to do this kind of project if you can't blink a led or read a port of the arduino.

So firstly try to connect a switch to a arduino port and a led on another port, then try to light the led when pressing the button (using arduino code), i know it looks ridiculous but you will learn how to read a port and write on another.
When you will be more familiar with arduino coding, try to use your switch matrix with the keypad  library to light up few leds.
After this you can also try to use the midi library with one switch. (try to do a Midi Noteon using this switch).
When you manage to do all these mini projects, you will abl to combine all theses and finish your project.

What i'm trying to say is: try to split your project into smaller separate part, and do them one after one.

And don't forget .. google is your friend ..

and to help you a bit on midi lib : http://little-scale.blogspot.ch/2007/06/arduino-midi-out-example.html



Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Sep 01, 2012, 02:15 pm
Thanks to everybody for your advice I'll get down to bussiness soon!
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: Nantonos on Sep 22, 2012, 08:37 pm

I built a MIDI controller with an old organ keyboard, an Arduino and two hc595 shift registers.  It is documented in my blog (it's written in french, but maybe the sketch and schematics will be of some help?)


I read French (I live in France) and my native language is English. If you are interested to have parallel French and English versions of those Arduino MIDI blog posts, I would be happy to translate them for you.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Sep 22, 2012, 10:43 pm
It would be great if you did so!
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: MikeOToole on Nov 05, 2012, 05:36 am
I'm about to start a similar project and although there no guarantee it will be finished any time soon, I will bookmark this topic so I can add a link when I have completed the necessary information gathering...

The project relates to building a basic midi keyboard (61 keys or so), generating on/off, velocity and possibly aftertouch data... Note, I won't use a diode matrix for keyboard scanning, probably something more on the lines of a common bus (polled configuration)... Anyway, I thought I mention it in case you loose interest...

I still have to determine what is necessary to use uno in midi mode, believe I need to reprogram 16u2 and a few other bits and pieces...
Mike
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: SotosAle on Nov 05, 2012, 10:29 am
I'm looking forward to seeing your project! Thanks for the reply!
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: DuaneB on Nov 05, 2012, 11:58 am
No midi in this on going project of mine, but similar idea using a cheap keyboard -

EDIT - post has been updated a lot - so not a repost. Code is still in need of a tidy up before I publish it, but I can send it to anyone who wants to try it.

Current features are - arpeggio record and play back with adjustable speed, 4 waveforms and transpose

http://rcarduino.blogspot.com/2012/10/five-dollar-synthesiser.html (http://rcarduino.blogspot.com/2012/10/five-dollar-synthesiser.html)

Duane B
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: Thot on Nov 07, 2012, 02:26 pm

....
Of course, you can do synthesis on PC, there are open source / free software available on-line


Magician, I spent hours looking for something like that for my project but did not find anything satisfactory.
Closer thing I found is VMPK: http://vmpk.sourceforge.net/
What do you recommend? I am looking of something "Arduino friendly".....

Thanks
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: winelight on Nov 15, 2012, 09:15 pm
OK guys I am wanting to do something similar to what's already been discussed. Basically I have built myself a 4-keyboard (3 manuals and one pedalboard) organ from old 70s analogue organs. There are also 40 tabs (switches). It kind of works as it is but it's nothing great, and the 40 tabs aren't connected to anything at all yet.

So I'm thinking about ignoring the analogue stuff and simply using the keyboards and tabs to generate midi signals, which is not such a big deal I can do keyboard scanning as already discussed, along with debouncing of course, plus I'm capable of reading the midi spec and generating midi protocol - although if I can find a library to do it for me, I don't mind at all!

But I don't really want a midi hardware interface because it's too slow: I want midi over USB. That's the only bit I know nothing about. I suppose I need a library like V-USB but in these forums I've read comments like "Implementing USB within the resource limitations of the these microcontrollers is "non-trivial"", and suggestions that it's best to use a second microcontroller purely for the USB, and that even the V-USB library is still "too complicated". So any pointers greatly welcomed.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: Nantonos on Nov 16, 2012, 01:03 pm
The Arduino-compatible Teensy 2.0 and Teensy 2.0 ++ (http://www.pjrc.com/teensy/index.html) boards have native USB-MIDI. They show up as a class-compliant USB MIDI device and your OS will use it's built-in driver to talk to them. Also, MIDI over USB is faster (so, lower latency) than traditional current-loop DIN MIDI.

The comments about matrix scanning and diodes on your key matrix still apply. Probably useful to tread how a MIDI keyboard works (http://www.openmusiclabs.com/learning/digital/input-matrix-scanning/keyboard/) and this DIYAudio forum posting (http://www.diyaudio.com/forums/instruments-amps/200973-diy-midi-keyboard-remodeling.html#post2791262).

So far, velocity sensitivity and channel aftertouch have not been mentioned - do your organ manuals have those?
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: jenshen on Dec 13, 2012, 06:37 am
Hi All,

I thought it might be interesting for some of you. I've wrote a step by step tutorial with schematics / breadboard and source for Arduino on how to convert a Piano toy into a MIDI keyboard:

http://www.codetinkerhack.com/2012/11/how-to-turn-piano-toy-into-midi.html (http://www.codetinkerhack.com/2012/11/how-to-turn-piano-toy-into-midi.html)

Would be glad to know if it was helpful to anyone.

:)

Thanks,
JenShen
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: 2wice on Jan 06, 2013, 08:44 pm
http://www.ucapps.de/midio128.html

This would probably be easier for your needs.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: jenshen on Jan 06, 2013, 10:59 pm


This would probably be easier for your needs.


Looks good but not easier at all - definitely require more effort. It has nothing to do with Arduino - different platform altogether.
Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: jenshen on Jan 27, 2013, 10:35 am
Hi All,

I've added Velocity sensitivity and Aftertouch to my earlier project.

Could be of use to someone: http://www.codetinkerhack.com/2013/01/how-to-add-velocity-aftertouch-midi.html (http://www.codetinkerhack.com/2013/01/how-to-add-velocity-aftertouch-midi.html)

Thanks,
JenShen

Title: Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question)
Post by: KyleIvanBlake on Feb 22, 2015, 06:25 am
Come on.... Somebody! I' ve already invested money in this project. It would be such a pity if I gave up!
If you don't have any programming background, you are going to need to learn how to program.

I recommend taking Principles of Programming I, II, and III at a local State University, or buying a C++ book, reading every chapter, then doing the "homework" at the end of each chapter so you can learn to code.  Those libraries are meaningless without programming ability.