It is currently Sun Dec 15, 2019 11:07 pm


Arduino + Optical Switches?

Building organ consoles for use with Hauptwerk, adding MIDI to existing consoles, obtaining parts, ...
  • Author
  • Message
Offline

Coenraads

Member

  • Posts: 32
  • Joined: Fri Feb 01, 2019 11:13 pm

Arduino + Optical Switches?

PostMon 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
Offline
User avatar

johnh

Member

  • Posts: 696
  • Joined: Sat Mar 15, 2003 7:51 pm
  • Location: Monterey Bay Area of California

Re: Arduino + Optical Switches?

PostMon 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...
Offline

GrahamH

Member

  • Posts: 546
  • Joined: Tue Sep 09, 2008 7:39 am
  • Location: Near Manchester, England

Re: Arduino + Optical Switches?

PostTue 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
Offline

murph

Member

  • Posts: 610
  • Joined: Fri Mar 02, 2012 6:45 pm

Re: Arduino + Optical Switches?

PostTue 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......
Offline

Coenraads

Member

  • Posts: 32
  • Joined: Fri Feb 01, 2019 11:13 pm

Re: Arduino + Optical Switches?

PostTue 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
Offline

murph

Member

  • Posts: 610
  • Joined: Fri Mar 02, 2012 6:45 pm

Re: Arduino + Optical Switches?

PostTue 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.
Offline

murph

Member

  • Posts: 610
  • Joined: Fri Mar 02, 2012 6:45 pm

Re: Arduino + Optical Switches?

PostTue 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.
Offline
User avatar

TheOrganDoc

Member

  • Posts: 788
  • Joined: Sun Sep 19, 2004 11:13 pm
  • Location: South East, Florida, USA

Re: Arduino + Optical Switches?

PostTue 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...............
Offline

Coenraads

Member

  • Posts: 32
  • Joined: Fri Feb 01, 2019 11:13 pm

Re: Arduino + Optical Switches?

PostTue 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
Offline

GrahamH

Member

  • Posts: 546
  • Joined: Tue Sep 09, 2008 7:39 am
  • Location: Near Manchester, England

Re: Arduino + Optical Switches?

PostWed 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
Offline
User avatar

NickNelson

Member

  • Posts: 789
  • Joined: Tue Dec 20, 2005 11:31 am
  • Location: Leeds, UK

Re: Arduino + Optical Switches?

PostWed 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
Offline
User avatar

TheOrganDoc

Member

  • Posts: 788
  • Joined: Sun Sep 19, 2004 11:13 pm
  • Location: South East, Florida, USA

Re: Arduino + Optical Switches?

PostMon Feb 18, 2019 5:22 pm

I was told last year by a well known Midi Encoder builder, that the, "opto transistor junctions" are effectively "diode junctions" when not conducting, Therefore isolating diodes are not needed, and the extra 1/2 volt drop affects having a low, (Note Off) input of 1 volt could result in your encoders Missing Low level inputs !, If you differ in this opinion, please explain, Thank you , Mel- (TheOrganDoc) ! Since my Opto system runs parallel inputs (61 per keyboard),
[ I do not have the scanning, Isolation problem at this time ! ]

Coenraads wrote: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
Mel..............TheOrganDoc...............
Offline

Coenraads

Member

  • Posts: 32
  • Joined: Fri Feb 01, 2019 11:13 pm

Re: Arduino + Optical Switches?

PostMon Feb 18, 2019 7:41 pm

The question of levels is one I had not given much thought. As a hobbyist, if it works I walk away smiling and I treat the opto transistor pretty much as a simple switch. If I were a developer of a commercial product, questions such as this would keep me awake at night since my reputation would be on the line.

I can only speak to the characteristics of the HY870P optical switch and the IO pins on an Arduino. Arduino specs say that anything below 1.5 volts is low and anything above 3.0 volts is high.

Time to haul out an Arduino and make some measurements.
I hooked up a potentiometer to the input pin and watched a note turn on and off on my organ app. At 2.2 volts the note turned on and at 2.5 volts it turned off. So the band of uncertainty is only 0.3 volts, quite different from the very conservative 1.5 volts in the Arduino specs.

Next I connected an optical switch. The LED was supplied with only a modest 8 mA. With the light blocked, the input pin rose to a solid 4.9 volts. Unblocked, the voltage dropped to 0.10 volts which is very comfortable. So what happens if you connect a diode in series? This time the unblocked voltage read 0.53 volts which I think is still pretty safe.

If the optical switches are to be arranged in the usual 8x8 matrix, the optical switches must have isolating diodes. If the switches are parallel wired, each has its own input and isolating diodes are unnecessary. And I gather that is the case with your organ.

If I were doing a keyboard with optical switches, I would go for parallel wiring. See my more recent post on that topic. Optical switches should be compatible with the code I'm using there. And, I believe, that simply swapping the names of the turnNoteON procedure with the turnNoteOFF procedure, you can reverse whether blocking the beam turns the the not on or off. Correct me if I'm missing something.
John
Offline
User avatar

NickNelson

Member

  • Posts: 789
  • Joined: Tue Dec 20, 2005 11:31 am
  • Location: Leeds, UK

Re: Arduino + Optical Switches?

PostTue Feb 19, 2019 7:29 am

Having worked quite a lot with both encoder design and optical switching there a few observations / considerations I have to offer.

Optical switches, while logically like mechanical swithches, are in reality very different. The main point of difference is that a mechanical switch is basically either on or off, though it may go through several cycles of this which is why de-bouncing is generally necessary, and the transition between the two states is very fast. Optical switches on the other hand take time to switch on and especially to switch off. This is generally due to capacitance at the base of the opto-transistor (and opto-darlingtons are worse still). Unless driven quite hard (5mA collector current for example) they may take several hundred uS to switch. This probably doesn't matter much where each line is monitored individually, but in matrix arrangements the switch-off time delay can be a real killer.

The problem is that the designer has to allow sufficient 'settling' time between switching from one bank of sensors to another and reading the states of the new bank of sensors. I would always aim to scan an entire 10x8 matrix (ie 61 keys and 16 pistons) within 2 mS and this can be achieved quite readily with careful design of the sensor circuitry.

I used to worry quite a lot about optimising the code for speed of execution. This is why I have always used assembly language for the purpose, as it gives you exact and absolute control over the timing of every event. More recently I have begun to realise that in reality the microcontrollers spend more time doing nothing, while waiting for the sensors to settle, than they spend actually detecting events and generating the necessary responses.

Personally, I always use a matrix to scan keyboards, pistons and stops since the amount of wiring is so much less, and a small, cheap microcontroller can do an awful lot of work. As an example, while there is nothing wrong, as such, in using 64 lines from a microcontroller to encode an organ manual, and I agree that the conceptual simplicity has some appeal, but those 64 lines in a 32x32 matrix arrangement could monitor 1024 switches. This is much more than sufficient to deal with all the key and pedal contacts, pistons, stops and couplers for a very large 5 division console. There would be a considerable additional advantage in that the merging of the MIDI traffic could be done internally and at relatively very high speed compared to a sequence of separate encoders in a MIDI chain.

Nick
Offline

ARoss

Member

  • Posts: 3
  • Joined: Sun Sep 20, 2009 7:06 pm

Re: Arduino + Optical Switches?

PostSun Mar 24, 2019 7:36 pm

Fairly new around here. Thank you everyone, this thread has answered so many of my questions this week! Special thanks to those who have posted photos!!

I've already converted an old EP console which still has its exposed silver contacts and I'm trying to plan out what to do now that I'm thoroughly frustrated with how well that's working at 5v (not well). Initially I was thinking about magnetic reed switches but some other threads on this forum helped me realize the disadvantages of that. Opto seemed the way to go but I wasn't sure I wanted to sink that much time in just yet (Also frustrating to find opto switches in bulk). So I started looking into keeping a similar system to what is in there now. I admit I am surprised no one sells gold-plated key wipers specifically designed for low voltages. Gold clad wire also seems to be a bit difficult to come by and I'm guessing at the end of the day it will end up being as expensive or more than opto.

I guess opto is looking like the best option after all. Bonus: it'll even get rid of the "kwitch kwitch" sound.

Alex.
Next

Return to DIY organ consoles / MIDI

Who is online

Users browsing this forum: No registered users and 2 guests