Hi there, firstly, let me just introduce myself to you guys, hi, I’m Rick and I’m coming from an Arduino background but have bought two of these Spark cores cos they look great.
However, they are a bit sparce on pins so I have had to rethink a control panel I originally designed for use on an Arduino Mega. I have a panel of 8 buttons which I want to connect using a resistor ladder to get an analog output. I have other stuff on the other pins so I need my 8 buttons to use as fewer pins as possible so the resistor ladder seems like a good solution.
If I use pin A0 as my reader for my button array, will it trigger the interrupt if my array only produces say .5v?
I have not received my cores yet so can’t test this out, it’s more of a feasibilty study currently, I see the core only outputs 3.3v so if anyone can tell me if this will work I’d greatly appretiate it.
Awsome, I was hoping someone would suggest a chip I could use, I have found this one 74HC165N, would this mean that I can connect 8 buttons to it and then I would presumably get a serial (uart?) out. Is there a way I could get the chip to say trigger the interup then in the ISR read the serial output of the chip or am I getting it all a bit wrong with my understanding. Thanks for the reply
Ok, yes, I want to process my user controls via ISRs because it frees up my main loop to do the meat of the functionality.
I come from a .NET desktop developement background and so am used to handling events and using interrupts just feels much more natural to me for handling user input than constantly polling switches and buttons etc.
Can anyone else suggest an elegant way to handle an array of buttons, preferably via an interrupt and preferably hardware debounced. I am currently using R/C network and schmit trigger to debounce each button and having individual pins on the mega but, hmm, my knowledge of what components are out there / electronics design patterns is letting me down
Hey, sorry to keep banging this drum but would this work
Then in the ISR attatched to A6 I could read A7. I however have no idea what transistor I’d need but with my limited electronics knowledge the small output of the ladder would make the transistor send 3.3v to A6 no
rickpbush, I am not sure you need an interrupt in this case. With equal resistors, you will get about 0.4V discrimination per switch assuming all resistors are the same. That is an ADC count per switch of 511 or so.
By sampling the ADC in loop(), you can detect a single button push using an if/elseif ladder. Assuming loop() runs fast, your sampling negates the need for an interrupt. Another approach is using an Arduino library for creating debounced analog buttons. A quick look tells me it should be easy to port to the Spark. If that interests you, let me know.
Thanks peekay, I actually bought two sparks after reading through the Digole thread that you played a major part in, I was unaware of the spark prior to that and stumbled upon your thread while looking for help with the Digole Serial oled, as a direct result of your library work they sold 2 spark cores to me
Anyway, I know I can put the button polling in the main loop, it’s just potentially I’ve got lots going on,
a 4 position selector switch,- a hall effect joystick
and all the drawing routines for displaying the menus, capturing user data etc.
All the controls are currently handled by ISRs to keep that stuff out of my way while processing the main loop. I may be wrong but I feel designing a system to use interrupts is preferential to polling constantly, if only that it ‘feels’ more comfortable to me to interrupt the main program flow when something ‘non normal’ happens, like the user wants attention, ie he pressed a button or something.
However, I was entirely unaware of the AnalogButtons library. I took a look and it is exactly what I’m trying to do :), I would however need 8 buttons so I may need to tweek it a bit, and there I was thinking I was being clever using a resistor ladder
Another option for reducing pins would be a multiplexer. You could read 8 buttons with 4 digital pins (3 address lines, one data input). More pins that it would take with serial, but much simpler to read. It’s all about trade-offs, right?
Ok, I have decided that my best option is simply to use the library and a few resistors, I’ll poll in the loop as suggested by peekay and de-bounce in software, it just seems like the best solution to me and won’t require the procurement of exotic hardware. Thanks for your help on this guys I now have a different set of questions for which I will create a new thread because they relate to expanding my basic (non existent) knowledge of the sparks capabilities/design.
I see that you also have a rotary encoder on your list, which is great. I don’t know if you mean the kind used with a motor to resolve position or the kind used with a knob as a user-input mechanism.
You will want to use interrupts for that for sure! I have the user-input knob kind working fine with interrupts (I can post the code) but I had to give up on software debouncing–just adding two small caps was much less frustrating. There is some good Arduino code out there, but there is also a lot of bad code for dealing with rotary encoders.
The motor kind of encoder can bring different challenges due to the higher speed requirements.
Hi bko, thanks for the input, it’s a user input knob type.
I have implemented my rotary encoder using an RC network and schmit trigger, total overkill but it works brilliantly on an interrupt and I wanted to learn about debouncing which is why I did it that way.
I only needed to use one interrupt on the up cycle and a digital pin on the down because both up and down fire when the knob is turned, just out of sync with each other as I’m sure you know, I simply read both pins and compare when the interrupt is fired to deturmine turn direction.
I love these encoders used in conjunction with an LCD as a means of cycling alph/numeric character to capture user input strings, my encoder has a push button on top so entering strings feels really natural. By adjusting the cap/resistor value (ie taw), I can get really fast acurate debounced input.
At some point I’ll do a blog for those who are interested, I’m still a novice but I do get quite excited about making stuff work and getting feedback makes me feel less of a loner