Page 1 of 2

PS/2 keyboard hookup with microcontroller

Posted: 13 May 2018, 22:17
by marcelk
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.
IMG_3302-1-768x522.jpg
IMG_3302-1-768x522.jpg (31.15 KiB) Viewed 6944 times
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

Posted: 14 May 2018, 12:57
by at67
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

Posted: 04 Jun 2018, 23:33
by marcelk
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:

IMG_3606.jpg
IMG_3606.jpg (185.11 KiB) Viewed 6864 times

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

Posted: 05 Jun 2018, 15:50
by marcelk
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:

IMG_3614.jpg
IMG_3614.jpg (120.34 KiB) Viewed 6830 times

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
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.

Re: PS/2 keyboard hookup with microcontroller

Posted: 05 Jun 2018, 18:15
by WattSekunde
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... :lol: 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$
The Gigatron receives the bytes (green line) and then stays in "Ready to load".

Re: PS/2 keyboard hookup with microcontroller

Posted: 05 Jun 2018, 18:57
by marcelk
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.
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)

Also made an issue for it.

Re: PS/2 keyboard hookup with microcontroller

Posted: 05 Jun 2018, 22:23
by WattSekunde
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

Re: PS/2 keyboard hookup with microcontroller

Posted: 06 Jun 2018, 21:54
by marcelk
I played with the DigiSpark about two years ago.

IMG_3642.jpg
IMG_3642.jpg (153.35 KiB) Viewed 6786 times

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:

IMG_3655.jpg
IMG_3655.jpg (128.8 KiB) Viewed 6786 times

The cut cable comes from one of our ditched game controllers with incompatible signals. There is nothing standardised with these famicom-like controllers.

Re: PS/2 keyboard hookup with microcontroller

Posted: 07 Jun 2018, 17:49
by marcelk
IMG_3661.jpg
IMG_3661.jpg (84.22 KiB) Viewed 6757 times
IMG_3659.jpg
IMG_3659.jpg (80.72 KiB) Viewed 6757 times
Hookup
Hookup
IMG_3657.jpg (141.47 KiB) Viewed 6757 times

Re: PS/2 keyboard hookup with microcontroller

Posted: 07 Jun 2018, 18:20
by marcelk
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...