When I was asked for advice on using optical switches to replace broken switches on a keyboard, I had to admit I had never given it any thought. But as an Ardent Arduino fan, I started thinking how this might be done using my favourite micro-controller.
My initial reaction was to use a brute force approach. All the LEDs would be powered on all the time. The output from each optical switch would connect to to its own digital IO pin. There are 60 such pins, on an Arduino Mega, and since pin 13 is useless for input, two more are needed. But one or more of the Arduino's four serial ports can also be switched to digital IO duty. Problem solved. Some simple code would do the scanning and put out MIDI codes on one of the remaining serial ports.
Not terribly elegant, requiring three Arduinos for one organ, but I'd be interested to know if anyone has actually tried this and whether the result was satisfactory.
Then I started casting around for a more elegant solution. Some experimentation was in order. The optical switches I used were of the HY870P variety consisting of the usual (infra-red) LED illuminating a photo-transistor. First I determined that the dark current is negligible even when the collectors of eight transistors were tied together. Then I determined that 4 of the LEDs wired in series operated happily on 4.67 V, drawing 8 mA. So with an additional 41 ohms in series, the LEDs are 5 V compatible. Eight in a series/parallel configuration could easily be driven by a single Arduino IO pin.
I think you can see where I'm heading with this. It now appeared possible to wire up the optical switches in an 8x8 matrix configuration. Each of the 8 rows of 8 LEDs are wired in the series/parallel configuration described above. Each row can be turned on one row at a time by driving the cathodes low.
Each of the 8 collectors in a column are hard wired together in a wired OR configuration and connected to an input pin. This is now virtually identical to the way 64 mechanical switches are wired in a diode isolated matrix, and in fact, I used the exact same code to scan this configuration.
But there was a problem! The scan totally missed the key I was pressing and instead gave me the codes for three notes exactly 8 notes apart. Some pondering led me to the conclusion that the Arduino scan was simply much too fast to take into account the latency and persistence of the LEDs. The solution was simple. After turning on a row of LEDs, introduce a very short delay to not only let the current row of LEDs achieve full brightness but to let the previous row wink out. With the addition of this one line of code, my small scale experimental setup functioned just fine.
Again, I'd be very interested to know if someone has tried a full scale version of this or whether I've missed some crucial point. Please reply if you have.
The fact that the note gets turned on when the light path is unblocked might be difficult to arrange mechanically, especially if the optical switches are to be mounted under the keys. But then that might be a poor location in any case since control of ambient light would be important and having direct sunlight falling on the keys might give some interesting results. A better solution is possible if the key is extended at the back so that the tail pivots up when the front of the key is pushed down.
John
My initial reaction was to use a brute force approach. All the LEDs would be powered on all the time. The output from each optical switch would connect to to its own digital IO pin. There are 60 such pins, on an Arduino Mega, and since pin 13 is useless for input, two more are needed. But one or more of the Arduino's four serial ports can also be switched to digital IO duty. Problem solved. Some simple code would do the scanning and put out MIDI codes on one of the remaining serial ports.
Not terribly elegant, requiring three Arduinos for one organ, but I'd be interested to know if anyone has actually tried this and whether the result was satisfactory.
Then I started casting around for a more elegant solution. Some experimentation was in order. The optical switches I used were of the HY870P variety consisting of the usual (infra-red) LED illuminating a photo-transistor. First I determined that the dark current is negligible even when the collectors of eight transistors were tied together. Then I determined that 4 of the LEDs wired in series operated happily on 4.67 V, drawing 8 mA. So with an additional 41 ohms in series, the LEDs are 5 V compatible. Eight in a series/parallel configuration could easily be driven by a single Arduino IO pin.
I think you can see where I'm heading with this. It now appeared possible to wire up the optical switches in an 8x8 matrix configuration. Each of the 8 rows of 8 LEDs are wired in the series/parallel configuration described above. Each row can be turned on one row at a time by driving the cathodes low.
Each of the 8 collectors in a column are hard wired together in a wired OR configuration and connected to an input pin. This is now virtually identical to the way 64 mechanical switches are wired in a diode isolated matrix, and in fact, I used the exact same code to scan this configuration.
But there was a problem! The scan totally missed the key I was pressing and instead gave me the codes for three notes exactly 8 notes apart. Some pondering led me to the conclusion that the Arduino scan was simply much too fast to take into account the latency and persistence of the LEDs. The solution was simple. After turning on a row of LEDs, introduce a very short delay to not only let the current row of LEDs achieve full brightness but to let the previous row wink out. With the addition of this one line of code, my small scale experimental setup functioned just fine.
Again, I'd be very interested to know if someone has tried a full scale version of this or whether I've missed some crucial point. Please reply if you have.
The fact that the note gets turned on when the light path is unblocked might be difficult to arrange mechanically, especially if the optical switches are to be mounted under the keys. But then that might be a poor location in any case since control of ambient light would be important and having direct sunlight falling on the keys might give some interesting results. A better solution is possible if the key is extended at the back so that the tail pivots up when the front of the key is pushed down.
John