I want to read the individual positions of four 12-position analogue rotary switches with as few control lines to the arduino Uno as possible. I am therefore looking for a digital chip that will read sequentially the state of each of these rotary switches and return the condition to the arduino software program. The Rotary switches will have a range of resistor values that the chip will need to pass to the software. I'm assuming the program (I haven't written it yet) will request the output state of the digital switch which will return the state (i.e resistor value) of rotary switch 1, and then advance itself (or be advanced from an arduino control line) to point at the next rotary switch 2 in preparation for the next program call to the chip output state.
Because I wish to minimise the number of digital pins used (most of them being used for other functions) - it would be good to find a chip that automatically cycles through its switch options automatically on having its output pin read - or something like this. I think this is called Event-driven switching.
Therefore the question is - I need pointing in the direction of digital chips that could do this job - just need some possible chip names for me to investigate. The chip needs at least 4 input switch pins but of course can be greater than 4 - I will just cycle through the redundant ones in software.
Being a digital novice, I'm also open to suggestions if forum members think I am going about this the wrong way.
There is no such chip.
But why do you need one, this is something you can do with an arduino,in fact it is exactly the sort of thing the arduino, and other embedded processors were designed to do.
However from your description it is difficult to say what exactly you want to do.
What exactly is a 12 position analogue rotary switch?
I want to read the individual positions of four 12-position analogue rotary switches with as few control lines to the arduino Uno as possible. I am therefore looking for a digital chip that will read sequentially the state of each of these rotary switches and return the condition to the arduino software program.
This is the sort of job that microcontrollers are used for. In other words you need another Arduino...!
To explain further: my digital lines on the arduino are being used to control a 24 x 6 matrix LED array. This array will show the fret positions on a guitar fretboard according to different key, scale, mode types. This uses 4 x 74HC595 shift registers (this is modified from an Arduino Forum project - 48x8 Scrolling Matrix LED Display). I have successfully set up a 16 position keypad and LCD display that uses just 3 of the analogue inputs with 1 analogue input controlling the keypad through cascaded resistor values (this was gained again from another Arduino forum project). This works, although with the matrix membrane keypad, the resistance values were often not read properly - and every time I wanted to change anything, I needed to go through the whole procedure of choosing key, scale, mode, etc.
So instead, I though about using a series of rotary switches with each dedicated to one of: key, accidental, scale, mode. Then not only would the fretboard remain as set last time - but I could individually change the variables. Each rotary switch would have a range of different value resistors on the 12 peripheral contacts that could be read by individual analogue inputs. The program using “analogRead” then just runs through the analogue inputs and using a common nested “IF” loop sets up the LED array accordingly. Now I could just use 4 analogue inputs if I did away with the LCD display (which needs 2 analogue inputs). But I just wondered whether there was “out there” a chip that would cycle through the analogue values from the rotary switches (either automatically when the output line from the chip was read - or via a control line that advanced the chip to read another input).
But I just wondered whether there was “out there” a chip that would cycle through the analogue values from the rotary switches (either automatically when the output line from the chip was read - or via a control line that advanced the chip to read another input).
Each rotary switch would have a range of different value resistors on the 12 peripheral contacts that could be read by individual analogue inputs.
Yes you can do that, there are several methods but the simplest is a chain of all the same values and the wiper of the switch goes to the analogue input.
Like what - bad link.
Well in fact no anyway that is not what is being asked.
Maybe you can try explaining then what is wanted as the way I read it is the OP has 3x 12 position rotary switches that they want to know the position of. They intend to used a resistor array off each contact connected to a analogue input so they can read the 12 positions per rotary switch with a single analogue pin (3 pins needed). Using a port expander they can dispense with the resistors and read all three switches using 2 analogue pins (SCL & SDA).
Thanks for the replies - I’m learning a lot.
What I think I will do is just use Analogue pins A4,A5 as SDA,SCL to control the LCD display and allocate A0-A3 to each rotary switch individually. If I subsequently need more analogue inputs, I can dispense with the LCD display, which while a necessity when using the keypad becomes a luxury with labelled rotary switches.
The 24 x 6 LED matrix uses Digital Pins 2-7, and I only need a maximum of 7 of each of the rotary switch positions - I mentioned 12 position rotary switches because I already had them in my spares box and it would allow me to increase the options to include different tunings and exotic scales. Currently the requirements on each rotary switch are:
Switch 1- Key (A,B,C,D,E,F,G); Switch 2 - Accidentals (sharp, flat); Switch 3 - Scale (Major, Minor, Major Pentatonic, Minor Pentatonic, Blues scale); Switch 4 - Mode (Aeolian, Locrian, Ionian, Dorian, Phrygian, Lydian, Mixolydian).
The question to you guys is: could I use two 74HC150 16-line-to-1-line multiplexers (I’m gaining this information from page 654 of Practical Electronics for Inventors - Paul Scherz) to read the rotary switches - each rotary position then being either 0 volts (not connected to the rotary output pin) or 5v (connected to output pin) to supply the digital 0 or 1 to the 74HC150 input pins - (or vice-versa - depends on whether I choose a pullup or pulldown resistor circuit).
This all seems to be getting a bit complicated - and I probably won’t go down this route - but its interesting to explore these alternatives and you guys evidently know a lot more about this than I do - and the only way I will learn is by asking. So is the alternative digital route above feasible?
could I use two 74HC150 16-line-to-1-line multiplexers (I'm gaining this information from page 654 of Practical Electronics for Inventors - Paul Scherz) to read the rotary switches -
No because then each switch would need to be a 4 pole switch in order to have the enough combinations of zero and ones to identify each position.
Such switches do exist though, each would need 4 input pins for which you could use a port expander.
Thanks for the reply. I don't want to waste your time - as I will probably solve this by using the analogue inputs as mentioned in my last post.
But, with the 16-line-to-1-line multiplexer (74HC150) could I just cycle through the "data select" values (0000, 0001,0010,....1110,1111) until the output line registered a "high" thus identifying rotary switch position from 1 to 1 pairing between the "data select" values and the rotary positions. I know its all a bit ungainly, but would appreciate an answer just for information. I promise this will be my last post on this subject.
That's no problem as long as you are learning stuff whether you use it or not immediately is not an issue.
could I just cycle through the "data select" values ....
Yes you could, if you wired all the inputs to pull up resistors and the wiper of the switch to ground then only one input would be zero at any time. Then, as you say, you could search the combinations of the data select line to find what one produces a logic zero.
However, that is as you say a bit clunky.
A better circuit to use would be a "priority n encoder". An example of such a chip is 74F148, this is an 8 line to 3 encoder, which is a bit short of what you need. However these can be easily cascaded, there is an example in the data sheet showing how two of these chips can be combined to give a 16 to 4 line encoder. Basically the input with the highest number that has a logic zero on it, is signaled in binary on the output bits.
However the down side is that you need to use 4 inputs to read in the position of the switch.
I promise this will be my last post on this subject.