Close

"Just one more pin!"

A project log for Stylish!

A most stylish wearable music synthesizer! A real stylus based monophonic music synthesizer built into a giant trucker belt buckle!

t-b-trzepaczT. B. Trzepacz 10/09/2018 at 04:210 Comments

Previously in our adventures, I had to reuse the line for the MODE button for one of the keys, because the line it was using turned out to be used for USB. <Sad trumpet sound>

Well, I'd still like to have a MODE button, but I'm out of pins. I'm trying to keep the cost down, so I don't want to add extra shift registers and multiplexers to the design.

Now, if I could hit two pins at exactly the same time (say WRITE and PARAM), I could detect that in software. But if I just wired those two pins to the pad, it would hit both pins if I hit either of the original pads as well.

The obvious solution to that is to add two diodes going from those pins to the MODE pad that I want to trigger. Current can go to the MODE pin, but it can't come back up to the WRITE pin if the PARAM pad is touched, and vice versa. SMD Diodes are cheap, and PCB assembly houses usually have that kind of thing in their stock, so I'm not even worried about the price of these items.

The circuit for this is pretty simple:

I used a 1N4148 switching diode, which is pretty common in keyboards and such and is very good for this type of task. I still have a ton of them from when I was trying to build my own keyboards for the NanoEgg synthesizer project (I will get back to it eventually, I promise!)

So then, wiring it up:

The first thing to do is to disconnect the mode button pad from it's pin and from the pad for the key that needed to be remapped.

Then a bodge wire needed to be run to reconnect the keyboard pad to that pin again. That is in black in the picture below.

Then, two diodes need to be attached to the MODE pad (black line on that side for correct polarity, and the other end attached to the pins/pads for WRITE and PARAM. I put yellow insulation on the leads to keep it from shorting stuff out. It is easy to find such things on the floor if you never clean up in your workshop / home.

Here you can see the two diodes in yellow attached to traces going to their pins on the right, and the mode button on the left, and the wire rerouting the key's pad to the pin that was formerly for the mode button in black on the lower left.

Powered up in software and everything is worky! Yay!

How to do the software?

Just put an "if" statement before returning any key down and check for both pins together. If they are down, set the value to the mode button instead of either of those two pins. Standard debouncing applies.

So, there you go. A pretty basic hack that involves hardware and software, but saves a lot on money for a multiplexer. Obviously, one could use this technique to multiply pins to get more buttons, but at some point board real-estate, part and assembly costs come into play and you might be better off with a multiplexer or shift-register solution.

Pad multiplication with "charlieplexing"?

Another interesting possibility, similar to "charlieplexing" would be to move the stylus to a pin that can do input and output, and then use a diode on each pad to indicate whether it was sensitive to being an input or output.  On some pins, the stylus would act to pull the pin, and the pin would be the input. One others, the pin would be the output, and you would detect it's touch on the stylus line. This does require one diode per key, and requires one additional pin for the stylus, but doubles the number of pads you could attach. 

I'm not sure the "multiple downs per button" thing would work well here, since you have other pads reading current the other way that might be triggered  when you change the line from input to output, but perhaps that wouldn't be a problem if the software isn't looking for that input at the time it is driven that way? I'm not sure; it bears further thought. 

I know, I'll leave it as "and exercise for the reader" like they did in all of my old textbooks! Don't you just hate that? I always thought that was just the authors getting lazy. Which is exactly what I am going to do now...

Discussions