element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum How to use Arduino Uno to connect USB keyboard to matrix keyboard?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 8 replies
  • Answers 1 answer
  • Subscribers 393 subscribers
  • Views 1746 views
  • Users 0 members are here
  • ports
  • keyboard
  • matrix
  • usb
  • timing
  • uno
  • reducing
Related

How to use Arduino Uno to connect USB keyboard to matrix keyboard?

Former Member
Former Member over 12 years ago

Either I am looking in the wrong places or nobody has done this before.

 

What I am looking for is a way to read a USB keyboard that is attached to an extra USB port (as in the examples with D- and D+ to two/three? ports) and then write a matrix code to output.

 

To explain what I am trying to do in more detail. The old Sinclair ZX computers have a matrix keyboard.

For example the ZX81 has a 5x8 matrix. Five lines are selected one by one and pulled low over and over again. The pressed key pulls one out of 8 columns low. Shift key is special as it is the switch for the first bit only.

These membrane matrix keyboards tend to breakdown, their life expectancy is lower than 30 years :-)

So I'd like to find some way of using a standard USB keyboard instead.

 

I see several challenges:

 

1. Reading the USB keyboard. Looks like the USBHost library cannot be used for this???

 

2. Reading 5 lines (5x8 matrix) from the old retro computer line-select output (via interrupts), then if a character was received from the keyboard, translating it into 8 bit output. Should be doable as I know exactly which key is on what location, for instance if the current line is the first one, and a key '3' has been pressed without shift, then I can send a 00010000 byte, the first bit being shift. If the key was shift-3 (like '#' on some keyboards) then send 10010000.

 

3. Probably I got a shortage of ports on the Uno, if 3+5+8 are needed. Perhaps a way to feed a shift register with 8 bits output through one/two ports?

Or use the chipKIT Max32 that I have for this, hmmm lots more ports.

 

4. Somehow adjust to the timing factors of the old computer (keyboard repeats? control-shift-alt combinations?) and utilize buffers from the USB keyboard...

Of course the timing from the interrupts has the most important role. But I suspect the USB keyboard works with keypresses and releases, that might complicate things?

 

Can you guys please advise.

 

Regards, Martin

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 10 years ago +1 verified
    Update. As no one solved this problem I have initiated a project for doing this. This project is finally finished: I have now an Arduino Uno with USB Host Shield, the USB Host Library 2.0 (from GitHub…
Parents
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago

    The second 4051 is not clear as to its wiring

     

    it will save you pins and should be easy to drive with 5 pins from the arduino, then 3 more for the original one (Assuming you leave it perminantly enabled)

     

    the 5 pins (4 is again you leave it permenantly enabled) are assigned as follows

    3 for addressing one of the eight rows

    1 for toggling the line HIGH / LOW

    one optionally to enable the chip

     

    so code would work as follows

    two loops, 0 - 7 address one inside te other

     

    Char keypressed = ""

     

    for each row (0-7)

         {

         for each column (0-7)

              {

              toggle Z input to new 4051

                   if the output Z of original 4051 toggled

                       {

                       keypressed  = key (row, Column)

                       }

              }

         }

     

    thats pretty much it, the 4051 is an analogue multiplexer so will do nothing except wire a path between the Z and one of its Y pins so what you have wired is a 1 to 8 multiplexer through the switch matrix then into an 8 - 1 multiplexer allowing you to scan every pin in squence.

     

    It will not account for multiple key presses at the same time, this takes more code than a simple scan, though you could capture each key into an 8*8 array for the state  but there may be key combinations that would fool the scan into thinking more than the actual number of keys are pressed.. In older keyboards, diodes where often employed to prevent this

     

    also as the keys not currently being scanned will be floating (Analog switch remember, not a 3-8 line logic level decoder) so I would suggest a pull up on the output of the 4051 your reading from then all keys will read high except the one your addressing.

     

    come to think of it. if you tie the input Z of the matrix to ground and use a pull up on the ourput Z, then you save a pin and wont need to toggle it. the pin reading 0 if any will be the one pressed

     

    if you want a logic 1 to mean the key is pressed then use a pull down resistor and tie the input Z to 5V (Not through a resistor)

     

    Hope this helps

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago

    The second 4051 is not clear as to its wiring

     

    it will save you pins and should be easy to drive with 5 pins from the arduino, then 3 more for the original one (Assuming you leave it perminantly enabled)

     

    the 5 pins (4 is again you leave it permenantly enabled) are assigned as follows

    3 for addressing one of the eight rows

    1 for toggling the line HIGH / LOW

    one optionally to enable the chip

     

    so code would work as follows

    two loops, 0 - 7 address one inside te other

     

    Char keypressed = ""

     

    for each row (0-7)

         {

         for each column (0-7)

              {

              toggle Z input to new 4051

                   if the output Z of original 4051 toggled

                       {

                       keypressed  = key (row, Column)

                       }

              }

         }

     

    thats pretty much it, the 4051 is an analogue multiplexer so will do nothing except wire a path between the Z and one of its Y pins so what you have wired is a 1 to 8 multiplexer through the switch matrix then into an 8 - 1 multiplexer allowing you to scan every pin in squence.

     

    It will not account for multiple key presses at the same time, this takes more code than a simple scan, though you could capture each key into an 8*8 array for the state  but there may be key combinations that would fool the scan into thinking more than the actual number of keys are pressed.. In older keyboards, diodes where often employed to prevent this

     

    also as the keys not currently being scanned will be floating (Analog switch remember, not a 3-8 line logic level decoder) so I would suggest a pull up on the output of the 4051 your reading from then all keys will read high except the one your addressing.

     

    come to think of it. if you tie the input Z of the matrix to ground and use a pull up on the ourput Z, then you save a pin and wont need to toggle it. the pin reading 0 if any will be the one pressed

     

    if you want a logic 1 to mean the key is pressed then use a pull down resistor and tie the input Z to 5V (Not through a resistor)

     

    Hope this helps

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube