Re-purposing a USB keyboard matrix controller - momentary switch ideas - Page 1
Forum section: electronics / beginners

author: JasonStonier
author_rank: Newbie
timestamp: December 06, 2020, 01:31:34 pm
content: Background - 25 years ago I had an A-Level in electronics but I've only just come back to real electronics as a hobby and I'm trying to re-skill - so I'm not a complete beginner, but there are an awful lot of gaps in my knowledge.TL/DR - I need to find a way to use a reed switch as a momentary switch to give a pulse when the field is applied, and another pulse when it is removed.I'm trying to build a chess computer and ideally I want to use reed switches to detect the piece on the board. I also want to use a USB keyboard PCB as the matrix scanner for the board. The Keyboard PCB has 8x 'outputs' which are at 5V, and 18 'inputs'. Connecting an output to an input closes one matrix node and types a letter.What I want to be able to do is close the node with a reed switch by placing a magnetic puck on it, but the keyboard scanner can only detect 4 keys simultaneously, so the closed contact needs to be momentary for each reed switch.I've tried an edge-detect circuit using an XOR with an R-C combination to give a 200ms pulse on each of the rising and falling edges - and for blipping an LED it works fine, but doesn't work on the keyboard scanner - I'm presuming because it's buffering the connection between 'output' and 'input'. Without knowing exactly how the scanner works, it's hard to say. But what is clear is that I need a pure closed contact from 'output' to 'input' for it to work.I'm not asking for anyone to design a circuit for me - but I'm looking for some pointers of things I can research to solve this problem myself.I'm wondering about using the XOR circuit to drive a solid state relay to close the contact - but also wondering if there's a more elegant way?

author: Ian.M
author_rank: Super Contributor
timestamp: December 06, 2020, 01:49:59 pm
content: Quote from: JasonStonier on December 06, 2020, 01:31:34 pmYes, *DONT* use a recycled USB keyboard PCB!If USB connectivity is essential, e.g. because you want to use a PC chess program, consider using an Arduino Leonardo or other ATmega32U4 based Arduino, as they can easily be programmed to emulate just about any USB HID device, including keyboards. Seehttps://www.arduino.cc/reference/en/language/functions/usb/keyboard/The 'trigger' condition for each keypress would then be fully under your control, so responding to change of reed switch state, rather than simple contact closure wouldn't be an issue as long as each switch has a diode in series so all can be detected independently irrespective of the state of other switches in the matrix.

author: JasonStonier
author_rank: Newbie
timestamp: December 06, 2020, 06:48:40 pm
content: Quote from: Ian.M on December 06, 2020, 01:49:59 pmYou're obviously absolutely right, and I deserved that after putting the word "elegant" anywhere near my cludge of a proposed architecture.Problem is, I've got some sort of disorder that makes it impossible for me to stare at my box of random salvage for any length of time without wondering "now how could I repurposethatthing into something cool...". This project came about because I was staring at a salvaged USB keyboard PCB and wondering what I could use it for.I'm going to have one more go at it using a transistor for the switch, and if that fails I'll turn the keyboard matrix into a steampunk keyboard and use an arduino for the chess computer.Thanks for the reply, I do appreciate it

author: Renate
author_rank: Super Contributor
timestamp: December 07, 2020, 12:26:07 pm
content: I scavenge the little boards (and USB cable/plug) out of trashed keyboards when I can.Even the most disgusting keyboard has a clean PCB.They're usually really small with glopped-on chip.But... I only use them for things like PAGE DOWN foot switches or something simple.And you know what? They aren't even good for that.For one thing, they present themselves as a QWERTY keyboard.If you plug it into an Android the on-screen keyboard won't pop up(Unless you use an obscure option, in which case it will also still pop up when you use a Bluetooth keyboard.)If you make your own USB HID keyboard you can specify in the HID report descriptor which subset of keys you handle.If you don't have the lettter 'Q' then Android won't consider it a QWERTY.So, back to the chess board.If you're talking reed switches, the layout lends itself well for an 8x8 matrix with diodes.If you talking Hall effect you'll have to use some sort of I/O expander or parallel/serial shift register.I'd just send 8 bytes of the current status in a custom HID report.The bigger question is generic chess piece detection vs. specific chess piece.With only generic detection a computer will be able to follow a game, but it won't be able to start by itself from the middle of a game or problems.A computer program will need to be clever to figure out what is going on sometimes, e.g. castleing.Are there any standards for this?Have you seen this:DGT e-BoardI get a laugh out of the fact that they have only recently switched from serial to USB.