Search:
Submit Search


Arduino + Optical Switches?

Building organ consoles for use with Hauptwerk, adding MIDI to existing consoles, obtaining parts, ...

Arduino + Optical Switches?

Postby Coenraads » Mon Feb 11, 2019 11:00 pm

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
Coenraads
Member
 
Posts: 11
Joined: Fri Feb 01, 2019 11:13 pm

Re: Arduino + Optical Switches?

Postby johnh » Mon Feb 11, 2019 11:24 pm

In all the optical switching implementations I've seen the movement of the key interrupts the beam between the emitter and the detector...
User avatar
johnh
Member
 
Posts: 696
Joined: Sat Mar 15, 2003 7:51 pm
Location: Monterey Bay Area of California

Re: Arduino + Optical Switches?

Postby GrahamH » Tue Feb 12, 2019 5:56 am

Hello John
I have used opto-switches on pedal boards and on both types of keyboard - not with Arduinos, but in 8x8 matrix arrangements with Midiboutique HWce2x.encoders.
You may find this document useful:
https://www.dropbox.com/s/989knkoy50zj3b8/Opto-switch%20experiments.zip?dl=0

Mounting optical switches below the keys is a bit more fiddly but, depending on the design of keyboard, it is possible and works well.
If you send me a PM with your email address I will send you some photos - though I'm afraid taking decent photos proved more difficult than fitting the opto-switches.
Graham
GrahamH
Member
 
Posts: 527
Joined: Tue Sep 09, 2008 7:39 am
Location: Near Manchester, England

Re: Arduino + Optical Switches?

Postby murph » Tue Feb 12, 2019 5:53 pm

I've just ordered 10 small optos to try a combinaton of John and Grahams approaches. I'll report back when I get around to it. (They come in tubes of 100 @ €25 from RS!!!!).

This could mean 4 manuals optically sensed for €150 including Arduinos/diodes etc......
murph
Member
 
Posts: 552
Joined: Fri Mar 02, 2012 6:45 pm

Re: Arduino + Optical Switches?

Postby Coenraads » Tue Feb 12, 2019 8:17 pm

Thank you John for your observation that interrupting the the light beam normally should trigger a turn-on event. I recently built some racks of switches for the organ in Victoria's Christ Church Cathedral. It's a tracker but some of the bass pipes are on offset electro pneumatic chests. They are triggered by air switches mounted above the channels. The switches were failing so I designed a switch where air flow blows a small pivoting piece of aluminum out of the gap in an optical interrupter, triggering the pipe. So this breaks the rule. The chamber lights don't cause any spurious triggering and normally they are off anyway. But it doesn't mean I don't have reservations about my optical switch matrix arrangement. With 8 collectors tied together this will only magnify any ambient light problem. Only if the switches were mounted at the tails of the keys and protected by a black painted housing would I be comfortable recommending this otherwise elegant approach.

And Graham, thank you for your offer. I'll keep you in mind should I ever end up building an optically switched keyboard.

Good luck with your project Murph, and keep us posted. The more I think about the brute force approach, the more I believe that it is the better approach even though it requires one Arduino per keyboard. Powering up all 61 LEDs all the time can be accomplished with a simple 12V power supply. Eight LEDs in series with an additional 330 ohm resistor operate happily on 12V drawing only 8 mA. So only 64 mA is needed in total for one keyboard. I'll try to find time to write and test the required code in the next few days. I think the Arduino has 61 digital pins available. And this time, interrupting the beam will trigger a turn-on note event and I think ambient light will no longer be a potential problem. And Murph, you mention diodes. In neither approach, matrixes or straight, are any diodes needed.

When this is done, I will post a link to the code here.

John
Coenraads
Member
 
Posts: 11
Joined: Fri Feb 01, 2019 11:13 pm

Re: Arduino + Optical Switches?

Postby murph » Tue Feb 12, 2019 8:30 pm

Hi John,
have a close look at Grahams plans. Just scanning the opto-transistors (which DOES involve diodes) in a matrix, while permanently powering the LED's works. I'll report back.
As I said, joining brains can be good. (Sharing common space, though........)

Tony.
murph
Member
 
Posts: 552
Joined: Fri Mar 02, 2012 6:45 pm

Re: Arduino + Optical Switches?

Postby murph » Tue Feb 12, 2019 8:42 pm

murph wrote:Hi John,
have a close look at Grahams plans. Just scanning the opto-transistors (which DOES involve diodes) in a matrix, while permanently powering the LED's works. I'll report back.
As I said, joining brains can be good. (Sharing common space, though........)

Tony.



P.s. The reason for the diodes in the matrix transistor array is that they are permanently lighted, thus conducting.
You keep thinking in terms of them only being illuminated when the SELECTED row is scanned. That is not true, in this instance.
Different courses.... etc.

P.p.s.
However, a COMBINATION of your and Grahams methods should achieve much better price/performance results than anything available at the moment.
murph
Member
 
Posts: 552
Joined: Fri Mar 02, 2012 6:45 pm

Re: Arduino + Optical Switches?

Postby TheOrganDoc » Tue Feb 12, 2019 9:27 pm

Hello all,
I have been utilizing IR-Darlington switches on my Melitzer, (two manual Wurli console) although I am using the Artisan-organs-midi-encoder (Paralell switching {61 notes} system). I designed a 12 note PC Board and had a bunch made. I have two 32 note sets under each pedal, one set for bass keying, and the second set with diode isolation to trigger the Piano Sustain through midi ! (Works well except when using heel and toe keying !

For the keyboards I used smaller opto's, using "two" optos under each key, the second of which is set deeper, for use as second touch, and or for " Sampled Piano Touch Control".

This setup has been performing flawlessly for almost eight years ! I used the original brass contact plates, slightly modified, with their silver bars removed, "as shutters" ! I couldn't be happier with this reliable system :D .
Thank you, for the confirming post's.
(The original silver contacts were not reliable, when used in low voltage and current, electronic switching systems.)

PS, I was told by one of our midi PC builders that my darlington opto outputs exibit the usual ".5 volt Low output" that could cause problems, But I have yet to have this problem here !
Best wishes, Mel
Mel..............TheOrganDoc...............
User avatar
TheOrganDoc
Member
 
Posts: 769
Joined: Sun Sep 19, 2004 11:13 pm
Location: South East, Florida, USA

Re: Arduino + Optical Switches?

Postby Coenraads » Tue Feb 12, 2019 11:12 pm

Thank you Tony for your helpful comments. When I said no diodes were needed, I was strictly referring to my two designs: the brute force approach, one wire per switch to 61 pins on one Arduino, and the 8x8 matrix of optical switches. I hadn't yet seen Graham's circuit because a) my iPad wouldn't open the file, and b) my MacBookPro died last week. So I dusted off my very old PC and had a look. Graham's solution is very clever, and, in retrospect, so obvious. So why didn't I think of that? That's why we have the forum.

Yes, Graham's circuitry should be completely compatible with my Arduino Mega scan program. Take a look at my Galanti project. The Arduino Mega scans the two manuals and it would be easy to add the code for the pedal and pistons. The only reason I put that on an Arduino Uno, was because I was trying to solve a problem due to interference on a common data bus. You'll find the code here. And the heavy duty debouncing should not be necessary. The debounceCount can safely be reduced to 2 or 3. Oh, and one other important detail, assuming Graham intends to turn a note on by interrupting the beam as opposed to unblocking the beam, then the calls to the turnNoteOn and turnNoteOff procedures needs to be reversed.

https://sites.google.com/site/casavantopus400/

However, I will still proceed with coding my brute force, 61 lines to 61 pins approach. For some people, the conceptual simplicity of it will be attractive. I'll also include code so that the program will merge its output with that of another, daisy chained, Arduino.

Again, my thanks to all participating in this discussion.
John
Coenraads
Member
 
Posts: 11
Joined: Fri Feb 01, 2019 11:13 pm

Re: Arduino + Optical Switches?

Postby GrahamH » Wed Feb 13, 2019 5:11 am

Oh, and one other important detail, assuming Graham intends to turn a note on by interrupting the beam as opposed to unblocking the beam, then the calls to the turnNoteOn and turnNoteOff procedures needs to be reversed.


Because I was using bog-standard Midiboutique encoders I needed to go for a 'shutter open/beam unblocked = note-on' arrangement which necessitated an 'L' shaped shutter that travelled beyond the photo-interrupter's slot.
If space is limited with under-keyboard switches, a 'shutter closed/beam interrupted = note-on' arrangement would probably be more practical - and if you are programming your own encoders you can of course arrange this.

Regarding ambient light, when I was doing the initial experiments on the work-bench in my conservatory on a bright sunny day I encountered real problems, but once the opto-switches were in place under the keyboards I had no further problems.
I did, however, find that the shutter material was critical. For example, white plastic appeared to be transparent to infra-red whereas the same plastic painted black worked OK. I was told that it wasn't actually a case of the plastic's being transparent to IR, but rather, it was IR 'spillage' due to the white material scattering the IR.

Graham
GrahamH
Member
 
Posts: 527
Joined: Tue Sep 09, 2008 7:39 am
Location: Near Manchester, England

Re: Arduino + Optical Switches?

Postby NickNelson » Wed Feb 13, 2019 6:12 am

GrahamH wrote:I did, however, find that the shutter material was critical. For example, white plastic appeared to be transparent to infra-red whereas the same plastic painted black worked OK.


I use a home made laminate of two sheets of matt black card with a layer of heavy duty aluminium foil between them. The layers are stuck together with spray-on photo mount adhesive. The result is easy to cut, but quite stiff, absolutely opaque to IR (so far as I can tell) and can be stuck to the key tails with ordinary PVA glue.

Image

Nick
User avatar
NickNelson
Member
 
Posts: 759
Joined: Tue Dec 20, 2005 11:31 am
Location: Leeds, UK


Return to DIY organ consoles / MIDI

Who is online

Users browsing this forum: No registered users and 4 guests