Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Building electronic toys

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

One site I can recommend for such DIYs is Instructables.

 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 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.
 
Marshal
Posts: 79956
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Since the posts are over a year old, maybe the OP has already got such a box.
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic