Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:07 04 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 : Keyboard for Micromite Plus

     Page 6 of 14    
Author Message
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2949
Posted: 09:35pm 25 Aug 2015
Copy link to clipboard 
Print this post

Thanks Grogs, Bob,

I knew there would be a logical answer

Mick

Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 02:13am 26 Aug 2015
Copy link to clipboard 
Print this post

UPDATE:

Here we have the running prototype - excuse the rats-nest of wiring.....





...and the results on the console...





This is just initial testing - the code needs tweaked some more, but basic keyboard is working fine, and I have the 170 MM chip throttled back to 10MHz, AND with a 100ms delay between keypresses. Matrix scanner code is crude by some members' standards - just a whole heap of IF/THEN lines inside a loop. Loop completes in 25ms @ 10MHz, and is down to about 9ms @ 48MHz, but you don't need it to run that fast, really, just for scanning a matrix.
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:26am 26 Aug 2015
Copy link to clipboard 
Print this post

Yes! Success!

Mine will take some more time.

Goes to show the power of a MM, from plan to working prototype in a very short time.


Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:28am 26 Aug 2015
Copy link to clipboard 
Print this post

Hi G,

Nice
Can you clarify something for me please. What 'electrical connection' is being used to connect the keyboard to the MM for it to 'drive' the onboard console? Is it through a serial port? If so, which pins?

Also, is there drive for caps LED?

Been keeping my eye on this thread with great interest and am keen to try things that you have achieved so far.

WW
 
Chris Roper
Senior Member

Joined: 19/05/2015
Location: South Africa
Posts: 280
Posted: 02:40am 26 Aug 2015
Copy link to clipboard 
Print this post

Well done Grog It is looking good.

I have an old USB keyboard here that I bought for my long dead Nexus 7 Tablet.
I am tempted to pull that apart and test the matrix now.

Between yourself and ZTA.. you are breaking new ground for all of us to try hacking keyboards.

Cheers
Chris

http://caroper.blogspot.com/
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:41am 26 Aug 2015
Copy link to clipboard 
Print this post

Future challenge:

CPU in SLEEP, then wake on keypress to process key and output data, then sleep (maybe after period of inactivity).

This would then make keyboard ideal for battery powered (rather than 15mA (ish) continual). If a C-Function is doable to keep MHz to a minimum, along with the SLEEP method then you have something really useful.

Loving this thread now . . . .

WW
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 03:04am 26 Aug 2015
Copy link to clipboard 
Print this post

  WhiteWizzard said  Can you clarify something for me please. What 'electrical connection' is being used to connect the keyboard to the MM for it to 'drive' the onboard console? Is it through a serial port? If so, which pins?

Also, is there drive for caps LED?


Hi-de-hi.

The output from this experiment is via the native MM console pins.
These would connect directly to the console of another MM, or any other serial port.
At the moment, the code basically ignores console RXD, and is an output device only.

'Power' LED on KB is lit, and blinks when you type anything(not shown).
'CAPS' LED on KB is driven from an IO pin, and the PCB I have made allows for both these LED's in their original locations, so they will show up through the case like they would have before I got hold of it. The other two LED's are NOT allowed for.

I only have lower-case working at this point - I need to add more flags for shift and caps etc, so that in the output routine, I can just make use of MM's UCASE$ function.
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 03:37am 26 Aug 2015
Copy link to clipboard 
Print this post

  WhiteWizzard said   Future challenge:

CPU in SLEEP, then wake on keypress to process key and output data, then sleep (maybe after period of inactivity).

This would then make keyboard ideal for battery powered (rather than 15mA (ish) continual). If a C-Function is doable to keep MHz to a minimum, along with the SLEEP method then you have something really useful.

Loving this thread now . . . .

WW


I am considering this and the matrix will allow for that if internal pull ups of the pic are still in use after going into sleep mode.
I was thinking that the 4017 is putting a '0' on all the columns (by not using Q0 as part of the matrix)), the PIC has all '1' because of the internal pull up. If a key is pressed then one of the PIC's inputs will go low. This could trigger a interrupt/wakeup. Lots of reading and testing required but it should be possible.

I should have included a few LF versions of the chip i ordered, because they are really low powered.
Edited by TZAdvantage 2015-08-27
Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 04:37am 26 Aug 2015
Copy link to clipboard 
Print this post

UPDATE:

I now have the SHIFT and CAPS LOCK features working, along with the CAPS LOCK LED.





...and here is the really un-sophisticated tester code:

EDIT: Removed Code Window. Forum code was mis-interpreting my square-brackets I was using in my commented code. I will upload a link shortly, where you can download the BAS file...

2015-08-26_144209_BlueKB_003.zip Edited by Grogster 2015-08-27
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:13am 26 Aug 2015
Copy link to clipboard 
Print this post

Good progress!

Would you be able to test my version of the matrix scan on your setup?
I used your pins so no need to rewire. I switched the columns to input and the rows to output to match the one i am making.
This is just written in notepad without any testing. You know what they say. "It should work". :)

Main will detect any key press. (This would be nice if it can be done with an interrupt.
Main then calls scanmatrix to find out which keys were pressed.

Each key should produce an output with a RowNumber,ColumNumber followed by the character from the lookup table. The lookup table needs to be updated with the right values. Now they are just placeholders. The lookup table needs to be extended for key combinations with CTRL, ALT, SHIFT, FN.
If this works then any matrix can be used by changing the lookup table.
[code]
Dim Lookup(8) as string * 8
Lookup(0) = "abcdefgh"
Lookup(1) = "ijklmnop"
Lookup(2) = "qrstuvwx"
Lookup(3) = "yz123456"
Lookup(4) = "7890-=[]"
Lookup(5) = "\;',./~!"
Lookup(6) = "@#$%^&*("
Lookup(7) = ")_+{}|:" + CHR(34)
Lookup(8) = "<>?ABCDE"

C0=15:C1=16:C2=17:C3=21:C4=22:C5=23:C6=24:C7=26 'Setup columns
R0=02:R1=03:R2=04:R3=05:R4=06:R5=07:R6=09:R7=10:R8=25 'Setup rows
SetPin C0,din,pullup:SetPin C1,din,pullup:SetPin C2,din,pullup
SetPin C3,din,pullup:SetPin C4,din,pullup:SetPin C5,din,pullup
SetPin C6,din,pullup:Setpin C7,din,pullup

Setpin R0,dout:SetPin R1,dout:SetPin R2,dout:SetPin R3,dout
SetPin R4,dout:SetPin R5,dout:SetPin R6,dout:Setpin R7,dout
Setpin R8,dout

Delay = 50
DebounceDelay = 10

DEBUG = 1

'MAIN
Do
SetRow(-1)
PAUSE Delay
If ReadColumns() <> 255 then
print ScanMatrix$()
endif
Loop


SUB SetRow(value)
'Row pins 2,3,4,5,6,7,9,10,25
if value = -1 then
'Set all bits to 0. This will allow detecting any keypress
PORT(2,7,10,1,25,1) = 0
else
'Set a bit to 0
PORT(2,7,10,1,25,1) = 512 - (2 ^ value)
endif
END SUB

FUNCTION ReadColumns()
LOCAL FirstScan, ScanCode

'Read the column port and do a simplistic debounce
'Column pins 15,16,17,21,22,23,24,26
FirstScan = PORT(15,3,21,4,26,1)
PAUSE DebounceDelay
ScanCode = PORT(15,3,21,4,26,1)
If FirstScan <> ScanCode then ScanCode = 255
ReadColumns = ScanCode
END FUNCTION

FUNCTION ScanMatrix$()
LOCAL K$,Keys$, RowNumber, ScanCode

Keys$ = ""
RowNumber = 0
Do
SetRow(RowNumber)
ScanCode = ReadColumns()

'Decode the ScanCode
if ScanCode <> 255 then
'One or more keys were pressed
if DEBUG = 1 then PRINT ScanCode
for ColumnNumber = 0 to 7
'Check every bit in the column
if (Scancode OR (255 - (2 ^ ColumnNumber))) = 0 then
if CAP = 0 AND SFT = 0 then
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
else
'For now use the same lookup table, use RowNumber + 9 when debugged
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
endif
if DEBUG = 1 then
PRINT RowNumber + "," + ColumnNumber + "=>" + K$
endif
Keys$ = Keys$ + K$
endif
next
endif

RowNumber = RowNumber + 1
Loop until RowNumber > 8

ScanMatrix$ = Keys$

END FUNCTION
[/code]

Edited by TZAdvantage 2015-08-27
Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 07:32pm 26 Aug 2015
Copy link to clipboard 
Print this post

Hi. Result:





EDIT: Ignore - should be CHR$(34).....

EDIT: Port errors:



Edited by Grogster 2015-08-28
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6268
Posted: 07:48pm 26 Aug 2015
Copy link to clipboard 
Print this post

Try

PORT(2,6,9,2,25,1)


JimEdited by TassyJim 2015-08-28
VK7JH
MMedit
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:59pm 26 Aug 2015
Copy link to clipboard 
Print this post

Thanks for testing! Some stupid little mistakes.
That PORT command is fighting me all the time. I would have preferred just a list of pins instead of the pin,count pairs just like in the other commands like LCD and KEYPAD.

I just got some mail. This weekend will be fun.

Edited by TZAdvantage 2015-08-28
Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 10:24pm 26 Aug 2015
Copy link to clipboard 
Print this post

Here is the result of the test once I change the port command to Jim's suggestion:




Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:43pm 26 Aug 2015
Copy link to clipboard 
Print this post

I think i know the bug. I got my AND and ORs wrong.

What do you get when you change
[code]
if (Scancode OR (255 - (2 ^ ColumnNumber))) = 0 then
[/code]
into this:
[code]
if (Scancode AND (2 ^ ColumnNumber)) = 0 then
[/code]

Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 11:08pm 26 Aug 2015
Copy link to clipboard 
Print this post

Acknowledged - standby.....
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 11:13pm 26 Aug 2015
Copy link to clipboard 
Print this post

Results:





This is with the change you requested - OR changed to AND on line 75.
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:29pm 26 Aug 2015
Copy link to clipboard 
Print this post

Well obvious something is not working as expected.
What should happen is that after a keypress is detected it goes into the ScanMatrix$ function which starts a full scan.

It does see the keypress but it does not determine which column.
The code should test each bit in the ScanCode for a 0.
If it finds one then you have a row and column number.
That IF statement after the FOR is not doing what i expected. I tested that in MMBasic for DOS and it worked. Is there a difference in versions when 64 bit integers were introduced?

If i just use
[code]
print (239 AND (2 ^ 4))
[/code]
i get 0, and that is right.
I'm puzzled.....




Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 12:16am 27 Aug 2015
Copy link to clipboard 
Print this post

Grogs,

Can you please post TZA's code with all the updates you have made from suggestions posted. This is so we can eliminate any 'silly' typo's/errors i.e. have you changed both PORT commands in the SetRow sub (if not then it won't work).

TZA,

I think you may find that in you SetRow sub, then the following line (in the ELSE section):
PORT(2,7,10,1,25,1) = 512 - (2 ^ value)

needs to be ... = 511 - (2 ^ value) otherwise you have too many 0's!!

ALSO

SetRow(RowNumber) in ScanMatrix (under the first DO) you will need to change to SetRow(RowNumber + 1)

Make these two changes and you should progress further . . .

WW

These two changes simply give you a correct value to compare with - there may still be other issues which will be easy to detect once the most recent version of TZAs code is posted


Edited by WhiteWizzard 2015-08-28
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 12:58am 27 Aug 2015
Copy link to clipboard 
Print this post

Here is a little idea: command buffer built into the keyboard. If the keyboard knows when the mite is in command mode, it could replace up and down arrows with previously entered command lines
http://rittle.org

--------------
 
     Page 6 of 14    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025