![]() |
Forum Index : Microcontroller and PC projects : Keyboard for Micromite Plus
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2949 |
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 ZealandPosts: 9586 |
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: ThailandPosts: 2209 |
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 KingdomPosts: 2932 |
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 AfricaPosts: 280 |
Well done Grog ![]() 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 KingdomPosts: 2932 |
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 ZealandPosts: 9586 |
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. ![]() 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: ThailandPosts: 2209 |
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. ![]() Microblocks. Build with logic. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9586 |
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 Smoke makes things work. When the smoke gets out, it stops! |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
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] Microblocks. Build with logic. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9586 |
Hi. Result: ![]() EDIT: Ignore - should be CHR$(34)..... EDIT: Port errors: ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6268 |
Try PORT(2,6,9,2,25,1) Jim VK7JH MMedit |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
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. Microblocks. Build with logic. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9586 |
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: ThailandPosts: 2209 |
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 ZealandPosts: 9586 |
Acknowledged - standby..... Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9586 |
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: ThailandPosts: 2209 |
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 KingdomPosts: 2932 |
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 |
||||
kiiid Guru ![]() Joined: 11/05/2013 Location: United KingdomPosts: 671 |
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 -------------- |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |