Jump to content
IGNORED

USB Keyboard Adapter w/Arduino style components


jedimatt42

Recommended Posts

I remember going to a workshop at OSCON where they talked about building a keyboard from scratch. It's been a couple years, but here's a link:

 

http://www.slideshare.net/obrajesse/building-a-keyboard-from-scratch

 

I wonder if that might help any.. the guy who did it has lots of experience, and had dozens of prototypes. Could probably pretty easily go the other way with translating USB signals on the keyboard to the standard on/off the TI is expecting on certain pins.

Link to comment
Share on other sites

I remember going to a workshop at OSCON where they talked about building a keyboard from scratch. It's been a couple years, but here's a link:

 

http://www.slideshare.net/obrajesse/building-a-keyboard-from-scratch

 

I wonder if that might help any.. the guy who did it has lots of experience, and had dozens of prototypes. Could probably pretty easily go the other way with translating USB signals on the keyboard to the standard on/off the TI is expecting on certain pins.

 

Those are interesting custom keyboards... the guy seems to be very intent on getting his thumbs more involved in the typing process. I'm quite content leaving them rested enough to focus on the space bar :)

 

It is cool to see how to craft a matrix keyboard though...

 

99% of going from the USB Host Shield input to the TI pins is actually easy. But then there are quirks, like not interfering with the built-in keyboard since TI's manufacturers left all the diodes out, or overriding the state of the inputs. Interfacing with the column scans. Overriding what seems like a straight forward mapping when you figure out that shift ' is really fctn p, and now your modifiers are all screwed up. And still being able to hold modifiers down. :)

 

Thankfully I'm starting with HID libraries that are pretty robust, but they are designed for driving an arduino... Setting the caps-lock on by default is an interesting challenge, as I have to compose a proper USB HID Report and send that back to the keyboard on the USB.

 

On the progress side, I have been able to get hot-plugging to work. ( unplugging and plugging in a keyboard without power cycling the TI ) That was huge! for usability.

 

-M@

Link to comment
Share on other sites

Today's efforts fixed caps-lock and num-lock on by default.

 

It is highly likely that the ability to hold a key down while the TI powers up may never work.. The USB initialization process seems to be too slow.

 

I have an UberGrom cartridge to test holding spacebar down for the recovery menu... But... drum role please... the TI is too fast! :)

 

Luckily the internal keyboard works fine in parallel for those special boot moments... Or, if you have a reset button wired up, that at least works for getting into the UberGrom while holding spacebar. I don't have any PEB equipment that cares about keyboard on powerup, so I don't know if they also work fine from a hard reset?

 

-M@

Link to comment
Share on other sites

Just a little update:

 

Last night I was working on joy1 support. Nothing checked in to git yet, but XBox pc or usb controllers connect up and I can get input from them. I haven't mapped it out to the TI yet, but I learned something along the way... I need to respect the USB spec's demand for capacitance at the host. I couldn't get the gamepads to recognize off of proven code from the USB Host shield library, until I added the required capacitance. The USB Keyboard I've been testing with, didn't care.

 

After adding them, I attached a Logitech Unifying Receiver and tried out the wireless keyboard. Which worked straight away. That did not require any software change. Which is what I expected, since I'm using the USB Boot keyboard protocol for when your PC doesn't have a driver loaded yet...

 

So, I'm close to wanting to get a prototype board made... I'm thinking of using the same kind of 16 pin connector ( 2x8 ) for the keyboard ribbon that the PIO PEB card uses.

 

I've also re-arranged the PCBoard layout so the programming port, and the USB Host port can both be easily exposed out the back or side of the console. That change is on github. That caused me to re-assign many of the gpio pins.

 

Another thing, I'd like input on is mapping the gamepad... I'm tempted to give it modes...

Some gamepads have a 'select' and others have a 'xbox' button.. pressing that followed by a direction on the dpad to select one of 4 modes. Of course, I'd be happy with a good definition for 1 mode...

 

Mode 1:

Left Joystick: Joystick 1

Right Joystick: arrow keys

Dpad: Joystick 1

Back: F9 - Back

Start: Enter

A: Fire

B: 1
X: 2

Y: 3

L1: F8 - Redo

L2:

R1: F6 - Proceed ?

R2:

 

I guess I'm aiming at a parsec mode :) Anyone have suggested alternatives?

Link to comment
Share on other sites

  • 2 weeks later...

post-42954-0-68735600-1444486399_thumb.jpg

 

Above is my paper layout, showing the expected parts overlayed on a printout of the pcboard.

 

I'm thinking it will fit nicely in the back left corner in either orientation ( side ports or back ports ) It should be thin enough to fit in many versatile places.

 

I've finally got my interfacing between the virtual keyboard state and the TI itself working correctly after realizing that columns 0-5 are on the octal decoder in the TI, and so transitions between the scan columns don't include an off and then an on, but rather a more instant switch from one column to another or to none. And that the caps-lock is not on the decoder, so it is the one column that is free to be on at the same time as the others.

 

That eliminated a key bounce behavior that always plagued '.' and '/' and if the Teensy's usb programming port was in Serial mode and connected, then occasionally any other key as well.

 

It also fixed a weird problem where pressing 3 to set lift to high in Parsec would also cause the ship to go up... which always caused me to crash into the refueling tunnel on the way out...

 

Separately, I do peek in on the high score thread, and so tried out Micro Pinball II. This exposed an odd behavior interacting with the zero key ( pull and release the ball ) where it would not release... I've got a fix for that.

 

I have a remaining interesting issue, I know how to work around, but am trying to find a solid generalized solution for. That is, it appears the TI won't finish resetting when I press Fctn=. This will give me something to learn how to use the oscilloscope. On the surface, it appears that no column change occurs, and so no change interrupt is generated in my teensy.

 

Focus wise, I'm backing off the usb-xbox controller thing... I'll leave the hardware set up for it, but I really want to get this hardware inside my console. Reprogramming it for a gamepad can happen easily enough after the fact.

 

-M@

  • Like 1
Link to comment
Share on other sites

Sounding really good! Since you're getting down to the wire, one thing I had a lot of trouble getting right was simple use of the arrow keys -- try typing in a few BASIC programs (including editing lines with lots of forward and back scrolling through the line - both tapping and holding the arrow keys). That was where I had the biggest issue with getting ref counts right. That, and typing apostrophe s ('s) quickly. :)

 

Great to see your progress! Congratulations!

Link to comment
Share on other sites

  • 4 weeks later...

I've noticed as you said, unexpected behavior when doing a lot of editing. Backspace is so naturally quick, but I have typing habits on a PC, such as pressing the next key before really releasing the backspace. And since the backspace maps to a modifier (fctn) and s, it acts like I'm holding down fctn,s, and the next key...

 

It was also pretty stable, power wise, but then after I put in the F18A, it wouldn't work. I solved that with some capacitors. But I don't really know what I'm doing with capacitors. Does anyone know a good technique to figure out how much is needed and where? Or a dummies intro to this?

 

Thanks,

-M@

Link to comment
Share on other sites

When you are ready to make your PCB, I recommend OSHpark (https://oshpark.com/) for getting a few boards. I used them for my initial beta F18A boards, for the F18A ADAM adapter, the BankSwitch Mini, and for a few other non-TI related projects. Cost is based on board size and something like my F18A board (~2" x 1.5") is about $8 per board.

You might also find the Keyboardio (http://shop.keyboard.io/) interesting. They had a kickstarter a while ago and I went to one of their cross-county events to try the keyboard in person. I backed them. Anyway, it is a good story and the keyboards should be really nice. The project prompted me to do some keyboard research and I learned that, sadly, PS2 keyboards are apparently better than USB keyboards; both on the keyboard and PC side of the connection. On the PC side it seems the USB key inputs are routed to the same circuits that directly accept the PS2 signals (probably for compatibility, which keeps the x86 architecture from ever getting better.)

Also, the USB keyboards don't respond as quickly as PS2 keyboards. All this info is a few months old in my head, so do your own research, I could certainly be getting parts of it wrong. However, I do have a problem with modern keyboards when following a capital letter with a lowercase letter. The second letter is almost always capitalized as well, i.e. the keyboard/computer still had the shift-key in the "pressed" state when the second keystroke comes in. This pisses me off to no end. Modern keyboards and computers should *easily* be faster than any human typist.

USB and PS2 keyboards also have a maximum number of keys they can track simultaneously, something around six I think. People who need more "chording" (like for music and such) apparently buy special keyboards that support more simultaneous key presses. The Keyboardio has claimed to be addressing this problem as well. Modern keyboards also have simultaneous key limits because like the TI's keyboard, they don't have the required diodes across each switch to completely isolate the connection.

I'm not sure why adding the F18A to your system would affect your keyboard interface. When you say "I solved that with some capacitors", what exactly did you do? Where did you add the caps? I don't have any good capacitor references, but I'm sure a quick Internet search will give you more info than you care to know. But you can get into trouble really fast with caps if you don't understand what you are doing with them.

I feel your pain on the "start up" issue. The F18A has the same problem on some systems because it takes about 100ms to load its bit-stream from Flash. The 99/4A has a relatively long power-on reset though (compared to some systems), and you have about 150ms to 200ms to get your device up an running before the 99/4A comes out of reset. Of course you have to wait for the keyboard to power up and initialize too.

 

I just did a search to refresh my memory. This is a good article (http://www.tomshardware.com/reviews/mechanical-switch-keyboard,2955-5.html) about PS2 and USB keyboards and their differences. Technically, PS2 keyboards are superior IMO. You would think the tech industry would be able to get keyboards right by now... Sad, very sad.

 

Edited by matthew180
Link to comment
Share on other sites

When you are ready to make your PCB, I recommend OSHpark (https://oshpark.com/) for getting a few boards. I used them for my initial beta F18A boards, for the F18A ADAM adapter, the BankSwitch Mini, and for a few other non-TI related projects. Cost is based on board size and something like my F18A board (~2" x 1.5") is about $8 per board.

I've looked at OSHpark a bit. It looked promising. It's a bit of a leap to take :) But sometimes I think the instability I experience is the wiggly wires in the breadboard.

 

You might also find the Keyboardio (http://shop.keyboard.io/) interesting. They had a kickstarter a while ago and I went to one of their cross-county events to try the keyboard in person. I backed them. Anyway, it is a good story and the keyboards should be really nice. The project prompted me to do some keyboard research and I learned that, sadly, PS2 keyboards are apparently better than USB keyboards; both on the keyboard and PC side of the connection. On the PC side it seems the USB key inputs are routed to the same circuits that directly accept the PS2 signals (probably for compatibility, which keeps the x86 architecture from ever getting better.)

Keyboardio looks very related to some 'build your own keyboard' link that was posted earlier. I still can't believe someone wants to hit the modifiers with their thumbs... But it is cool. I believe in personalized computers. I'm a lefty in a righty world, so I respect the totally custom layout. But I actually enjoy a variety of keyboards, from my Logitech K750, which I'm surprised I like, to my Happy Hacking Keyboard Lite. I use too many different computers between work and home, that I need to customize them back to what my fingers know.

 

 

USB and PS2 keyboards also have a maximum number of keys they can track simultaneously, something around six I think. People who need more "chording" (like for music and such) apparently buy special keyboards that support more simultaneous key presses. The Keyboardio has claimed to be addressing this problem as well. Modern keyboards also have simultaneous key limits because like the TI's keyboard, they don't have the required diodes across each switch to completely isolate the connection.

I haven't seen anything in the USB keyboard 'boot' protocol that inherently limits the number of simultaneous keys, but it is those missing diodes, and how the matrix is wired up to the microcontroller in the keyboard that encodes it out to USB that is the problem. The makers have to balance consumer desire for cheap against the desire for quality.

 

I'm not sure why adding the F18A to your system would affect your keyboard interface. When you say "I solved that with some capacitors", what exactly did you do? Where did you add the caps? I don't have any good capacitor references, but I'm sure a quick Internet search will give you more info than you care to know. But you can get into trouble really fast with caps if you don't understand what you are doing with them.

I'm pretty sure I don't know what I'm doing with them, which is why I'm hoping to find something that can change me. I'd like to understand there role, and how to determine the correct size for an application.

 

I don't really think the F18A did anything but mix up the power demands a little. It appeared as though the USB host control chip was continuously resetting, very rapidly. Normally, the guy who makes the USB Host shield, cheats on the 5v power to the usb device, and puts a capacitor (200uf) across the 3.3v/gnd supply from the teensy to the USB Host shield. But that was said to be to protect the shield causing undervoltage on the teensy and resetting it when the USB device is powered on. This is a 3.3v cheat that works with some usb devices.

 

But I'm not powering the USB device off the 3.3v. I cut the connection between the VBUS and the 3.3v, and supply the 5v to VBUS like it is supposed to be for the USB standard. In the beginning, I had just the teensy and usb host shield. 5v wired to VBUS, 5v wired to teensy VCC, and the teensy's 3.3v out supplying the usb host shield's 3.3v in requirement. This worked fine for a cheap little wired USB keyboard.

 

But then I ordered a wireless to test. And there was no joy. I read more, and experimented. The USB standard expects a host port to provide a certain amount of capacitance, but most host ports provide grossly more than the spec calls for. I think the spec wanted 150uf as a minimum. I worked my up to a 330uf capacitor at VBUS on the 5v line, and then the wireless unifying receiver from Logitech worked. This has been pretty stable for a while now, except I seem to have to wiggle the wiggly breadboard wires.. :(

 

Ok, so enter the F18A. Like I said, I don't think it is anything bad with the F18A, it is just exposing that I get pretty far without hard knowledge :) So, in the 3.3v USB power cheat it was common to have a capacitor between the USB Host and the 3.3v supply from the teensy. So I put a 100uf cap there. That didn't seem to work.. I left it there, and then put another 100uf cap on the 5v line to the teensy, this happens to be in parallel with the supply to VBUS ( so there is also a 330uf cap downstream )... This works better, but when cold, still seems to need a few restarts to get it working. Then after it has been live for a while, I can take those two 100uf caps out, and power down, pause for a bit, and power back on and it all seems to work.

 

So, I've got to learn something to figure out how to make this stable. I figured the 100uf wouldn't hurt as a greater value was not unheard of. Although I feel like the 330uf on the VBUS should be providing the undercurrent protection when the USB device powers up, so the 100uf shouldn't be necessary, or should be something smaller. And the last one I put in feels like it is just a stab in the dark.

 

I'm searching the internet wrong, cause I'm not finding anything that describes how to choose to influence my circuit. I am assuming my application is about smoothing out the voltage. I just realized I haven't tried youtube... :) Anyway, if anyone has the correct words to google, or any detail that I'm headed in the completely wrong direction, that input is welcome.

 

I feel your pain on the "start up" issue. The F18A has the same problem on some systems because it takes about 100ms to load its bit-stream from Flash. The 99/4A has a relatively long power-on reset though (compared to some systems), and you have about 150ms to 200ms to get your device up an running before the 99/4A comes out of reset. Of course you have to wait for the keyboard to power up and initialize too.

 

I just did a search to refresh my memory. This is a good article (http://www.tomshardware.com/reviews/mechanical-switch-keyboard,2955-5.html) about PS2 and USB keyboards and their differences. Technically, PS2 keyboards are superior IMO. You would think the tech industry would be able to get keyboards right by now... Sad, very sad.

I think the tech industry is just trying to eliminate them with touch screens. :) I joke... I hope.

 

-M@

Link to comment
Share on other sites

In other news, I just got a couple usb host shields from DuinoFun.com that appear to be nearly identical to the Circuits@Home device I have used in my prototype. It is slightly modified, in that it doesn't have the solder pads there are traces you might cut for certain applications. But it is still clear where to cut to isolate the VBUS 5v supply to the USB device.

 

Supply chain on this piece is much better. About 1 week for delivery, instead of 30days for the other.

 

And I've got a couple Teensy 3.2 boards, which is for my purposes completely pin/software compatible with the Teensy 3.1 I used.

 

So I believe supply of these breakout boards I'm using will be healthy. Just something I was worried about.

Link to comment
Share on other sites

Personally I would not use that UHS mini for a USB host, too risky tying the USB +5 VBUS supply to a constant source. A USB Host should detect that a device needing power is connected and switch the VBUS accordingly (see the example schematic on pg. 26 of the MAX3421E datasheet.) Also, tying the MAX3421E 3.3V power to the USB VBUS *at all* is not a good idea, ever, IMO.

 

You also have to remember that the 5V supply current being provided to the 99/4A keyboard connector is limited. You are also driving the USB bus with that, and USB peripherals can expect to get up to 500ma from the bus (in addition to all the chips you are trying to power), which the keyboard connector may not be able to provide.

 

As for capacitors, they can be used in many ways and you should really try to get an understanding of them. Capacitors don't "give" capacitance to a circuit like a regulator provides current. It does not work that way. Capacitance is a function of a device, which can be a capacitor, but it can also be just a pair of wires, traces on a circuit board, the space between two resistors, etc. Capacitors can be used to couple signals between circuits, used in signal filters, as timers, as small batteries, etc. Lots of possibilities.

 

When you see a capacitor between a power supply pin and ground, that is typically being used as a small filter / battery. Typically they are physically located close to the Vcc pin on a device to provide a little extra current in a digital system that can have lots of digital signals switching rapidly. Regulators will almost always have capacitors on their inputs and output which act as filters. In your circuit, the use of capacitors is going to be limited to these two cases. The circuit for the USB bus itself is already implemented, and any discussion of capacitance in the USB spec is mostly likely related to the d+ and d- lines and not the VBUS power.

 

Of course all this info is a heavy simplification and generalization. But just searching for "understanding capacitors" or "capacitors in digital circuits", etc. should get you a lot of info. You can also search for "electronic filters", "power supply basics", etc. to get an understanding of their use in power supplies and such.

Edited by matthew180
Link to comment
Share on other sites

Personally I would not use that UHS mini for a USB host, too risky tying the USB +5 VBUS supply to a constant source. A USB Host should detect that a device needing power is connected and switch the VBUS accordingly (see the example schematic on pg. 26 of the MAX3421E datasheet.) Also, tying the MAX3421E 3.3V power to the USB VBUS *at all* is not a good idea, ever, IMO.

I agree. The creator of the USB Host mini ships with the 3.3v going to the USB +5 VBUS output, but I cut that trace and provide the TI's powersupply +5v to the USB VBUS. This is where I attempted to follow the USB Host mini howto page and provide some substantial capacitance at the VBUS. It is proving unstable. I'll go read the MAX3421E datasheet. I keep having this nagging feeling, I need to learn to do surface mount, and skip this USB Host mini. It takes around a month to get one, or you go the knock-off route, which seems questionable.

 

As unstable as it is, once it is up and running, I'm able to use it all day long. But ignoring that USB handshake if you will for power, sounds like a good place to narrow in on why my adapter's boot up is unpredictable. Thanks!

 

You also have to remember that the 5V supply current being provided to the 99/4A keyboard connector is limited. You are also driving the USB bus with that, and USB peripherals can expect to get up to 500ma from the bus (in addition to all the chips you are trying to power), which the keyboard connector may not be able to provide.

I am not driving the usb bus with anything from the TI keyboard connector. Those lines are just going to digital gpio lines on a "Teensy 3.1.", I power the Teensy off the +5v on the TI power supply, and that powers the USB Host mini board off of it's 3.3v power output. The 3.3v is disconnected from the USB +5 VBUS with an exacto-knife. And the +5v VBUS is fed again off the TI power supply. It seemed reasonable :) except for the part where I am not switching the VBUS on request.

 

As for capacitors, they can be used in many ways and you should really try to get an understanding of them. Capacitors don't "give" capacitance to a circuit like a regulator provides current. It does not work that way. Capacitance is a function of a device, which can be a capacitor, but it can also be just a pair of wires, traces on a circuit board, the space between two resistors, etc. Capacitors can be used to couple signals between circuits, used in signal filters, as timers, as small batteries, etc. Lots of possibilities.

 

When you see a capacitor between a power supply pin and ground, that is typically being used as a small filter / battery. Typically they are physically located close to the Vcc pin on a device to provide a little extra current in a digital system that can have lots of digital signals switching rapidly. Regulators will almost always have capacitors on their inputs and output which act as filters. In your circuit, the use of capacitors is going to be limited to these two cases. The circuit for the USB bus itself is already implemented, and any discussion of capacitance in the USB spec is mostly likely related to the d+ and d- lines and not the VBUS power.

 

Of course all this info is a heavy simplification and generalization. But just searching for "understanding capacitors" or "capacitors in digital circuits", etc. should get you a lot of info. You can also search for "electronic filters", "power supply basics", etc. to get an understanding of their use in power supplies and such.

Thanks! That should give me a lot to chew on.

Link to comment
Share on other sites

 

 

I am not driving the usb bus with anything from the TI keyboard connector.

 

Yeah, there's no power on the TI keyboard connector, it was a pain in my butt too, since it prevents a single-connection replacement. It's nothing but the row/column lines to the switch matrix.

Link to comment
Share on other sites

  • 2 months later...

On January 1st, I finally ordered some trial boards from OSH Park. Then I finally rewrote the keyboard input software to stop being glitchy and support holding modifiers down by themselves, and fixed all that shift-locky nonsense I was getting with my earlier brute force code. I spent the day after that typing in most of the programs from Buck's "programs" thread, without issue. That code is all up on github now.

 

I got the boards today. So... here are some new images.

 

https://goo.gl/photos/xhLKCTwCPuAeUbP86

The assembled item:

 

post-42954-0-86439300-1452929376_thumb.jpg

 

Connected to the TI:

 

post-42954-0-21792100-1452929537_thumb.jpg

 

I've also had success testing with my KVM. The KVM is cheap, so it actually relies on USB hot-plug behavior. Since my board is coded to go into a slow boot loop if it loses the USB device, this worked out fine.

 

Next step is to stuff it into the TI.

 

-M@

  • Like 6
Link to comment
Share on other sites

Awesome! Congratulations! :)

 

Thanks, this has been a fun project. I've managed to resist looking at your PS/2 adapter source code. But now that I'm happy with the behavior, I'll have to take a peek. We had different constraints, so I'm curious how different the solutions ended being.

 

I had to let go of some of the keyboard mapping of 'www-' keys, and media keys. I never use them on PCs, and the USB Boot protocol doesn't use them. But the 101-key key layout is fully mapped following the layout you gave me. Thanks.

 

 

Very, very nice. I'm impressed!

 

Have a BOM built yet?

 

I'll write up full instructions this week. Things that can be slow to get are the Teensy 3.1 or 3.2 board, and particularly slow was the UHS mini breakout board. But I found a vendor from China for that too, which delivered much faster. I'll test with that. And I'll get a BOM up on the github project. I want to revise the board a little. C1 isn't desirable, and C2 really should really be labelled for polarity.

 

It's something like:

1x of this little board.

1x Teensy 3.2

2x 14pin sip socket connector

1x UHS Mini

2x 12pin sip socket connector

3-4 cm of fine wire.

( You'll need to mod the UHS Mini with an exacto knife. )

1x 10uf capacitor (labelled C2 on the board)

1x 16 pin 2x8 right angle header ( or equivalent IDC socket )

1x 16 pin 2x8 IDC ribbon cable connector

you probably want about 18 inches of ribbon cable. ( I haven't mounted mine inside the console yet )

1x 5pin header

at least 2 leads with header connectors to run to ground and +5v from the TI power supply.

  • Like 3
Link to comment
Share on other sites

I have updated the Copper Connection file, and gerbers on the github page. And built this little website http://ti994a.cwfk.net/TiUsbKeys.html with details and links to assembly and installation images, links to parts. Details on the capabilities, etc...

 

I've tested with the cheaper USB Host shield from DuinoFun. It works.

 

And I have shipped one off to an independent party for evaluation and feedback.

 

post-42954-0-31991300-1453660836_thumb.png

 

post-42954-0-06242100-1453660850_thumb.png

 

-M@

  • Like 6
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...