Reading voltages of several wires in a ribbon cable

Hello,

I have a Meowsic toy piano that I want to equip with a MIDI out, just for the fun of it.

Writing code isn't a problem, I'm experienced at it and I know the MIDI specs. Hardware, on the other hand, is a big issue for me. I have very little knowledge of how proper circuiting is done.

Inside Meowsic, the parts relevant to the project are two ribbon cables coming from one of the boards to... well... another board, consisting of 8 and 6 wires accordingly. These appear to be a scan matrix for keys of the actual keyboard and some other buttons. By unplugging and re-plugging some, I was able to determine that, for example, the leftmost wire controls each 8th key, then the next one controls each next 8th key, etc.

I'm fairly clueless when it comes to hardware, but a friend of mine had a stash of unused Arduino Uno clones that he gave me, so this is what I'm using here. Unfortunately, Uno has only 6 analog inputs, so I'll probably have to use two of them and send data from one to another. I don't know yet, I'll cross that bridge when I come to it. Anyway, I plan to read voltages coming along these wires and output MIDI signals from the Uno (note on / note off).

I determined that need to read voltages of 12 wires in total (8 from one of the ribbon cables and 4 from the other one). Since it's a scan matrix, it probably needs to happen reasonably fast. I don't know the voltages in the wires yet. I've skimmed through some tutorials about building a basic voltmeter, but like I wrote, I have very little knowledge when it comes to electronics. I don't have a breadboard, but I do have a bunch of standalone wires that I can put to use (just tie/tape them together for now, I guess).

Do I just slice the ribbon cable in half, connect one part of each wire to the GND on the Arduino and the other part to a different Analog In, and that's it (to close the circuit once again)? Or should the circuit be made differently? The wiring inside is honestly a mess, I don't even know what serves as the ground. Basically, what I want to do is to "cut into" these ribbon cables and read what's coming through them, without breaking the functionality of the toy.

Any advice or general direction will be greatly appreaciated! I don't want to fry the board or break things; I already need to solder some of the wires on the toy back into place because the thing wasn't really built to be disassembled one day.

If you are looking for an ON/OFF signal, then using digital pins would be the solution. As far as for 12 of them, why not use a multiplexer? A high impedance input would prevent loading the source, and the original circuitry handles any floating circuits. You would need to verify what voltage levels you have though.

I'm a little confused when you say it's a mess in there. Usually, ribbon cables make things fairly clean, unless the cable is way too long. It's also not an easy task to hack one apart to splice into it. Is it (8)-single wires in a connector?

Look for an Arduino port extender. That should enable you to interface to the required number of wires.

Do you expect the toy to still work afterwards? It still makes its own noises in addition to MIDI out? Then you'll have to play along with however it is matrixing the keys. If you get to drive the matrix columns, then it's a lot simpler.

I'm a little confused when you say it's a mess in there

I didn't mean the ribbon cable itself, rather how the contents of the Meowsic are organized and packed inside the toy. It's full of duct tape and glue holding everything in place, and the scan matrix handles keyboard keys and buttons for triggering melodies (above the keyboard), but some other buttons are handled elsewhere in the toy.

Since I made the first post above, I wrote to an acquaintance of mine who suggested connecting GND pin to the Minus terminal of the battery unit and the A0 pin to one of the wires in the ribbon cable (as in, "just expose the wire and connect to it, no need to cut it in half"). I did, and got a stream of 0 and 1023 values with a period of about 10 ms or so. I'm not sure if I did everything right, but if I did, then it's probably the scan matrix at work.

For what it's worth, I later experimented with connecting GND to - of a simple AA battery and A0 to + of the same battery, and got a very stable reading of ~ 291 (~1.4V).

As a side note, my Meowsic has an annoying hum that grows louder whenever I touch any of the (plastic) boards inside it, or even the (useless) microphone. What would be the first things to check to get rid of it?

Is it (8)-single wires in a connector?

It's 8 wires, but they don't end with a connector of any kind, these wires are just individually plugged into their sockets (is it the correct English word?) in the board and then coated in transparent glue. Definitely not something that was made for disassembly. When I was trying to figure out the matrix at first (prior to my first post here), I gently removed the layer of glue and pulled some of these wires out, but that left some residue of them in the sockets and now they don't hold into place. I'll solder them back in, I suppose.

Do you expect the toy to still work afterwards? It still makes its own noises in addition to MIDI out? Then you'll have to play along with however it is matrixing the keys. If you get to drive the matrix columns, then it's a lot simpler.

Fair point, and yes, ideally I'd want it to work as a standalone toy too. I've thought about accessing directly those "buttons" under the keys of the keyboard instead of messing with the matrix, but I don't know yet how I feel about that (there are 28 of them, after all).

For the record, decoding the matrix into key numbers isn't an issue at all; it's catching the timing of matrix scans is what seems to be the issue now, from the code POV.

Something I missed at first...

If you are looking for an ON/OFF signal, then using digital pins would be the solution.

Do you mean the PWM pins on the other side of the Uno, across the board from the Analog Ins? I've counted, and there are 6 Digitals there (excluding the ~ Analog ones and RX/TX), which together with 6 Analog Ins form the 12 I need (according to this, they can be used for input as well). If that's the case, then indeed I can route some of the wires to Analog Ins, and some to these pins. It's probably not the most elegant solution, but it would work (I take it that Ground will need to be connected separately for these pins).

0-1023 seems like a digital signal. Actually 1023 is a little high - are you sure the Meowsic is only putting 5V on those wires?

All the pins on the Arduino (except reset and power) can be used as digital inputs. The ~ symbol next to the PWM pins denotes a special output capability. The input circuit behind each pin is identical. The A0-A6 pins have an additional input ability, but all the same can be used as digital inputs.

pinMode(A0, INPUT_PULLUP);

Ah, got it. And yes, I suspected from the start that it would be a digital signal (on/off) transferred along those wires, but I had no idea what voltage it would be. The toy is powered by four 1.5V AA batteries, so it should be about 6V, I suppose.

Right now, the course of action to me seems to be like this:

  1. Solder those wires into place (see photo above) or otherwise attach them reliably where they belong.

  2. Hardware work: split both ribbon cables into standalone wires. Expose the individual wires (keeping them at a distance from each other, perhaps fixing them on a piece of wood or something). Connect each of them to a different pin of the Arduino. Connect only one GND of the Arduino to the Minus of the battery unit (or the GNDs on both sides of the board?).

  3. Software work: poll the pins as fast as possible, or as fast as reasonably sufficient once the period is determined. While column 1 is kept ON (by Meowsic), values from the pins of rows should be interpreted as on/off states of corresponding keys (the ones that are at the intersection of column 1 and this row). When the column switches to 2 (wire of column 1 is off, wire of column 2 is on), values from rows should be interpreted as states of keys at the intersection of col. 2 and these rows. Etc.

Does this sound right?

Eh, I'm back to square one, it seems.

It appears that that situation with 0s and 1023s was a fluke; a badly attached wire, most likely. I'm not able to reproduce it. What is definitely reproduceable, though, is the situation when the individual wires in the ribbon produce an output of ~ 20-30 when the key is not pressed, and above 50-ish (out of 1024) when it is pressed. This is such a small difference that I wrote it off as noise at first, but it's definitely there. However, there are enough false positives and false negatives (I experimented with different thresholds and different amounts of averaged samples) that it's unusable as it is. If Meowsic is indeed sending such a small (and fluctuating!) value along these wires, I don't know how it separates signal from noise. I also wasn't able to pick any periodic activity (scan matrix) in either of the ribbons, no matter how fast I was polling, even though the keyboard continues to function normally.

That, and I managed to accidentally cut a couple wires during my attempts to bare them. They are made of just a few strands of hair-thin wire. Guess I'll be off to try to solder this mess first.

So the Meowsic is fixed and working now, but I'm afraid I need further advice.

For context: with soldering and some external help, the ribbon wires were removed and replaced with regular jumper wires (fairly standard ones I suppose, the ones that fit in breadboards and Arduino itself). The purpose of this was to make each wire easily "disconnectable" - there's a male one coming from one of the internal boards and a female one coming from another one, and they connect in the middle, forming a complete wire.

One of those boards appears to be the "main" one, deciding which sounds to output, and the second one just collects button/key presses and has a scan matrix in it. The main board sends signals along row wires and reads what's coming from columns.


I can now read what's coming through the wires by "inserting" Arduino into the middle of the wire; either with a breadboard or directly. The first half of the wire (coming from the "main" board of the toy) connects to GND on Arduino, and the second half of the wire connects to, say, A0. Now, when I connect Arduino to a wire of a specific row of the matrix, I can clearly see the periodic signal coming through.

However, my issue is this: does it mean that I need 14 Arduinos to sniff 14 voltages inside 14 wires? Arduino doesn't have 14 "ground"s, so I'm at a loss about how to measure 14 voltage differences.

You need one ground as reference for many signals. You might need an Arduino with more than 6 analog
inputs of course. Or an analog multiplexer chip.

Do you have access to an oscilloscope, so you might actually see what you are dealing with?

MarkT:
You might need an Arduino with more than 6 analog
inputs of course. Or an analog multiplexer chip.

The readings I get (by printing them into Serial as a debug mode of sorts) look like this:

0
252
1023
477
0
250
1023
482
0
230
1023
493
0
233
1023
495
0

It's a digital signal, and as mentioned earlier in the thread, Uno has enough pins that can act as digital inputs. The output above was generated with no delay in the loop whatsoever; I expect the code to work faster without the Serial.println() so that peaks would be captured more reliably even if the signal would be read digitally (because of the more forgiving time window). It's late here already, but I plan to test this tomorrow (i.e. by storing some readings in an array without interrupting for serial output and then outputting it all at once).

Or, as suggested by tinman13kup, I should probably borrow an oscilloscope.

In any case,

MarkT:
You need one ground as reference for many signals.

This is my primary problem now. If I connect directly "into" the wire (use one side of it as ground and attach the other to the input pin), I get reliable measurements. But there's no "common ground" for these wires, at least not one that I can find. The ground wire from the battery unit connects to the board that these wires are coming from, I tried to use that as a ground, but it produces near-randomness. The "+" wire from the battery unit goes to the "on/off" switch, from where a multitude of wires go to different boards within the toy, including this board from which these scan matrix wires come from.

Then you need to synthesize your ground with signal diodes - ie the lowest voltage wire defines ground at any point
in time. So long as at least one wire is ground that will work. 1N4148 or schottky diodes would be appropriate
for this.

But much better is to bring out the known ground explicitly...