Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Single-pin 4x4 keyboard for micromite
Author | Message | ||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
for those struggling to work with both LCD and KEYBOARD at the same time with a micromite, the following solution might be of use to get back 7 pins. it uses a single analog input pin to read the keypress from a keyboard set up to provide a 16-level analog output: the LM334 with 68 ohm resistor will give a 1mA current flow through the keyboard when a key is pressed. the other resistor values have been chosen such that the output voltage (1mV per ohm) will range between 100mV for the top left key up to around 1.6v for the bottom right key. unfortunately the steps are not perfectly even, so it will be necessary to use 15 if/then statements to sort out the keys. the resistance/mV values returned should be close to: 100, 490, 920, 1300, 180, 570, 1000, 1380, 270, 660, 1090, 1470, 390, 780, 1210, 1590 software required is a 5mS (or thereabouts) timer interrupt routine that reads the analog pin, and if it is within around 30mV of the value read on the previous interrupt, deposits the read voltage into a variable. this double-check will act as a debounce mechanism. the A/D converter in the micromite (set up for 3.3v FSD) should be able to resolve down to around the 3mV level. the main program, when wanting to check for a key needs to first see if the ISR returned voltage was greater than about 2 volts - if so, then no key was pressed. it then needs a series if/then statements to separate out the above 16 voltages. the split points will be the differences between consecutive values: 0.140v, 0.225v, 0.330v, 0.440v, 0.530v, 0.615v, 0.720v, 0.850v, 0.960v, 1.045v, 1.150v, 1.255v, 1.340v, 1.425v, 1.530v (please check, i calculated these by hand) use 1% resistors. the 68 ohm resistor could be replaced by a 100 ohm/20 turn pot, which would allow tweaking the spread of the whole range. but this would probably be overkill. the top two voltages (1.47v and 1.59v) are about 8% apart, which is much greater than the tolerance stackup of everything else. the above circuit and code has not been tested, but i see no good reason why it should not work. enjoy, rob :-) |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Hi Rob, The analogue input method has been covered on the forum a couple of times before, e.g. 4x4 keypad single input. There's no real issue with the number of pins available, it's more to do with sorting out the two interrupts operating concurrently i.e. from SETTICK for the countdown, and keypresses from the new KEYPAD command. It's working OK at the moment, but it's not tidy. Greg |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
i'd not spotted those posts from the distant (pre-micromite) days. have built up the above circuit, and it works well. needed the one addition of a 100k resistor from the input pin to ground. this kept the micromite happy, as it did not like to see it's input floating high. the error introduced into the calculated voltage drops by this resistor is negligible. below is sample code. debounced, and ignores multiple buttons pressed at once. have not been able to fault it: SetPin 2, AIN
SetTick 10, kbdISR Pause 50 Do Do key = keypress() Loop Until key <> -1 key = keypress() Print key, keyvolt Do key = keypress() Loop Until key = -1 Loop '---------------------------- Function keypress If keyvolt > 1.7 Then keypress = -1 ElseIf keyvolt < 0.140 Then keypress = 1 ElseIf keyvolt < 0.225 Then keypress = 4 ElseIf keyvolt < 0.330 Then keypress = 7 ElseIf keyvolt < 0.440 Then keypress = 10 ElseIf keyvolt < 0.530 Then keypress = 2 ElseIf keyvolt < 0.615 Then keypress = 5 ElseIf keyvolt < 0.720 Then keypress = 8 ElseIf keyvolt < 0.850 Then keypress = 0 ElseIf keyvolt < 0.960 Then keypress = 3 ElseIf keyvolt < 1.045 Then keypress = 6 ElseIf keyvolt < 1.150 Then keypress = 9 ElseIf keyvolt < 1.255 Then keypress = 11 ElseIf keyvolt < 1.340 Then keypress = 20 ElseIf keyvolt < 1.425 Then keypress = 21 ElseIf keyvolt < 1.530 Then keypress = 22 Else keypress = 23 EndIf End Function kbdISR: prevkey = nextkey nextkey = Pin(2) If Abs(prevkey-nextkey) < 0.030 Then keyvolt = (nextkey - 0.018) * 1.06 EndIf IReturn note the two constants 0.018 and 1.06 in the ISR. the 0.018 is the resistance of the keypad i am using. seems to be fairly constant. adjust so that when the '1' key is pressed keyvolt is 0.100 or thereabouts. the 1.06 multiplier is to take account of the inaccuracy of the 3v3 on my setup. again, adjust so that the bottom right key returns a keyvolt of close to 1.59 rob :-) |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Perhaps a candidate for submission to a MicroMite user programs library? Smoke makes things work. When the smoke gets out, it stops! |
||||
SteveP Newbie Joined: 21/03/2013 Location: United StatesPosts: 19 |
Sparkfun sells a 4x3 VKey Voltage keypad as part PRT-12080 https://www.sparkfun.com/products/12080 And now have a tutorial for it https://learn.sparkfun.com/tutorials/vkey-voltage-keypad-hoo kup-guide |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Rob: The circuit shown in the link I gave above gives a gives an almost 100% linear response to the keys. you can then replace the seventeen IF statements of your code with one line, (as for linear equations (y = S*x + c)): keynum=Cint(5.2539*vkey+0.0534) 'Convert to integer by calib'n eqn
The CINT function also efficiently gives the maximum range available between each voltage level so things stay very stable and there's almost double the spread of voltage to start with. Steve: Yes, I saw them. They use a bit more complicated op-amp circuit instead of the constant current circuit we're using and calibration is a bit more involved. The description implies the calibration might need adjusting occasionally too. Greg |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
it seems that with the 28-pin micromite there is a major issue if one wants to use both a keypad and an LCD using the built-in commands and minimal extra hardware. of the 19 available pins, 14 are used up, leaving just 5 free! add an RTC, and you are now down to only 3. you are right, that a linear solution is possible, but the original circuit still has a few issues. from my own testing, it will not work reliably with the micromite due to the analog input being left floating when no key is pressed (an easy fix), plus it does need a 5v supply to operate with the choice of resistors and temperature compensation of the LM334. upping the current to 1mA and dropping the TC allows for 3v3 operation and better noise immunity. the TC is nice, but adds complexity that most beginners don't need. does anyone know of a better choice than an LM334? having done a few more calculations, one can use 4x 100 ohm resistors in a ladder for the rows, and 3x 390 ohm resistors similarly for the columns, with a 220k resistor to keep the LM334 live when all buttons are open. the key voltage then becomes 100mV (+18mV for keyboard resistance), plus 97mV per step. the (calculated) returned resistance stays within about a 2% error band. rob :-) |
||||
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2817 |
I fully agree with paceman; and have to totally disagree with rob's opinion when he says 'there is a major issue'. Here's why . . . If we just take a step back and look at what is being said by rob. It seems that with the 28-pin MicroMite there is a major (??) issue if one wants to use both a keypad and an LCD using the built-in commands . . .and RTC . . . and MINIMAL extra hardware you are down to only 3 pins spare. Well, you can actually do a great deal with just 3 pins but it really does depend what it is you want to do. And what exactly is meant by 'minimal hardware'? If you want a few more I/Os then there are multiple support chips to choose from. Surely just one extra chip to meet I/O requirements is minimal hardware? Or why not have a second MicroMite and write a simple comms routine to communicate between them (Geoff has a brilliant example on Pages59-62 in Beat16 manual). Then you have many more pins to play with so that could hopefully meet your I/O requirements. Or why not use a 44-pin MicroMite to give 33-pins to use? Or even two of them connected together? Sometimes we have to make a compromise. Sure it can be challenging to try and get something to work the way you 'think' is the best solution; but taking a step back, you may just find a 'slightly' different approach that is actually more suitable when you think about it . . . By the way, I once built a brilliant little 4x4 analogue keyboard using just one analogue input. This was for an 8-pin PIC and incorporated temperature compensation too. I was well happy with it until my customer wanted multiple key presses. I spent ages looking for a solution to this trying to use the same PIC device but ended up having to use a 20-pin PIC and 8 I/Os (conventional 4x4 matrix scan). Anyway, customer was happy with new product and I had learnt to not try to solve a problem the way I thought best (i.e. to still try using the 8-pin PIC) and instead I learnt to compromise a little. 20-pin PIC16F690 was actually a cheaper device too! For everything Micromite visit micromite.org Direct Email: whitewizzard@micromite.o |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
Or why not have a second MicroMite [ ... ] Or why not use a 44-pin MicroMite i see one of the main philosophical strengths of the micromite as the ability to do something meaningful with a single chip in the middle of a piece of veroboard. this was perhaps one of the goals with the arduino, but it failed when many folks instead went in the direction of an assembled PCB costing $30 or so that contained a whole load of extra hardware. the dominating discourse become one that was far more 'affluent' than the average kid-experimenter. and i depreciate the 44-pin device because the assembly is beyond the soldering ability of a beginner, and an assembled version is far more expensive (until the chinese start selling them on ebay). while two micromites strung together adds extra wiring, two sets of code to keep track of and debug, and the need to get one's mind around the logical interactions between two processes happening at once. as a teaching/learning tool i can see: 1. a micromite on a bit of veroboard with a ZIF socket + ICSP + ttl serial headers, as i have built myself 2. a kid with a $20 prezzy card (prepaid visa) who can buy all the bits on ebay for less than $20 3. a 'classroom kit' that is a micromite sitting on a solderless breadboard that kids can make do something within the limits of a 1 hour lesson. if a 32MX gets fried, the teacher has a tube of spares in the back that have been donated by microchip. 4. the ability to do clever things with just a few switches, simple sensors, and a handful of passive components. there are, of course, my opinion. others may have different opinions that vary widely. rob :-) |
||||
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2817 |
Hi Rob I agree with everything you say - plus at the end of the day, the analogue keyboard makes a nice 'classroom' lesson too. I am actually going to be using the MicroMite as a teaching tool for a MicroController course I am compiling for beginners. I just love the idea of a 28-pin DIP, breadboards, keypad, LCD and most importantly just a FEW lines of code. Works wonders in the classroom. And fully agree with the spares being a simple swap-out when something goes 'pop' (which it always will in a classroom!). But all that said, IF you are constructing an end product (classroom or otherwise), if you haven't got enough pins then rethink what it is you need to do to achieve your end goal. If the analogue keyboard is the most appropriate then great -use that. Simply understand any hardware 'limitations' and work within them. Then there is never a 'major' issue. One final thing, please check your PMs in a few minutes!! Thanks . . . For everything Micromite visit micromite.org Direct Email: whitewizzard@micromite.o |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Yes, the skinny DIL certainly comes into it's own in the classroom for ease of use/replacement etc. Everything has it's place. Smoke makes things work. When the smoke gets out, it stops! |
||||
SteveP Newbie Joined: 21/03/2013 Location: United StatesPosts: 19 |
does anyone know of a better choice than an LM334? Linear Technology LT3092 constant current source 2-pin http://www.linear.com/product/LT3092 http://www.linear.com/solutions/1006 |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
The teaching example with the 28 pin DIP on Veroboard seems a great option to me. The keypad can be either direct to the board with 8 lines or the single pin voltage solution can be used. Put a header on the keypad (I used a right angle one) and go direct with breadboard leads for the 8 pin and then when you want more pins left on the micro, (or just to demo the technique) go via a little analog board plugged into those pins. The analogue board has an 8 pin female header on the keypad end and a 3 pin header for the supply, gnd and analogue out. This is actually the arrangement I use for proto-ing with the keypad and/(or not) the analogue board. For teaching, the analogue board itself can be a project or it could be made up very cheaply with SMD's (except the LM334) and be a very small plug in module. The LT 3092 suggestion would be expensive and not justifiable. Element14 prices are: LT3092 - $7.50 LM334z - $1.10 It works well with the 334, why go to a constant current source that's twice the price of the micro? Greg |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
I did mean for just the project we were talking about. As Phil said, If you have a more complex need go for the 44 pin chip, it's the same price, you'll probably be into SMD's anyway and 0.8mm pitch isn't too difficult. You could still add a lot more with the few pins left on the the 28 anyway if you used I2C. For a home project where you want to use Veroboard and the DIP 28 then get extra pins by using the analog keypad route. The post link I gave was using the Maximite so a 5v supply was available, and in many cases it is. It also gives you more range for voltages to drift a bit without affecting the keypress results. Your option for the 3.3v supply is good if 5v isn't available. Adding the temperature compensation doesn't seem to me a significant complication given it's only one diode and resistor, the total component count doesn't go up much. The datasheet recommends not going above 100uA without TC and going up to 1mA from 200uA is a fair jump without it. It makes the LM334 considerably more temperature dependent which is a bigger problem when using a 3.3v supply Vs a 5v supply. Greg |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
apart from the cost, the LT3092 doesn't come in a leaded package. if it did (and was cheaper and more widely available) it would be quite perfect. doing a few calculations, i see that going from 0 to 50 degrees C the voltage 'output' of the LM334 varies between about 62mV and 74mV. this translates to an output current (with 68 ohm resistor) going from 0.91mA to 1.09mA, so temperature compensation is pretty much essential in any application outside of the lab. adding in the 0.6v drop of the compensation diode necessitates running off 5v, unless someone can come up with a better compensation mechanism that doesn't incur any additional voltage drop. my thoughts are: 1. if the internal temperature sensor of the micromite could be read, this could be used to make a correction at the calculation stage. there is still the issue of the A/D converter being scaled to the Vcc voltage. 2. adding in just the right PTC thermistor across the current setting resistor so that the combined value tracks from 62r up to 74r over the 0 to 50 degrees C range. 3. a second LM334/68r resistor could feed a fixed 1k6 resistor monitored by a second analog input - this could be used to derive a scaling factor. advantage - this would also compensate for Vcc not being 3v3. rob :-) |
||||
Print this page |