A lot of people can bake a cake. Sort of. Most of us can bake a cake if we have a cake mix. Making a cake from scratch is a different proposition. Sure, you know it is possible, but in real life, most of us just get a box of cake mix. The Raspberry Pi isn’t a cake (or even a pie), but you could make the same observation about it. You know the Raspberry Pi is just an ARM computer, you could program it without running an available operating system, but realistically you won’t. This is what makes it fun to watch those that are taking on this challenge.
[Deater] is writing his own Pi operating system and he faced a daunting problem: keyboard input. Usually, you plug a USB keyboard into the Pi (or a hub connected to the Pi). But this only works because of the Linux USB stack and drivers exist. That’s a lot of code to get working just to get simple keyboard input working for testing and debugging. That’s why [Deater] created a PS/2 keyboard interface for the Pi.
Even if you aren’t writing your own OS, you might find it useful to use a PS/2 keyboard to free up a USB port, or maybe you want to connect that beautiful Model-M keyboard without a USB adapter. The PS/2 keyboard uses a relatively simple clock and data protocol that is well-understood. The only real issue is converting the 5V PS/2 signals to 3.3V for the Pi (and vice versa, of course).
The code bit bangs the PS/2 clock and data, unlike some other projects that tie up the UART (disallowing use of the serial console for development). [Deater] says the code might work with a mouse with a little work. The challenge is handling the data rate in the face of unknown interrupt latencies. The USB port on [Deater’s] PCB, by the way, allows you to connect some USB keyboards that fall back to PS/2 mode with an adapter. You can’t just plug any USB keyboard into it.
We’ve covered PS/2 interfacing to different platforms before and even saw a keyboard converted to a drum machine. You can see a video about the construction of the Raspberry Pi interface below.
29 thoughts on “PS/2 Keyboard For Raspberry Pi”
“The only real issue is converting the 5V PS/2 signals to 3.3V for the Pi (and vice versa, of course).”
Don’t worry about that, I regularly connect keyboard to PIC working at 3.3 volt and all keyboards I have tried work well at 3.3volt. Better yet an USB keyboard fall back to PS/2 protocol when D- an D+ lines are tied to Vdd true a pullup resistor.
D- become PS/2 data and D+ become PS/2 clock.
The same for me with AVR ATMegas, PS2 is easy and 3.3v are enough for them.
In theory a PS/2 keyboard can draw up to 250ma of current, so I do worry about drawing that much from the 3.3V pin on a Pi. Probably only a problem if you try to use a model-M keyboard though, not a recent USB one.
250ma? are you using keyboard from the 80’s? At this moment I have an HP PS/2 keyboard 15 years old on hand. The label rate it at 50mA. Considering there is 3 LEDs on it, one can figure this 50mA figure is when all of them are lit.
Not the 80s but I do have some 1990s vintage keyboards kicking around (including some that have AT/PS2 adapters hanging off of them). Wasn’t planning on using them for this project thought.
Now I wish I had put a spot for a sense resistor on the board so I could measure keyboard current more easily. It would fit in well with some other research I’ve been doing on per-component power usage of modern server systems.
There are USB dongles that measures voltage and current. So you can use them to measure the not so vintage ones that supports USB and PS/2. Just put it between the keyboard and its PS/2 dongle.
The only complain is that the cheap ones have very low resolution and the sampling resistor is around 0.05 ohms range, so don’t expect that they give you good resolution (i.e don’t expect 10mA resolution.)
These boards are for use in a class with students who are going to struggle as it is to get an interrupt handler going, so I designed the board to be as in-spec as possible just so the bugs they encounter are due to their own code and not potentially flaky hardware. You could save a few $ on the board by omitting the level shifter, jumpering the lines, and cutting the 5V trace.
I did know about the “USB falls back to PS2 trick”, that’s the whole point of the USBA header on the board. I do have at least one USB keyboard where this didn’t work the first time I tried it though.
I have old keyboards that only works on 5V supply as they use 5V controllers. They do however handle 3.3V signals on the clock and data on the PS/2 just fine.
PS/2 uses open collect/drain I/O, so you can change the voltage level by changing pull up on the host side to 3.3V. Use a series resistor with a diode clamp to the 3.3V/Ground rails as you got some extra protection. The diode clamp also help to protect against some of the keyboards that have their internal pull up to 5V.
“Most of us can bake a cake if we have a cake mix”
That’s the most American thing I have read today.
And singularly the most depressing
There’s such a thing as cake mix? That really is sad.
I can’t say I bake cakes very often, but it’s not that hard. If you haven’t, I recommend that you put the soldering iron down for a bit and go bake a cake. From normal ingredients, not cake mix. Then eat it and come back.
One of the dumbest things I’ve seen in a long time was “praline mix” at a store a few weeks ago. It was a bag of brown sugar with some vanilla in it. That’s it.
A good trivia question is: Who was Duncan Hines? Hint: he wasn’t a baker.
He wrote a number of impressively delightful to read travel guides (dealing with where to eat when travelling). They’re real gems, and I keep hoping to run across them in digitized form!
Its basically just all the dry ingredients pre mixed so you just have to worry about butter/water/oil/eggs/etc. I prefer making from scratch myself but some of the mixes are actually fairly good.
There’s more to it than that, though. You generally can’t make an equivalent cake mix at home because they add stuff to it that you can’t just get at the grocery store. The result is that the cake requires fewer wet ingredients and is more… robust (less failure prone).
I like brownies. I buy brownie mix to make them. I could make brownies completely from scratch – and have before – but the mix is easier and the results are excellent. If it weren’t, I dare say the product wouldn’t sell and the companies would stop making it.
What annoys me is (British) pancake mix. Just add egg and milk! So it’s basically flour.
I wonder if they eat British-style pancakes anywhere else? And Yorkshire Pudding, which is pretty much the same thing in a different shape. They’re heaven. Gods, I could eat some now! Have to go over my Nana’s tomorrow, convince her it’s Pancake Day.
Not just the British, decades ago American cake mix companies learned that if they included powdered eggs and powdered milk to the mixes… they didn’t sell well. It turned out, people want to feel like they’ve “made a cake” instead of just adding water.
I would hope that there is baking powder, sugar in there with the flour too…
British pancakes don’t rise, and I’m pretty sure there’s no sugar, just egg, milk, flour. You add the sugar, and the lemon juice, when you eat it.
For Yorkshire pudding, you beat air into it, the egg holds the air, and that’s how it rises.
Sadly there are those who can’t boil water without melting a pot or two… Two of my housemates back at school days did just that. We found an ingot of aluminum under the heater.
And there are tons of people who can’t even solder…
Western civilization has created a society based on individual expertise. We no longer have to do everything for ourselves that survival requires, and so we can focus on becoming really good at one thing that is generally useful to society and engaging in commerce to leverage the expertise of others to fill in the gaps. I’m really good at writing software, and I’m not terrible at microcontroller based electrical engineering design and construction. I’m no good whatsoever at building houses or sewing clothing. But I live in a comfortable home and wear clothing that I’m not embarrassed to be seen in public wearing. Things would be quite different if the world population were divided by a thousand.
Well you know what they say an expert is, someone who knows more and more about less and less until he knows everything about nothing. I admit we are in a specialized society but it’s good to try your hand at things that are outside your bailiwick if just to say you sort of can.
That is a good way to put it, I’ll have to remember it in the future when I try to explain it to others.
That said, I still disagree a bit.
Having knowledge/experience outside your expertise can be incredibly useful, even INSIDE your expertise. It is one of those things that I find helps you “think outside the box”. Sometimes outside experience can augment or even replace an expertise, once a sufficient amount of outside experience is attained. It can also make you a valuable assistant to someone with a different expertise.
I have heard this referred to as being a “Versatilist” or being “T shaped”. The horizontal part of the “T” representing a shallow depth of knowledge/experience across multiple fields, and the vertical part representing expertise of a few fields.
Some of us still aspire to be Renaissance Men.
…using a clothes iron to make toasted cheese sandwiches!
Your mission is to go find an average citizen of London and have them bake you a cake from scratch. Let us know how that turns out for you.
There’s places in the world besides the USA and London. Even in Britain.
One thing I learn from living on my own since high school is that there are recipe or instructions on packages. They are enough o get you going. Sometimes they might even have a 1-800 number or URL. So if I have no idea how to make a cake nor google, I would likely to find something in the baking section of a store e.g. cake or general purpose flour, baking powder that comes with those handy instructions. There are youtube, cooking sites etc if your want to find it.
The problem with the society is that people are afraid of getting their hands dirty or bother learning the basic (life) skills. Witness the people that don’t bother to read datasheet, example schematic in app notes, but instead of relying on 3 party video or blog. Find out the source information and learning to read and understand technical documentation are essential basic skills.
This is a really coll idea especially for the Pi Zero
1. The whole cake mix thing is just annoying. It has got to be the single dumbest tangent I have seen on HAD ever.
2. This seem like a great idea to me. PS/2 keyboards us less resources than USB and would free up the limited USB bandwidth on the PI for other things. Also a great option for the zero IMHO.
Please be kind and respectful to help make the comments section excellent. (Comment Policy)