Arduino Forum

Using Arduino => Audio => Topic started by: Macola on Oct 23, 2017, 09:41 pm

Title: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Oct 23, 2017, 09:41 pm
My M-audio keystation 61 midi keyboard stopped working and the culprit is on microcontroller which is responsible, among other things for usb connection. That chip costs 1$ but I've been told that the original code is protected and can't be find and the whole original pcb replacement is to costly. The whole circuitry is very simple: there are 2 chips, first one (W78E052DDG) is connected to all of the keys matrix and their velocity calc (24 input pins). Then the result is sent to another chip (micro controller C8051F320) via 14 pin jack, which is doing USB/midi communication.

It should be fairly easy to replace second pcb with arduino considering that it gets sorted out signal from keyboard velocity chip? Right?

Or maybe to replace both chips and connect 24 pins matrix directly to arduino?
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Oct 24, 2017, 12:06 am
Quote
Right?
If you say so but I doubt it. Many of those custom chips have hardware built into them that the Arduino dosn't.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: DVDdoug on Oct 24, 2017, 12:27 am
It might be possible, but if you've never made a MIDI project before, I'd recommend building a simple test/experiment project first...   Maybe something that sends a couple of MIDI notes/commands with little or no user input.

Quote
It should be fairly easy to replace second pcb with arduino considering that it gets sorted out signal from keyboard velocity chip? Right?
"Sorting out" those signals could be tricky, especially considering that the keys are velocity-sensitive.  (It's not a simple "digital" matrix.)

It should be possible to replace all of the electronics, but you'll have to multiplex the (analog) key-inputs in order to get enough inputs.

I wouldn't say wiring-up 61-keys (and other controls?) and everything would be "easy", especially if you don't make a custom PC board or two.   And, then there's the programming.    By the time you're done you'll have lots of hours into this thing and it might not be as good as the original, and you may put more money into it that you anticipate.   So, I'd recommend you only do this if you're doing it for fun, or if you want to add some features/functions that you can't find in a commercial keyboard.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Oct 24, 2017, 08:58 am
Thanks for the replies. I am aware of the things you've said. I am not an expert in this area and the things would easily get tricky at some point. On the other hand there are many diy project on line to make a midi keyboard out of any cheap non usb/midi keyboard just by adding some electronics. I don't have an intention to restore all the original functions, which are not many in this case anyway. Just to make keyboard basically work connected to pc via usb. And, yes it would be a joy project.

Many people recommend arduino as there are available libraries. Surprisingly, there are also many specialized chips (with free open code) exactly for this purpose - to make midi keyboard out of any old keyboard. For example E510 - 128 keys velocity sensitive keyboard scanner. So I thought it would be worth giving it a shot. It's just that atm I lack experience.

I this case of mine both chips are just simple general purpose microcontrollers similar to the arduino ones. One is doing keyboard scanning/multiplexing the other has usb controller. Each cost 1$. The problem is the code in them. It's proprietary.

This, for example, looks pretty straightforward: http://www.geocities.ws/JDPetkov/Hardware/mkcv96/mkcv96.htm

Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Oct 24, 2017, 09:07 am
OK that is fine as long as those are your expectations.
The most common way for a velocity sensitive keyboard is to have two switch contacts per key. When a key is pressed first one contact is broken and then the other one is made. The time between make and break is the velocity data.

The complication arises because you are trying to measure the time of multiple contact changes at the same time.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Oct 27, 2017, 04:56 pm
I took apart my keyboard and realized the type of matrix and velocity. Classic matrix and the velocity is double switches per key but both getting contact when pressed just in a slightly different time depending on velocity/force.

Also found a guy who did exactly what I want - connected key matrix of broken keyboard (same type matrix) to arduino. He actually has connected flat cable of the keys directly to arduino mega cuz it has sufficient input pins. As far as I can see on the pic he has even physically connected it directly w/o any additional cables/adapters.

And the code is exactly for velocity keyboards. How cool is that.

I am not sure if it's legit to link that here?
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Oct 27, 2017, 11:35 pm
Quote
I am not sure if it's legit to link that here?
If it is on the internet then you can link it.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Nov 29, 2017, 09:33 am
Ok, I am a bit late cuz I wanted to give it some try first, and I did.

The project I was referring to is: https:

I managed to make my mega act as USB MIDI instrument by burning special firmware in, but the above sketch is not working.

Then, I tried an example midi library that comes with arduino IDE and that works! It generates sequence of midi notes and all the PC audio software plays it.

So it's about the sketch OR me not connecting pins right. I did check keyboards flat cable connectors with a multi meter and the situation is pretty clear. There are 8 x (8x2) matrix. The 8x2 is cuz double switches for velocity. Tbh, I didn't connect whole matrix but just some keys, but that should work? I didn't change pins in the sketch just connected the key according to the original code. Nothing happens when I press that key. Shouldn't there be an event if any row/column combination is switched on?

Another thing, there is a thick black wire. That is a ground? Tried to connect it to ground pin on digital pins row but no change.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 01, 2017, 07:10 pm
Anyone?

Should I paste the code here?
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Dec 01, 2017, 08:32 pm
Quote
The project I was referring to is: https://github.com/oxesoft/keyboardscanner
It is not very detailed is it? Without a schematic it is hard to know what is going on.

I would forget that code for the moment and concentrate on testing if you can get the key switches to be read. So forget about the MIDI and the scanning of all the keys and just concentrate on one key. Write a bit of simple code to do that and use Serial.print at a standard speed to send stuff out to the console so that you know you are detecting stuff.

Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 02, 2017, 02:12 pm
Exactly my thoughts! Build it up gradually. I did, already, the basic test of detecting pins by using example sketch in the DIO2 library (it's the included library in that project that makes the use of pins easier and supposedly speed it up). That code uses Serial.print ant it works. When each pin is connected to ground I can read them on serial monitor.

What I've noticed as a potential problem is that it may be reverse input - output pins. In the scanner code it's 16(8x2)input pins x 8 output pins, BUT by the orientation of keyboard diodes it should be other way around? Does that make sense?  EDIT: scratch this paragraph, it's the way it should be

I tried to reverse pins on one key but no luck.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 03, 2017, 02:24 pm
Ok this is getting seriously weird. Let me just show you, cuz you need to see it to believe it:

https://www.youtube.com/watch?v=6h_6V134Ty0

I've got me an air piano!

Now seriously, what the heck!? Why so much induction? At first I thought there is some mechanical failure with the pins, but then realized that I don't even need to touch it to play a sound. Especially when I connect a wire to just one pin it gets overloaded and plays a bunch of notes.

My guess there is something oscillating to fast. Looping fast or something?

On the bright side it seems that I get it to work kinda. Just need to calm it down.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Dec 03, 2017, 02:54 pm
Quote
Now seriously, what the heck!?
This is normal. It is known as a floating input see this http://www.thebox.myzen.co.uk/Tutorial/Inputs.html (http://www.thebox.myzen.co.uk/Tutorial/Inputs.html)

Can you draw a schematic of what you think the project might be.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 03, 2017, 08:54 pm
The sketch I used when I've got the strange behavior is other than the one I originally posted about. This one uses demultiplexers like most of other project, so I just tried to make it work with no demiltiplexers code and got that.

So I am back to the project that suppose to be right the stuff that I need, cuz it's for the velocity matrix keyboard and for arduino mega. But it refuses to work. I actually bought the mega just because I've saw that project.


Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Dec 03, 2017, 11:55 pm
Sorry but the code means little without a schematic.

You first have to verify the hardware before delving into driving it otherwise you don't know if the problem is hardware or software.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: MarkT on Dec 04, 2017, 03:22 am
Ok this is getting seriously weird. Let me just show you, cuz you need to see it to believe it:

https://www.youtube.com/watch?v=6h_6V134Ty0

I've got me an air piano!

Now seriously, what the heck!? Why so much induction?
CMOS inputs are usually extremely high impedance (10^10 ohms or greater), so they simply sniff the
surrounding electric fields like a sensitive electroscope (induction is magnetic, that's something else).

In a finished project you should avoid leaving any inputs floating (you can set pins to INPUT_PULLUP).
This is especially important for micro-power circuits as a single floating pin can draw many mA of
current from the supply, whereas a non-floating input pulls millions of times less power.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 04, 2017, 08:58 am
@Mike
Here you go. It's like this one, just 8x8 not 8x6.

https://www.dropbox.com/s/gb145pdk8eumwpo/2017-12-03_152940.jpg?dl=0

@Mark
Not quite sure cuz it was long time a go but induction can be electric, magnetic and electromagnetic. No? Doesn't really matter. The funny thing is that it happened on the output pins. Tbh I did butchered someones code so have no clue what actually happened.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Dec 04, 2017, 01:09 pm
You are not getting this are you. I need a schematic of your system, not part of your system, not something like your system but what you actually have.

And posted here not off site.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 04, 2017, 09:25 pm
(http://i66.tinypic.com/2lk35v7.jpg)

This evening I will try to put a resistor just to figure out where.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Dec 05, 2017, 03:47 pm
D22 and D24 both need pull down resistors, otherwise they will float when the key is not made.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 07, 2017, 09:10 pm
When I inspected original keyboard electronics I saw that 8 rows of output pins are connected to Vcc trough 10k resistors. That means that the keyboard is pull-up configured? I was, also, puzzled by columns being connected both to first IC and pass trough to second MC until I read an excellent article about using a latch IC: http://www.openmusiclabs.com/learning/digital/input-scanning-matrix/latch-mux/index.html . That made all much more clear.

I've got back to my arduino project and made small progress after connected pair of input pins to ground at the same time. There was an signal to midi yet random one. (bringing them from floating to zero?). Does that mean that the project code is meant for pull down configuration and must be changed?

Also, only way to get a response over keyboard is to reverse column/rows. I didn't noticed that before cuz the code is written for velocity only, meaning it must be both key switches pressed at short time to get an output. So how to reverse when "input" has single pin per key and "output" is in pairs? Well I used a trick. I connected to two different keys pressing them at the same time. That makes keyboard to finally give some signal, but same random data appears. Even when I put resistors to either pull-down or pull up configuration. Altho, the pull-up configuration gives much more stable result. Data is less random, I should say, but still not as should be.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 08, 2017, 09:05 am
So I must use reversed connection to keyboard with a two keys pressing trick. When I look at serial monitor (firmware enable switching between serial and USB-midi) I get this:

(http://i67.tinypic.com/9r4lkl.jpg)

Which seems right.

But when I switch to USB-midi output I get this in MIDI-OX software:

(http://i68.tinypic.com/2rxz2ty.jpg)

When I debug over serial midi driver I get this:

(http://i63.tinypic.com/jrsj6e.jpg)

As if serial driver and USB-midi driver are expecting long midi command and getting short 3 byte one?

Any thoughts?
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 08, 2017, 02:00 pm
.
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 08, 2017, 03:23 pm
And this is the schematic of the circuit that actually works:

(http://i67.tinypic.com/2nby7x1.jpg)
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Grumpy_Mike on Dec 09, 2017, 02:42 pm
Quote
Only issue I need to resolve now is how to reverse keyboard matrix, as it only works the wrong way.
I have no idea what this means. Why is it the wrong way?

Quote
Even when I put resistors to either pull-down or pull up configuration.
How do you do that? The Arduino has no pull-down configuration.

I keep telling you we need to see a full schematic, you keep not posting one. Why should I bother to help if you will not cooperate?
Title: Re: Replace chip (PCB) in usb midi keyboard with arduino
Post by: Macola on Dec 09, 2017, 07:12 pm
Apparently my ability to express what am I doing is poor.

Also, apparently, my ability to resolve software and hardware problems is high. I never used C++ in my life, nevertheless managed to fully understand the code I was using and make necessary changes to it and to hardware configuration too, and make it fully work.

Due to poor interest for this topic I don't feel I should bother anyone with an explanation what I actually did to make it work.

Kind Regards