Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:59 07 Jul 2025 Privacy Policy
Jump to

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 : MicroMite MkII Keypad feature request(s)

     Page 1 of 2    
Author Message
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:11am 10 Nov 2014
Copy link to clipboard 
Print this post

Would it be possible to add a feature to the KEYPAD command so that it uses less pins?
and
Would it be possible to have a value that has the state of multiple buttons. (With 64 bit integers it would be possible to have a nibble for each row) This would allow for key combinations.

I often find myself connecting a few buttons to a MicroMite.
3 or 4 sometimes even 8-9.

Unfortunately that cost a lot of pins (and resistors*) when connecting them directly.
For that reason i like to wire them with columns and rows, exactly the same as a keypad is used only with less rows and columns.
To use them i have to write some code that scans the rows and columns.
Seems redundant when there already is a keypad command.

Ideally being able to use as little number of pins as possible. Even connecting one button by defining only one row and one column would still be nice because it will be debounced.

Now the KEYPAD command needs at least 7 pins. Maybe another way to provide the pin numbers could be considered. There are two options that i can think of now.
One is using the number 0 for an unused row or column. The syntax stays exactly the same, the firmware would need to recognize the 0 as an unused row/column.
Another variety would be to only supply the number of pins that are needed. This requires more documentation.
Here are examples how it could be used in both variations:
[code]
1 button:
KEYPAD var, int, r1, c1
KEYPAD var, int, r1, 0, 0, 0, c1, 0, 0

2 buttons:
KEYPAD var, int, r1, r2, c1
KEYPAD var, int, r1, r2, 0, 0, c1, 0, 0

3-4 buttons:
KEYPAD var, int, r1, r2, c1, c2
KEYPAD var, int, r1, r2, 0, 0, c1, c2, 0

5-6 buttons:
KEYPAD var, int, r1, r2, r3, c1, c2
KEYPAD var, int, r1, r2, r3, 0, c1, c2, 0

7-9 buttons:
KEYPAD var, int, r1, r2, r3, c1, c2, c3
KEYPAD var, int, r1, r2, r3, 0, c1, c2, c3

10-12 buttons:
KEYPAD var, int, r1, r2, r3, r4, c1, c2, c3

13-16 buttons:
KEYPAD var, int, r1, r2, r3, r4, c1, c2, c3, c4

[/code]

* When using the internal pullups those would not be necessary anymore.Edited by TZAdvantage 2014-11-11
Microblocks. Build with logic.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2431
Posted: 01:41pm 10 Nov 2014
Copy link to clipboard 
Print this post

there have been earlier threads on using a single analog pin to connect a keypad, it may be worth having a look at these. i posted one using am LM334 + PNP pass transistor that was self-calibrating and worked quite nicely.


cheers,
rob :-)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 02:03pm 10 Nov 2014
Copy link to clipboard 
Print this post

That seems doable, let me have a look at it.

Geoff
Geoff Graham - http://geoffg.net
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 10:45pm 10 Nov 2014
Copy link to clipboard 
Print this post

Isn't this the kind of thing we should be using CFunctions for ?
The only Konstant is Change
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:08pm 10 Nov 2014
Copy link to clipboard 
Print this post

A CFunction can not fire events.
And isn't the point of having a basic interpreter to actually use basic?
It would also be possible to backport it to the other members of the 'mite' family.

In this case i thought the functionality overlaps 100% with what the keypad command is already doing only with less pins.


Microblocks. Build with logic.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:49am 11 Nov 2014
Copy link to clipboard 
Print this post

Hi TZ,
Yes, I've been thinking along the same lines, but mainly for the single analog input pin method as Rob noted. I recently sent the e-mail below to Geoff and his reply is attached. I haven't replied to him yet because there's not really a "readily available chip or module" that I can point to. Sparkfun do an op-amp based single analog pin mini-board but I'm not too excited by their method. Robs method should be good but I'm not sure if it's tested, and Gregs method based on Jez Siddons work also works well and is tested.

The single pin analog method doesn't cater for 'double' multiple keypresses (like 'Shift A') but it could if one more pin was used. The 'state of multiple buttons' that TZ requested also wouldn't be covered.

Greg

--------------
Hi Geoff,
Given that you’re up to your neck in work at the moment I’ll probably need to duck my head on this possibility too - but I thought I’d mention it – maybe for a later list.
Single Analog input keypad command.
I’ve used a 4x4 keypad on a couple of projects and I think they’re always going to be a common requirement. The command you gave us for them is great and I’m using it, but it assumes the standard eight-pin connection to the micro. That’s a big chunk of the I/O pins of the 24 pin chip and I think it would often be helpful to be able to use the single analogue pin input method. The single method means just one pin used and it’s also very easy to design &/or connect to your micro’s board if you use a small cheap satellite board attached to the keypad to do the 4x4 to analog conversion - I’ve got one of these going and it’s pretty simple and neat, but could be tiny and cheap if done with SMD’s.
The MMBasic programming to use this method is not so simple however. I’ve got it working quickly and reliably (on a Maximite) using TIMER interrupts, but there’s quite a bit of other code needed and when you’re using multiple TIMERs it compromises how quickly they can be run.
What do you think of the possibility of adding a command to use this keypad method?

Greg
---------------------
Geoff's reply:
Hi Greg,
I try to make the built in hardware support work with standard, readily available chips and modules. Can you point me to a keyboard or circuit that does what you are referring to?

Geoff

--------------------

 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 03:01am 11 Nov 2014
Copy link to clipboard 
Print this post

  Quote  A CFunction can not fire events.
Good point. A CFunction can certainly cause things to generate interrupts, since CFunctions can take the address of 'C' functions, respond to them in C, and since one can take the address of a CFunction - PEEK(CFUNADDR cfun) - and pass that address through to a CFunction, it should be possible to have CFunction ISR's - I'll have to investigate this possibility, thanks for the nudge ! But as to whether a CFunction initiated interrupt can cause an event in MMBasic is an interesting question and probably only one which Geoff can answer. It would of course be entirely possible to have the 'C' code toggle an output pin which is coupled to an Interrupt enabled input pin which would then generate an MMBasic recognisable interrupt/event, but that's a bit of a bodge IMHO and uses up 2 I/O pins.

  Quote  And isn't the point of having a basic interpreter to actually use basic?


If it was just a matter of using Basic rather than requesting an extension to the Basic interpreter, then I would entirely agree with you, that "the point of having a basic interpreter to actually use basic?".

In contrast, when I wrote the I2C Keypad library - http://www.g8jcf.dyndns.org/mmbasic/I2CKeyPad_MUPV1.zip I used entirely MMBasic code, No CFunctions, No MMBasic extensions, just pure 100% MMBasic - and it is interrupt driven.

As a general rule, I think that the language should be as free/neutral of the hardware and especially specific h/w as possible. Libraries whether compiled, or in source form should be used to add specific h/w item support IMHO.

BTW, why not use I2C for all your I/O interfacing, eg LCD, Keypad, Switches, LEDs etc ? I2C should save one a lot of pins on the uMite, usually makes wiring a lot simpler, there are lots of standard modules available for very little money, and allows one to save uMite pins for really fast I/O or analogue I/O.

Peter
Edited by G8JCF 2014-11-12
The only Konstant is Change
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 07:35am 11 Nov 2014
Copy link to clipboard 
Print this post

  TZAdvantage said   A CFunction can not fire events.
And isn't the point of having a basic interpreter to actually use basic?
It would also be possible to backport it to the other members of the 'mite' family.

In this case i thought the functionality overlaps 100% with what the keypad command is already doing only with less pins.



I agree with you.

I also don't think I2C is the answer to everything. My opinion.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:02am 11 Nov 2014
Copy link to clipboard 
Print this post

i2c is good for 'intelligent modules'.
Not so much for controlling switches, leds etc.

I have made a whole range of modules that way, but when using them I found out that I had lots of pins left on the micromite that it was a waste of resources especially PCB space.

I know see more value in specific made PCBs that first use all the pins that are available before using i2c. Switching to a 44-pin or even a 100-pin is more efficient.
It is also the reason why companies like Microchip has so many different mucus available. Otherwise an 4 pin mcu with enough flash and memory would be enough.


Microblocks. Build with logic.
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 10:01am 11 Nov 2014
Copy link to clipboard 
Print this post

@TZ,

Ah OK, I understand your perspective re wasted pins, PCB wasted area and I2C, and for volume production that would indeed be a cost issue.

re "Intelligent Modules", when it comes to I2C devices sending data into the MCU, eg switches, and ADCs, it is a lot more difficult to code up if the I2C devices are just 'dumb h/w' such as the PCF8574 expanders. It can be done, but the coding is much more intricate, but of course once coded, implementation is effectively free per product shipped.

If one is able to create and stock distinct PCBs at will, then as you say there is benefit in using chips with more I/O pins rather than juggle with I2C/SPI etc.

BigMik's 8 pin uMite module is going to be an interesting module given just how tiny he's managed to make it.

Horses for courses.

Peter
The only Konstant is Change
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2431
Posted: 08:20pm 21 Nov 2014
Copy link to clipboard 
Print this post

  paceman said   Hi TZ,
Yes, I've been thinking along the same lines, but mainly for the single analog input pin method as Rob noted. I recently sent the e-mail below to Geoff and his reply is attached. I haven't replied to him yet because there's not really a "readily available chip or module" that I can point to. Sparkfun do an op-amp based single analog pin mini-board but I'm not too excited by their method. Robs method should be good but I'm not sure if it's tested, and Gregs method based on Jez Siddons work also works well and is tested.

The single pin analog method doesn't cater for 'double' multiple keypresses (like 'Shift A') but it could if one more pin was used. The 'state of multiple buttons' that TZ requested also wouldn't be covered.

Greg


i've done quite a bit if testing with the 'LM334 + PNP' circuit, and it does seem to work pretty well. multiple keys pressed at once are easily locked out by requiring the input voltage to return to > inkey * 18, and as you say shift keys can be on a separate pin. i'd certainly be keen to see geoff add support for the method to micromite basic.

as an added bonus, the simple circuit does have an educational value for the student to practice lashing together a few components into something that is hard to get wrong.


rob :-)

addendum: analog keyboard input could be implemented as an extension of the existing keypad command:

KEYPAD var, int, apin
Edited by robert.rozee 2014-11-23
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:39am 03 Sep 2015
Copy link to clipboard 
Print this post

A 'bump' to make this thread more current.
I ran into the same requirement and i thought to write a post when i remembered this one.
So hopefully, it is still under consideration.
:)

No worries if it can not be done. There are ways around it.
Microblocks. Build with logic.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:47am 23 Jul 2016
Copy link to clipboard 
Print this post

And today i found myself again in the situation that i need to connect about 5 buttons. The keypad command would have been great to use, now i have to do the debouncing and scanning myself.
Does nobody else run into this?

Microblocks. Build with logic.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 02:41pm 23 Jul 2016
Copy link to clipboard 
Print this post

  MicroBlocks said   And today i found myself again in the situation that i need to connect about 5 buttons. The keypad command would have been great to use, now i have to do the debouncing and scanning myself.
Does nobody else run into this?


I've thought about this thread a few times.
I²C comes to mind & also analogue input.

Both have been discussed & with various issues.

What about a fall back to older technologies?

DTMF has served it's purpose for many years, reliably it seems.
Before that there was just Multi-frequency signalling.

Curious what sort of hardware would be required to make a matrix output multiple frequencies.

Cheers.
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 174
Posted: 06:30pm 23 Jul 2016
Copy link to clipboard 
Print this post

@MicroBlocks and Phil23

When there is nothing on the market I go back to my roots and use a PIC12F675 or a PIC16F88. PICbasic Pro, by meLabs, is a wonderful thing. I knocked up just the thing some time ago. I limited it to scanning up to a 4 x 4 matrix (keypad or buttons) or up to 8 discrete buttons or switches.
It also has an interrupt output so your MM will not be wasting time polling an input.
You had the option to output a dedicated frequency or a serial code, depending on what resources were available. The MM's have a number of serial ports, or count inputs, so it should be ideal. Microcontrollers were designed for a reason. A simple circuit can do so much just by changing code. One chip, a capacitor and a resistor. Do that with analogue electronics.
If there is enough interest I will tailor it to suit everyone's needs and design a backpack PCB to suit readily available keypads. I will also make the source code, and hex file, available so everyone can program their own devices.
You can have the 'gerbers' too. The only thing is, I use Protel EDA Client. Still coming to grips with Autotrax DEX. Might be a while before I get around to using it 'wholesale'.

There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:14pm 23 Jul 2016
Copy link to clipboard 
Print this post

Still every other solution requires extra hardware. While it would be easier to just use a bigger mcu when not enough pins are available and use the extra pins. The 1-2 US$ for a larger mcu is then well spend and keeps the BOM count down. I'd rather solder a 44pin then a 28 pin with 5 resistors/capacitors/etc.

I just think that adding this to the keypad command is trivial when compared to the multitude of LCD's that are supported.
Yet something simple as switches is not.

It is also not difficult to write a function that does it in basic, but the feeling is that there is already a KEYPAD command with all the features needed like debouncing, interrupts, decoding etc. Repeating that feels redundant.

Thinking of beginners, the use of KEYPAD is a lot easier to explain then making a program that uses timers and machinestates to debounce and decode a small switch matrix. Ten's of lines of code that have to run while other processes need to continue, while a single command could suffice.

For something external i made a little mcu that decodes a matrix and outputs it to the serial port. This serial port is then connected to the RX from the console, so the keys kan just be read with input or inkey$.
The console RX is connected to the output of a little 'OR' gate which allows characters from the USB/Serial terminal or from the little mcu.






Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 03:34am 24 Jul 2016
Copy link to clipboard 
Print this post

I did look at extending the KEYPAD command and eventually discarded it. It turned out to not be that simple to implement and, as far as I could see, not many people would have been interested in using the extended feature anyway. In fact, I don't think many people use the KEYPAD command at all and it is on my list for possible removal.

Geoff
Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2431
Posted: 04:58am 24 Jul 2016
Copy link to clipboard 
Print this post

from the educational perspective, i see the KEYPAD command as an integral part of the package, allowing beginners to quickly get input into their project. the one change i would like to see is for the number of columns to be expanded to include 2, as well 5, 6, 7, or more - ie, have no upper limit. this would allow a slave-micromite to control a fairly complete ascii keyboard.

how difficult would it be to allow for other numbers (2, 5...) of columns, assuming the number of rows is kept fixed at 4?


cheers,
rob :-)
 
cosmic frog
Guru

Joined: 09/02/2012
Location: United Kingdom
Posts: 302
Posted: 05:16am 24 Jul 2016
Copy link to clipboard 
Print this post

  Geoffg said  ... In fact, I don't think many people use the KEYPAD command at all and it is on my list for possible removal.

Geoff


WHAT!
I nearly choked on my PicKit3 when I read that!
The keypad feature is great even when only used for one or two buttons. It's nice and easy to use and no faffin' around with debounce. I use it all the time.

Dave
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:08am 24 Jul 2016
Copy link to clipboard 
Print this post

I am currently testing something different that might make a good solution for adding switches/keypad.
I have added the code for scanning a little matrix to my USB/Serial converter.
It has an 8 pin connector that directly connects to those membrane keypads that have a 4x4 matrix.
like this one:



You can also use it to connect switches of your own, just wire them as a matrix. 1 key to 16 keys supported.



The extra code scans the matrix and injects a switch/keypad code into the outgoing serial buffer.
The micromite will receive it over the console rx and can treat it like any other key just as ones that are pressed on your pc's keyboard when using a terminal.


I am considering to use the normal ascii codes for it, or as an alternative send ascii codes 200-216 to distinguish between keypad and pc keyboard.




Microblocks. Build with logic.
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025