PS/2 keyboard hookup with microcontroller
Forum rules
Be nice. No drama.
Be nice. No drama.
PS/2 keyboard hookup with microcontroller
The Terminal.ino sketch in my GitHub repository can now do this:
https://www.youtube.com/watch?v=f9MukNFpffQ
The Arduino is a bit overkill. An ATtiny85 should be able to do the job equally well.
I feel this is the most acceptable route on the short term for keyboard hookup.
The controller could do cute things like mapping arrow keys to game controller signals.
And it could map Ctrl-Alt-Del to a 2 second holding of the [Start] button.
And perhaps some escape sequence to enter a monitor program. Many ideas...
https://www.youtube.com/watch?v=f9MukNFpffQ
The Arduino is a bit overkill. An ATtiny85 should be able to do the job equally well.
I feel this is the most acceptable route on the short term for keyboard hookup.
The controller could do cute things like mapping arrow keys to game controller signals.
And it could map Ctrl-Alt-Del to a 2 second holding of the [Start] button.
And perhaps some escape sequence to enter a monitor program. Many ideas...
Re: PS/2 keyboard hookup with microcontroller
This seems to be the simplest and most non intrusive method, compared to modifying Gigatron hardware and firmware and then most likely suffering from missing features and/or performance issues.
Re: PS/2 keyboard hookup with microcontroller
I spent some time today on the ATtiny85 route. It is not stable yet, but there is clearly signal processing going on. In fact, on the scope it looks all good, but for some reason the wrong keys get through most of the time. It shouldn't be a major leap from here.
I'm using the PS2keyboard module for Arduino so we can reuse all their logic and optional keymaps. This module uses the Arduino's attachInterrupt() which isn't supported (and doesn't work) for the ATtiny. But there is a workaround by setting up an ISR yourself. You have to do this anyway because the ATtiny85 only has simple "pin changed" interrupts. So when triggered the new ISR checks if it got a rising or falling edge. Only on a falling edge it calls the interrupt handler that keyboard.begin() failed to install, and with that all is well again.
The microcontroller must be programmed to run at 8 MHz because at 1 MHz it is too slow to catch any keystrokes. Yet another confirmation that the PS/2 protocol is not nice for simple designs.
Preliminary code is in GitHub. My schematic is not too special:
The only mildly interesting thing is that the Gigatron provides all power. Its multifuse is big enough that this doesn't cause any issue. To be continued...
I'm using the PS2keyboard module for Arduino so we can reuse all their logic and optional keymaps. This module uses the Arduino's attachInterrupt() which isn't supported (and doesn't work) for the ATtiny. But there is a workaround by setting up an ISR yourself. You have to do this anyway because the ATtiny85 only has simple "pin changed" interrupts. So when triggered the new ISR checks if it got a rising or falling edge. Only on a falling edge it calls the interrupt handler that keyboard.begin() failed to install, and with that all is well again.
The microcontroller must be programmed to run at 8 MHz because at 1 MHz it is too slow to catch any keystrokes. Yet another confirmation that the PS/2 protocol is not nice for simple designs.
Preliminary code is in GitHub. My schematic is not too special:
The only mildly interesting thing is that the Gigatron provides all power. Its multifuse is big enough that this doesn't cause any issue. To be continued...
Re: PS/2 keyboard hookup with microcontroller
Got it working now. Even 8 MHz is too slow for the old code and all bits to the Gigatron were shifted by one position. The Arduino ran at 16 MHz and is fast enough. I solved it by rearranging the bit-banging code and now it looks fine. I hope I didn't break the rest of the functionality of LoaderTest.ino
Demonstration video: https://youtu.be/kt3fdtl73NM
The little cheater still on its breadboard:
The sketch maps some special keys as follows:
These will change without any notice
P.S.: As you can see Snake doesn't play smooth yet. Perhaps because the controller sends the codes only for one frame, and Snake might miss that. I did that this way in order not to miss any key release events, but there is no real need to worry about those yet.
Demonstration video: https://youtu.be/kt3fdtl73NM
The little cheater still on its breadboard:
The sketch maps some special keys as follows:
Code: Select all
Arrow keys : Game controller arrow buttons
TAB : Game controller [A] button
ESC : Send Terminal.gt1 (only makes sense in Loader)
PAGE DOWN : Game controller [Select] button (changes video mode)
PAGE UP : Reset Gigatron
P.S.: As you can see Snake doesn't play smooth yet. Perhaps because the controller sends the codes only for one frame, and Snake might miss that. I did that this way in order not to miss any key release events, but there is no real need to worry about those yet.
-
- Posts: 24
- Joined: 22 May 2018, 10:25
Re: PS/2 keyboard hookup with microcontroller
Very nice and minimalistic solution. Maybe a little bit brute force.
Until I am get into GCL I tried to compile and transfer your little Terminal App called Main.gcl. Compiling worked well but transfer doesn't. All other GCLs in gigatron-rom-master I tried in the same environment worked well. Maybe a simple thing? But as a GCL newbie I don't see the obvious... So before I dig into the gt1 file format...
The Gigatron receives the bytes (green line) and then stays in "Ready to load".
Until I am get into GCL I tried to compile and transfer your little Terminal App called Main.gcl. Compiling worked well but transfer doesn't. All other GCLs in gigatron-rom-master I tried in the same environment worked well. Maybe a simple thing? But as a GCL newbie I don't see the obvious... So before I dig into the gt1 file format...
Code: Select all
devmac:gcl mk$ ./makeGCL Main
Compiling file Main.gcl label Main
Segment at 0600 size 256 used 256 unused 0
Variables count 8 bytes 16 end 0040
Symbols Char Newline Pos PrintChar fontData i p serialLast
Success ROM 0000-0107
Create file Main.gt1
devmac:gcl mk$ ./sendGT1 Main
Connecting to /dev/tty.usbmodem1A13311
Wait for prompt...
Resetting Gigatron
Starting Loader
Sending program 'Main.gt1'
...Failed: Timeout error (no data)
devmac:gcl mk$
- Attachments
-
- Main_gt1.jpg (83.88 KiB) Viewed 6999 times
Re: PS/2 keyboard hookup with microcontroller
It looks I broke our "compiler" at some point towards making it independent. This program doesn't load from the standard address $0200 but at $0600. That is just a hack because I didn't want to cross a page boundary for just a few bytes (which will be inevitable to do when extending it even more). The gt1 file maker spits out a wrong object file for this case. I just checked-in a manually corrected GT1 file for now... (just a conversion of Terminal.h)Until I am get into GCL I tried to compile and transfer your little Terminal App called Main.gcl. Compiling worked well but transfer doesn't.
Also made an issue for it.
-
- Posts: 24
- Joined: 22 May 2018, 10:25
Re: PS/2 keyboard hookup with microcontroller
Thanks!
Did you know about the Digispark? A nice little PCB with USB plug and Attiny85 16.5MHz.
That could be the perfect interface board to connect USB or PS2 to the Gigatron. There are also dozens of cheap clones around. The only downside it's a bit tricky to get the tools into the Arduino IDE. As far as I know is the Digispark in the Arduino IDE only up to 1.6.5R5 integrated. That's why I use this Version in parallel.
http://digistump.com/products/1
Did you know about the Digispark? A nice little PCB with USB plug and Attiny85 16.5MHz.
That could be the perfect interface board to connect USB or PS2 to the Gigatron. There are also dozens of cheap clones around. The only downside it's a bit tricky to get the tools into the Arduino IDE. As far as I know is the Digispark in the Arduino IDE only up to 1.6.5R5 integrated. That's why I use this Version in parallel.
http://digistump.com/products/1
Re: PS/2 keyboard hookup with microcontroller
I played with the DigiSpark about two years ago.
I also bricked one or two by destroying their boot loader I believe, and I couldn't figure out how to bring them back to life. I find it easier now to program the bare ATtiny85. There is more than one way to skin a cat. I'm toying with these parts now:
The cut cable comes from one of our ditched game controllers with incompatible signals. There is nothing standardised with these famicom-like controllers.
I also bricked one or two by destroying their boot loader I believe, and I couldn't figure out how to bring them back to life. I find it easier now to program the bare ATtiny85. There is more than one way to skin a cat. I'm toying with these parts now:
The cut cable comes from one of our ditched game controllers with incompatible signals. There is nothing standardised with these famicom-like controllers.
- Attachments
-
- IMG_3655.jpg (128.8 KiB) Viewed 6963 times
Re: PS/2 keyboard hookup with microcontroller
As said, the software needs improvement to deal with longer key presses. My ambition is that Snake, Racer and the setting of the clock in Mandelbrot should all work in this setup. I don't know if that is all realistic, and it very likely requires total assimilation of the PS2keyboard module. So this is several evenings of software hacking to finish it. But at least the concept works.
I built it on a small 1-inch protoboard from here: http://www.hobbytronics.co.uk/protoboard-1in
I got the PS/2 socket from a local electronics shop.
This thingy could become a small custom PCB... Something to put on Oshpark perhaps...
I built it on a small 1-inch protoboard from here: http://www.hobbytronics.co.uk/protoboard-1in
I got the PS/2 socket from a local electronics shop.
This thingy could become a small custom PCB... Something to put on Oshpark perhaps...