For a while I've been thinking it would be a neat hobby project to make my own toy piano. Not a full sized one, but something more that a kid would use with tiny keys. I'd need to have some sort of electronic system that could get keystrokes and play MIDI notes in response. I'm pretty good with Java, but know very little about hardware or how I'd go about building such a thing. Any suggestions?
I'm making some assumptions and not considered cost, so take what you will out of my reply.
Assuming that your MIDI notes are files, you would want some kind of storage to store them and some intelligence to read them. That immediately suggests a microcontroller.
You also want sound to be output.
So my suggestions in order of increasing complexity:
1. Use a Raspberry Pi (Model A is good enough for this, Model B/B+ would be overkill):
- It can run Java, has onboard audio output, and can accept keyboard inputs via USB or onboard GPIO (General Purpose Input Output) pins
- On the Raspberry Pi, write a program that reads the USB device or GPIO pins.
My preferred way to program the Pi is using python or C because the community and support are good. But if you're not comfortable with them, then use Java + [Pi4J library.
- This program checks the inputs, selects appropriate MIDI file and runs a command line MIDI player like timidity to play it.
- You need some kind of keyboard (maybe a mini USB qwerty, or a membrane keypad, or build your own 3d printed piano keyboard). Unfortunately, I have never built a keyboard, so I don't
have any suggestions, except to search in a site like Instructables.
- Connect keyboard to Pi via USB or via the onboard GPIO pins.
2. Using an arduino:
- I don't have a precise answer, but since you mention you're new to electronics, I thought I'll introduce some arduino related words that might help you google for a solution.
- Arduinos don't have onboard audio output capability. So you want to search for an appropriate "audio shield". "Shield" is the arduino term for an addon board that connects to
the arduino and adds some capabilities to it.
- If the audio data is small enough, you can store it in arduino's memory (which is limited to 32KB-256KB). Otherwise, you'll also need an SD/microSD card shield to store the data.
- Again, you'll need some kind of keyboard/keypad, but USB devices can be connected to only to a Yun as far as I know. For other arduinos, you'll need
a USB shield or other specialized shield.
I did something like this a long time ago, which will be somewhat out of date now. The first thing you should do before you consider the keyboard is program a microprocessor to send midi data to a synthesizer and make it play a note, and next make it play a scale. Look up the midi spec and see how to transmit pitch and "velocity" (volume) to a synthesizer. There is both a hardware and software spec, for midi.
Once you are the master of that, consider each key on the keyboard a switch and the micro will read the switches and if one is closed will transmit to the synthesizer the midi data corresponding to the pitch that that key represents. You will also want to control how the note decays as the key is held down, also done by sending midi to the synth.
My project didn't read keys but was actually a wireless system to get midi data into a synthesizer. I used a z80, I'm sure. For a modern micro development board I would consider the ARM M series. I don't know if there's Java development for it, but I know it does C. You can get the board for about $40.
The modern touch might be the synthesizer would be your computer and the connection would be usb... Figure out what midi hardware you want to use and choose a board that will support that.
Also, both Coursera and EDx offer a course on microcontroller development. After working through one of those the project would be a breeze.
Mark McKay wrote:For a while I've been thinking it would be a neat hobby project to make my own toy piano. Not a full sized one, but something more that a kid would use with tiny keys. I'd need to have some sort of electronic system that could get keystrokes and play MIDI notes in response. I'm pretty good with Java, but know very little about hardware or how I'd go about building such a thing. Any suggestions?
You can go for https://www.arduinostarterkits.com/resources/arduino-uno-cases/"" target="_new" rel="nofollow">arduino starter kit. It will be helpful for creating you tiny piano project. Arduino starter kit provides you most of the hardware for your projects. And keep one thing in mind, circuit or device needs protection, your Arduino board also need a protective layer to keep it safe from the accidental damage. So, you can also take some protective case for arduino.