Sunday, 8 January 2012

Midi-izing the Reissue Stylophone


A while back I did a "midi conversion" of a couple of Stylophones (The original analog model). I did this by removing the Stylophone electronics and leaving just the stylus, keyboard and resistor ladder. Using the keyboard as a voltage divider its then possible to connect the stylus to an analog input of a microcontroller (such as Arduino) and read the analog voltage to work out which note is being touched, then send out MIDI note data accordingly.

There are a few problems with this approach:

  • The stylus, keyboard and resistor ladder need to be disconnected from the rest of the stylophone circuitry... Looking at the stylophone schematic the best I could do was a minimum of three connections to break. It wouldn't be possible to have the original sound at the same time as MIDI doing it this way.
  • As with any mapping from an analog voltage to a range of discrete values there is a risk that a bit of dirt or grime on the keyboard will add enough resistance to cause the wrong note to be mapped. Not good!
  • Original Stylophones are classic bits of kit and ripping the guts out of them doesn't feel right. Also they aint getting any cheaper.


Since I had a couple of "reissue" Stylophones I picked up on ebay I decided to see if they might prove a better bet for a conversion...

The first problem was getting inside the thing... while the old Stylophone closed with a clip-on back, the new one is glued shut and getting it open without breaking any of the plastic is easier said than done.

Expecting similar nasty cost cutting inside I was actually surprised to find how much is actually in these things. There are no less than four separate circuit boards all individually screwed down to the case and connected with wires (although they are crappy wires with joints that snap when touched)

Removing the boards from the case I found there is the obligatory chip-on-board "black blob" and a few SMD components on the main board. As I expected these new Stylophones do away with the analog tone generator circuit in favour of some custom chip that presumably digitally creates the sound. There is also a through-hole soldered amplifier board and separate carriers for the power/vibrato switches and volume pot.


Those chip-on-board blobs are usually heart-sinkingly unhackable and the sight of one usually spells the end of any thoughts of doing anything interesting. However I was intrigued to see that there was a separate trace from each keyboard pad to the blob, and checking the stylus I found it was wired directly to the +4.5V supply.... so could it be that we had a digital inputs line for each keyboard pad, with some pull-down resistance? That would almost be too good to be true... but true, it was!


So why is that good? well microcontrollers like the Arduino love to read digital (i.e. ON/OFF) inputs. These are nice and reliable without the dirty connection issues of analog inputs, but not only that, you can "piggy back" your inputs off the original input lines (since you are just reading a voltage, not drawing a current). What this means is that you can read the notes being played, while the Stylophone circuit is still attached to the keyboard and playing normally. Also you should be able to get an Arduino to actually play the Stylophone, by feeding ON (logic HIGH) values into the lines... but I might leave that till another day :)


Even better, the board has an exposed pads on each line perfect for carefully soldering a wire to. So thats the good bit. The bad news is that there are 20 of these input lines... thats a lot of wiring and is enough to use up all the inputs on a Arduino board...

I decided to use 74HC165 shift registers to read the keyboard and cut down the number of input lines needed. These chips each read 8 inputs then send the data out in a serial stream. By chaining these together, any number of inputs can be read with just 3 wires to the Arduino (one to "capture" then inputs then a "clock" and data line for reading the data).


Using fiddly surface mount components it was possible to fit 3 of these shift registers on a board that would fit underneath the Stylophone main board, keeping it out of the way and snugly held to stop it shaking around.


An Arduino Nano would fit in the Stylophone case, but I decided to use a custom SMD board since I wanted to add an KXPS5 accelerometer to detect tilt (for pitch bend). I also added another 74HC165 shift register to the chain for reading additional inputs from a row of tactile switches mounted to the back of the Stylophone. A 5mm RGB on the front allows a "mode" to be indicated.


And it worked... mostly. I am having some issues with the accelerometer which may be down to a bad connection (those things are a bitch to solder!) but the keyboard reading and MIDI is working pretty well. Hopefully it will all be finished soon. Watch this space!


UPDATE: I finally found out why the accelerometer wasn't working... even in analog output mode on the KXPS5 it is neccessary to set the "enable" input high only AFTER the chip is powered up (at least 1ms after). I had tied the enable input high on my etched board, d'oh! Failure to do this makes the analog outputs go mental... I only found this out after I decided to ditch my homebrew board and use an Arduino Nano in there. 

4 comments:

  1. Hi, how are the tests doing, any final result yet? I ' m wishing to see them.

    Greetings

    ReplyDelete
  2. Hi - I did get it finished. The video clip is here
    http://www.youtube.com/watch?v=PYQHvYYkVoI

    ReplyDelete
    Replies
    1. Hi, I want to do the reverse and feed in a voltage from 0 - 5 and get a sound. I have my new stylophone apart - what do I do next. Great if you can help. Thanks.

      Delete
    2. Well you're looking at a totally different setup to add MIDI in. If you have the reissue stylo you need to provide a HIGH to one pad at a time. You can probably do it with 74hc595 shift registers. Use the analog in on an Arduino to read your control voltage and apply +5V from the Arduino to the appropriate keypad. Use a resistor to stop too much current flowing down to the +4.5 stylophone electronics. I guess you could experiment first with a couple of pads connected directly to Arduino output pins. Make sure you connect the GND circuit of the Arduino to the GND of the stylophone. Hope that stream of consciousness helps you :-S

      Delete