Easy Arduino PS/2 Keyboard Read Out

Поделиться
HTML-код
  • Опубликовано: 5 янв 2025

Комментарии • 120

  • @stupossibleify
    @stupossibleify 3 года назад +15

    Really surprised how simple both the VGA and PS/2 keyboard specifications are - thanks for making them accessible to everyday humans :)

    • @slu467
      @slu467  3 года назад

      I like this simple stuff, too. For hobby projects it's so convenient...

  • @PhilR0gers
    @PhilR0gers Год назад +1

    Wow! I have been looking up how to connect a PS/2 keyboard to my 6502 based computer, and I didn't want my main CPU to have to do the decoding work.
    This is by far the most simple way of getting the ASCII data (and with some tweaks, codes for a few special keys) that I have seen so far.
    Thanks.

  • @stephenstewart2628
    @stephenstewart2628 2 года назад +2

    I used this example to connect to an old IBM AT compatible keyboard which has a DIN 180 connector. Well it did have until I snipped it off. It worked a treat. This is just my first step in a larger project. Thanks for the leg up.

  • @trader891
    @trader891 8 месяцев назад

    Awesome. Just what i needed. I'm using an Arduino to control 2 stepper motors to set a back gage on a 90 to press brake, and needed a simple way to feed the back gage setting for each bend of the steel into the Arduino so it can spin the servos to the right spot. I was going to use a nice touchpad, but found it has no keypad function and the interface to the Arduino is quite complex and the library is huge. This is very simple and compact.

  • @djc1402
    @djc1402 4 года назад +2

    This is great timing as I was just about to try hooking my PS/2 keyboard to my Arduino Nano and see if I can interface it to my CPU.

  • @unilein
    @unilein 3 года назад +1

    I will be using this solution for my Z80 homebrew computer that I am currently developing. Thanks for showing this up.

  • @xotmatrix
    @xotmatrix 3 года назад +1

    Very helpful. I'm currently building a PS/2 keyboard interface for an Apple II computer.

  • @villagerjj
    @villagerjj 8 месяцев назад +1

    I am working on an open source program to hijack a gameboy color over the serial port. This helps a ton! Thanks 😊

  • @djc1402
    @djc1402 4 года назад +1

    I eventually got around to trying my PS2 keyboard with your code for the Arduino and it works great. I've remapped the keys for a US keyboard layout that we use here in Australia. I will use it to interface to my CSCvon8 minimal CPU, so it will have native keyboard input rather than through a terminal emulator and UART that I am using at the moment. Many thanks!

    • @slu467
      @slu467  4 года назад

      It is interesting to see how we are moving in various directions :-) Right now I have finished a big design step in order to get rid of ALL Arduinos in my CPU (they didn't feel too minimalistic after all...). Since James (Sharman) had released his miniseries about TTL UART from scratch (which you might be aware of) I saw a "minimalistic" way of integrating UART into my design, too. Et voila, success! But I now use UART as the ONLY means of communication with my computer. No VGA, no PS2 any more ;-)

    • @djc1402
      @djc1402 4 года назад +1

      @@slu467 I'm planning to go away from using the UART for screen and keyboard I/O and instead using it as a pseudo file system, having a keyboard connected via an arduino nano into the CPU, and having the VGA bit-mapped colour screen for output. I'm a big James Sharman fan and have watched his series a number of times. You should think about doing a minimal pipe-lined CPU. I am thinking of doing it myself one day.

  • @G8CHP
    @G8CHP 9 месяцев назад +1

    Great explanation, thanks.
    Being a radio amateur, and keen on building projects, I’m currently using Arduino for a portable RTTY transceiver. I’ve tried a USB keyboard with a host shield, but cannot get it to work. Hoping that this will answer my prayers!

  • @antonirla5396
    @antonirla5396 10 месяцев назад +1

    ie had this idea to use a ps/2 keyboard with my computer but apparently with win 10 u cant use a ps/2 keyboard even with an usb adapter. but i had my shower thoughts and hey arduino can emulate an usb keyboardand there you have it a working ps/2 keyboard with win10

  • @InfiniteCoder01
    @InfiniteCoder01 Год назад

    Since you've used interrupts and noInterrupts (just macros to cli and sei) you could use attachInterrupt for simplicity (not as fast as with ports, but it's only done once on startup)

  • @your-dad
    @your-dad Год назад +1

    I have a problem, I have a ps/2 usb keyboard with rgb leds, and every time i commect the keyboard to the arduino it open and close after half a second how do I resolve this?
    Thanks.

    • @slu467
      @slu467  Год назад

      Some more recent PS/2 keyboards require a two-way communication for setup. I remember having some trouble finding information about this on the internet. I'd recommend avoiding those "more modern" devices if you are looking for a simple keyboard-to-CPU interface. Good luck!

  • @bakialmaci
    @bakialmaci 4 года назад +5

    Thanks for this excellent video! I'm trying on my PS/2 type keyboard but this is not working on my implementation.
    If I need to give more specific details,
    - I've cut the wire and there is 4 color which are RED, BLACK, WHITE and GREEN.
    - I'm using original Arduino Uno board which has DIP socket.
    - RED -> 5V, BLACK -> GND, GREEN -> A3, WHITE -> A4.
    - Keyboard Model: Everest KB-517P (Not much knowledge about this model on internet).
    I am absolutely sure my Arduino working fine and I checked your answers to another comments/issues.
    How can I test my keyboard is working? (Without oscilloscope and PS/2 support).
    And what do you suggest to me?
    Regards..

    • @bakialmaci
      @bakialmaci 4 года назад +4

      It's working now !
      I disassembled the keyboard and followed the PCB paths. I was shocked to see that Black is + 5V and Green is GND. Thanks to you my project will be good.
      Regards..

    • @slu467
      @slu467  4 года назад +1

      Glad you like my videos :-) I highly recommend to at least obtain a small USB scope for those kind of projects. Otherwise it becomes very hard if not impossible to do any trouble-shooting. Different manufacturers might use different wire color coding... Cheers!

    • @slu467
      @slu467  4 года назад +1

      @@bakialmaci That's the spirit :-) Just take it apart and good things are gonna happen :-) congrats, glad that it's working now.

    • @bakialmaci
      @bakialmaci 4 года назад +1

      ​@@slu467 I implemented to MSP430 this code and working fine, Oh Yeah !

  • @colonelbarker
    @colonelbarker 4 года назад +1

    Well that makes a lot more sense! I was trying to read the data and clock continually and getting garbage.

    • @slu467
      @slu467  4 года назад

      @ Aaron: Glad it is helpful :-) How is your build going? Cheers!

    • @colonelbarker
      @colonelbarker 4 года назад +1

      @@slu467just waiting for ICs to arrive. I got thr keyboard working fine, barring the Y ans Z being inverted. It's school holidays here so I'm on Dad duties for about week.

    • @slu467
      @slu467  4 года назад +1

      @Aaron You can change the layout to your liking quite easily. I usually let the Arduino print out the raw scan code. Than, just find that location in the lookup table and replace it with whatever ASCII you like. This way, you can also access the function key, cursor keys etc. Happy parenting!

    • @colonelbarker
      @colonelbarker 4 года назад +1

      @@slu467Thanks! Yes- it will be good to have access to a few more keys, particularly the maths related ones! I want to make sure mine is as compatible as possible with software for yours. It's a rainy day here, so time for more wiring!

  • @JeffLee-h8n
    @JeffLee-h8n Год назад +1

    I want to be able to press some key on Keyboard and as result, Arduino should work as a keyboard itself for computer and act as if some other keys were pressed or sequence of keys. I want to make such keyboard convertor.

  • @hkfuertes
    @hkfuertes 3 года назад +2

    This is awesome to use with a Leonardo or a teensy, to reporpuse and old PS2 keyboard as a Macro keyboard for shortcuts for editing, for example :)

    • @slu467
      @slu467  3 года назад +1

      Glad you find this useful :-)

    • @welshdave5263
      @welshdave5263 2 года назад

      This is why I searched for this video, I have a Disney PS2 keyboard that I can lay my own printed sheet of keys on, want to make an editing/OSB Marco board.

  • @chonvalle392
    @chonvalle392 2 года назад +2

    Me funciono muy bien lo necesitaba para un proyecto, agradezco tu aporte. Thanks and congratulations!

  • @viktorhugo8252
    @viktorhugo8252 4 года назад +1

    in your ISR there can be the problem when unplugging the keyboard in time of being just in the routine. While loop is not the best way to wait for the clock edge when the keyboard can disconnect any time. And the for loop in ISR is to long if there is a second interrupt if you need another input of the arduino with a second device.
    In the case of no other IRQ you can do as shown. The ISR must always short as possible. 800 usek or more can be to much.

    • @slu467
      @slu467  4 года назад

      Hi Viktor, thanks for pointing this out - I see the point - but on the other hand I try to keep things as simple as possible ;-)

    • @viktorhugo8252
      @viktorhugo8252 4 года назад

      Slu4 , thanks for your answer. did you ever test a USB-Keyboard without a USB-Shield for arduino? I will use a USB - Keyboard because PS/2 is not up to date. There are keyboards with PS/2 - USB adapter will this fit for the first? Is USB D- Dataline and D+ always ckock? I think Your solution can also used with D2 or D3 / Int0 or Int1 for ISR with clock and any other unused digital Pin for the dataline. Can you please test this by changing the input lines? This can be useful as 2. or 3. UART for seriell transmission.

    • @slu467
      @slu467  4 года назад

      @@viktorhugo8252 USB is way harder to implement in TTL. That's why I went for PS/2 - old style but still available.

  • @gianchf9216
    @gianchf9216 3 года назад +1

    is it possible to create a layer? Thank you

  • @ThomasPerl4
    @ThomasPerl4 Год назад

    Thanks for a good description and visualization, especially that you explain the reasoning behind it and what would happen if a certain line (e.g. interrupt flags clearing) wasn't done and what each line does. Might have been interesting to see how to handle the parity bit (discard the input if the parity doesn't work out). Also, how does sending commands to the keyboard work (LED setting and others)?

  • @QuangNguyen20
    @QuangNguyen20 Год назад

    Does the same concept apply to these even older keyboards? The 5 pin din

  • @safakankara7613
    @safakankara7613 6 месяцев назад

    in the video at 1.04 the key code comes first followed by F0 but the BREAK code from the Scan code is for the letter A, F0 1C is seen like this in the libraries. You show that the last data coming with the oscilloscope is F0.
    Scan tables show
    MAKE =1C,
    break =F0 1C.
    Which one is correct.
    Thanks

  • @Xavier_Everwhere
    @Xavier_Everwhere 2 года назад +1

    Can you connect it with and display like liquid crystal display or tft display so that it can type letters on it like a small cmd computer

    • @slu467
      @slu467  2 года назад

      Hi Xavier, please see my other videos, especially the one about the Arduino Nano PC where I am doing exactly that, i. e. VGA output.

  • @royerickmelendez3408
    @royerickmelendez3408 3 года назад +1

    Exelent video my friend, y want to use this information to use my keyboard to a midi controller, thank you so much!

    • @slu467
      @slu467  3 года назад

      Glad to hear that you apply this stuff to your own projects!

  • @trushti_1375
    @trushti_1375 Год назад

    Would the code work for M5Stack which is a ESP32 based development board ?

  • @robe8274
    @robe8274 4 года назад

    Great vid. perhapse a ctrlisActive could have been added. Also, I'm looking to add parallel output (D2..D9 + D10 as strobe) as my retro Z80 used PIO chip

    • @slu467
      @slu467  4 года назад

      Thanks! Glad you can use it as a starting point for your project. Cheers!

  • @2150dalek
    @2150dalek 3 года назад +1

    Very informative. Impressive. I want to build some kind of tiny basic computer or VT Terminal using arduino(s).

    • @slu467
      @slu467  3 года назад

      Hi Dalek 2150, my new video might come in handy... :-)

  • @corcinox
    @corcinox 3 года назад

    muy buenos tus videos, he apredndio mucho y los estoy replicando una pregunta porque no usas las librerías de vgax ?

    • @slu467
      @slu467  3 года назад

      Hi, glad you find my videos interesting! The VGAX lib for Arduino does something else: 120 x 240 pixel BUT without any additional ICs. I am doing 320 x 200 pixel with the help of two standard ICs. Cheers!

    • @corcinox
      @corcinox 3 года назад

      @@slu467 si eso deja mas espacio para los programas, me di cuenta de eso ., tus video son geniales y ye informaré si logro completar la computadora basica con arduino. Lo unico es que en mi pais es difícil encontrar los ic. Tu sabes si se pueden reciclar de algún aparato electrónico?

    • @slu467
      @slu467  3 года назад +1

      I am mainly using the 74HCxx series in the DIL package. They are easy to handle and great for prototyping, but they are almost never being used in commercial electronics nowadays. You might be able to find some SMD logic chips though. They work just as good but are a pain to solder with a soldering iron... and you can't use them on breadboards of cause... In the meantime: I find it as enjoying to emulate basic CPUs. Take a look at my latest video about this topic, if you are interested. Cheers.

    • @corcinox
      @corcinox 3 года назад

      @@slu467 grasias

  • @Drxxx
    @Drxxx 3 года назад

    can you use it with usb barcode scanner??

  • @WSSTUDIO-wj6fx
    @WSSTUDIO-wj6fx 4 года назад +1

    Jejeje genial amigo, soy nuevo subscriptor, genial proyecto, me cuesta hablar el ingles pero muy buen video, es increíble lo que usted hace...

  • @joeplocki3525
    @joeplocki3525 4 года назад +1

    The problem I'm having is that my keyboard sends 0xAA on startup, and then again every 620ms or so. I looked it up, and it's sending me the results of its self test. I don't know how to acknowledge it, and it doesn't send any keystroke data at all, just the 0xAA, about every .6 seconds. Anyone familiar with this, and how I might deal with it?

    • @slu467
      @slu467  4 года назад

      Hi Joe, sorry, the PS/2 keyboards I've tested all behave pretty dumb :-) Maybe try an older model? The communication I've implemented is really only one-way... Cheers!

    • @SteveGuidi
      @SteveGuidi 3 года назад

      Hi Joe -- same situation with my keyboard. In my case, the keyboard is a dual PS/2 and HID-USB keyboard. Did you figure out how to acknowledge the 0xAA message?

    • @joeplocki3525
      @joeplocki3525 3 года назад

      @@SteveGuidi I haven't yet - I had to take a hiatus from my homebrew project while I convert one of the kid's former bedroom into a hobby area (not enough room at my desk with working from home once I had to bring home my work PC). Everything's been in a box since about a week after I posted this. Hopefully I'm close to having a workspace set up again. If I do figure it out, I'll reply back here.

    • @joeplocki3525
      @joeplocki3525 3 года назад

      @@SteveGuidi Ben Eater has an excellent series on using PS/2 (with a breadboard 6502 he's building) and one commenter on the second video solved the 0xAA problem. Well, he found the solution: www.reddit.com/r/beneater/comments/mih76u/ps2_keyboard_autoreset_circuit_for_keyboards_that/ I haven't tried it yet, but I remember you asking if I found a solution, so I had to search my history to find you... hope it helps. Let me know either way, if you have a chance to try it. I'm still working on setting up a workbench in the empty bedroom so I can start messing with my 65816 design again.

  • @sandrosalessales6324
    @sandrosalessales6324 4 года назад +1

    Excelente vídeo !! Thanks and congratulations !!

    • @slu467
      @slu467  4 года назад +1

      Thanks for tuning in! Cheers.

  • @johannahoppe5544
    @johannahoppe5544 3 года назад +1

    hi, your video is very good. Does this work kinda similar if I want to get data from a ps2 mouse, like the coordinates ?

    • @slu467
      @slu467  3 года назад +1

      Hi, my guess would be that data is transferred just the same. I am not sure about how to decode the info about mouse movement. I'd suggest, give it a try and see what data you get. Cheers!

  • @davidecosciani9232
    @davidecosciani9232 Год назад

    Sorry, if I want use this code on Arduino MEGA2560 how modify the source and INT? Now on Arduino UNO it uses A3 as DATA and A4 as CLOCK inputs, and
    PCICR = 0b00000010; // enable Port C pin change interrupt PCI "PCINT1"
    PCMSK1 = 0b00010000; // unmask Pin A4 pin change interrupt PCI
    It is possible adapt to MEGA? Thank you in advance!

    • @slu467
      @slu467  Год назад

      Since Mega is more powerful it should be possible. However, I cannot provide any insights here, since I do not own one.

  • @davidecosciani9232
    @davidecosciani9232 Год назад +1

    Very good! Very simple and cheap! Did you a same for USB keyboard?

    • @slu467
      @slu467  Год назад +2

      The protocol is not so simple for USB. So I always thought for my little projects it's not worth it. But in the end it's just ones and zeros...

  • @bakialmaci
    @bakialmaci 4 года назад

    I've checked your completed code and I figured out that you used char array instead of constant char array this will cause ram problem. It need to be optimized.
    Regards.

    • @slu467
      @slu467  4 года назад

      Hi, thanks for diving into this! Are you thinking about moving the charset into Flash RAM? Unfortunately, this wouldn't work, since accessing would take a couple of clock cycles too long. The charset has to reside in dynamic RAM, taking up precious space there. Or maybe I didn't get your point? Cheers.

  • @edgeeffect
    @edgeeffect 3 года назад

    I'd love to know how you're using the keyboard to "toggle" data into RAM without an operating system to help it.

    • @slu467
      @slu467  3 года назад

      Hi edgeeffect, I am not quite sure which video you are referencing. With my Minimal CPU there *is* actually an operating system receiving serial input, thus allowing you to toggle data into the RAM. My very first prototype however relied on an Arduino only *simulating* a control logic. It could receive KB input and access RAM per "DMA" so to speak.

  • @hipposhark
    @hipposhark Год назад

    Very informational! Would you mind sharing the model of your ps2 keyboard? I am using one that draws 100mA and it seems like the arduino nano is not able to supply that much.

    • @slu467
      @slu467  Год назад

      I am using and old Acer KB - also with 5V/100mA. The Nano should have no problem supplying up to 500mA via the USB port. You must be doing something differently. Good luck!

  • @karamca3722
    @karamca3722 3 года назад

    Thank you sir, if i use arduino uno which input do i use for data and clock

    • @slu467
      @slu467  3 года назад +1

      C3 (= Analog_3) is DAT, C4 (= Analog_4) is clock

    • @karamca3722
      @karamca3722 3 года назад

      @@slu467Thank you sir

  • @sabinbaral4132
    @sabinbaral4132 3 года назад +1

    Great video

    • @slu467
      @slu467  3 года назад

      Glad you like it. More to come soon!

  • @wsricardo23
    @wsricardo23 3 года назад

    Whats would be app or device that you used tô get signal from keyboard?

    • @wsricardo23
      @wsricardo23 3 года назад

      Is possible use this way to get signal from USB keyboard?

    • @slu467
      @slu467  3 года назад

      The Arduino is receiving input from the PS/2 keyboard and sends it via UART to whatever device is driving the Arduino - in my case its a Win10 PC. Cheers!

  • @jackjack-kw2zh
    @jackjack-kw2zh 3 года назад +1

    SO COOL

    • @slu467
      @slu467  3 года назад

      Thanks, jack jack :-)

  • @robipaul5762
    @robipaul5762 3 года назад

    can you pls show us to use a ordinary gamepad with arduino. not ps4 ps3 types. just normal ones. It will be a great help if you show us.

    • @slu467
      @slu467  3 года назад

      Sry, I don't have those available. So maybe set out by yourself :-)

  • @ducksonplays4190
    @ducksonplays4190 4 года назад +1

    I feel like this was made for me. All the other ones just don't work. I hope this works and do you think this would work on an arduino mega 2560

    • @slu467
      @slu467  4 года назад

      This really should work on any Arduino from Nano onwards. You might have to tweak it a bit...

    • @mirkoschulze4205
      @mirkoschulze4205 3 года назад +1

      Hey, Which Pins do you use for it at the mega2560? Which pin for CLK and which for Data?

    • @ducksonplays4190
      @ducksonplays4190 3 года назад

      @@mirkoschulze4205 currently ive had no luck with my mega 2560 im not sure if its just me or if its incompatible

    • @mrpotator3791
      @mrpotator3791 2 года назад +1

      I know it's been a year but I figured it out so let me know if you want the code.

  • @ahmetanbar6346
    @ahmetanbar6346 4 года назад

    I try to implement the arduino code at MSP430. I use msp430g2553. I click 'A' letter, and I check the value of 'val'. So I got the two different values like that:
    0000000011000000b
    0000000011100000b
    Is it related with my CPU speech? I check the code with arduino uno that has 16Mhz, it works clearly. I think I lose data with msp430. Do you have any idea?

    • @bakialmaci
      @bakialmaci 4 года назад

      Solved
      It related to keyboard communication protocol also you need to check your value when you release the key. Because, signals comes two times when you are pressed and released state.

    • @slu467
      @slu467  4 года назад

      Hi Ahmet, you are using a pin change interrupt (PCI) on our CPU as well, right? Maybe try and modify the ISR so that it reads in at the rising edge of the clock. Good luck!

  • @himanshutomar8165
    @himanshutomar8165 4 года назад

    This is not working for me any suggestions

    • @slu467
      @slu467  4 года назад

      Hm, it's really hard to tell from afar. If you could be a bit more specific... There might be some newer PS2 keyboards that actually want to establish a two-way communication with the CPU before they agree to send their data... those won't work. One would have to look at the signals to learn more... Good luck!

    • @himanshutomar8165
      @himanshutomar8165 4 года назад

      @@slu467 ok i understand now i need your help in ,i want to add ps2 pin connector in arduino uno and store some key strokes in it, then plug it in any computer and use that commands.

  • @ManicQuinn
    @ManicQuinn 4 года назад +1

    Will this work on an UNO?

    • @slu467
      @slu467  4 года назад

      Yes, it should work as well on an UNO, since it uses the very same CPU.

    • @ManicQuinn
      @ManicQuinn 4 года назад +1

      @@slu467 Thank you

    • @ManicQuinn
      @ManicQuinn 4 года назад

      @@slu467 Is the wiring the same?

    • @slu467
      @slu467  4 года назад

      @@ManicQuinn It's the same, yes.

    • @karamca3722
      @karamca3722 3 года назад

      Does it work with Arduino Uno ?

  • @VybGrib
    @VybGrib 2 месяца назад

    I want to connect keyboard via arduino directly to old dot matrix printer, to make direct typewriter machine... :-)

  • @gopro2804
    @gopro2804 3 года назад

    Liked and subscribed!

    • @slu467
      @slu467  3 года назад

      Thanks man!

  • @MD-qz6gk
    @MD-qz6gk 4 года назад +1

    Thank you a lot !!!!!

    • @slu467
      @slu467  4 года назад

      You are welcome!

  • @alexpark-q8m
    @alexpark-q8m 10 месяцев назад

    It doesn't work for me.

  • @servetbirgul
    @servetbirgul 2 года назад

    Amazing

  • @hallomeinnameistkarl216
    @hallomeinnameistkarl216 3 года назад

    Why is your wi and keyboard german?

    • @slu467
      @slu467  3 года назад

      I am from Germany, Karl ;-)

  • @rendszergazdanyh2537
    @rendszergazdanyh2537 4 года назад

    Hello!
    Would you like to further develop this project?
    I would need the arduino to be connected to a HC05 bluetooth module so that it can be used on a tablet to type on a PC keyboard with a PS/2 connector. Could you help with this?
    Is it enough to send the HEX code of the key pressed via bluetooth?
    Or will you not recognize the tablet as being a normal keyboard?

    • @slu467
      @slu467  4 года назад +1

      That sounds interesting, but I'm afraid I can't help you with your project. Currently my developments are taking a different direction... All the best!

    • @viktorhugo8252
      @viktorhugo8252 4 года назад +1

      Rendszergazda Nyh , many keyboards with BT can do this. Connect the keyboard in BT config (tablet or phone) and you can use it as input device (HID).

  • @sto2779
    @sto2779 3 года назад

    who the fuck uses PS/2? What about USB keyboard?