Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Is there a possibility of combining 4x4 keypad library for Arduino and usb keyboard built in library of Arduino

Status
Not open for further replies.

Madhurakshi B S

Newbie level 6
Joined
Mar 15, 2021
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
3
Activity points
153
Hello Sir/Madam,

I am working barrel filling project. In this project i need 4x4 matrix keypad to do multiple functions such as to load initial settings and same keys to enter digital data. I have studied the both 4x4 keypad library available for Arduino and USB keyboard built library of Arduino.

My question is that can be use both the libraries as there are advantages in both of them example there is availability of multiple key press in keyboard but in keypad there key which can toggle between assigned number keys and alphabet keys.

I want to use keypad library to initialize the key maps and keyboard library to handle multiple keys. Is this possible.

And in the usb keyboard library they say the once the usb connected to micro controller makes the system keyboard nonfunctional. My confusion is that after downloading the program through usb will the keypad that is peripheral to MC will behave as expected.

With Regards
Madhurakshi B S
 

Hi,

I guess that the USB keyboard library is for keyboars connected via USB.
..and the 4x4 matrux keyboard is for port (parallel, multiplexed) connected keyboards.

We don't know which keyboard you use and how you connected it... so we are not able to answer your question.
We don't know which hardware, nor which microcontroller you use.
Is it asking too much for a hand made drawing?

Give complete informations.

Klaus
 

It may be worth considering a PS2 keyboard rather than a USB keyboard. Same functionality without needing a USB port.
 
Hi Sir,

I am using Arduino Atmega 2560 as microcontroller and normal 4x4 soft key membrane matrix keypad.

I wanted to built in usb keyboard library as there are few supporting functions which help in my project need.

Can I use both the libraries, will there be any problem...
please do guide me in this section.

with regards
Madhurakshi B S
 

Hi,

You ask questions about libraries and keyboards. Still you don't give enough information, thus we are not able to give useful answers.
To me it's even unclear whether you want to design a (USB) keyboard or you want to use a (USB) keyboard for your "filling project"
...and whether you want to use the libraries for the microcontroller inside the keyboard or inside the filling project.

I agree with FenTrac that PS/2 is simpler (interface, protocol) than USB.
But a PS/2 keyboard does neither work with a 4x4 matrix keyboard library nor with a USB keyboard library.
Wasn't this the initial question in your headline?

I don't want to annoy you with repeated asking for informations. I just try to help, but this way I (we?) simply am not able to.
Don't blame it on us, if you don't get good assistance.
Is it asking too much
..it seems so..

I honestly wish you good luck for your project.

Klaus
 
You can use more than 1 library in the same program on an Arduino. The .h files for each library need to be included. The libraries can
not conflict with each other on pins used and other resources.

To use a USB keyboard directly connected to the Arduino a USB host shield would probably be the most straight forward way to implement this.
Then an appropriate USB library will be needed to handle a keyboard as an HID USB device.

The host computer's keyboard can be used through the Arduino's built in USB serial programming interface using a terminal program, such as putty, running on the host. The keyboard can be read using Serial.available() and Serial.read() by the arduino sketch. This requires that the Arduino is always connected to the host for this to work.

A PS2 keyboard can be connected to the Arduino, with a PS2 keyboard connector wired to The Arduino. The PS2 keyboard sends its data at TTL levels in a format similar to an asynchronous serial interface with: 1 start bit, 8 data bits, an odd parity bit, and 1 stop bit. It sends a clock and data on 2 of the connector's pins when a key is pressed. The keyboard is powered through the connector with 5v and ground from the Arduino. The baud rate on the clock pin can be measured with a scope. If the microcontroller's UART can be set to that baud rate, then the PS2 keyboard data pin can be connected to the serial receive pin of the UART ( and the clock is not used ). If it is connected to one of the mega's UARTs, then it can be read with Serial.available() and Serial.read().

Keyboard data is sent by the keyboard as a 1 or 2 byte scan code identifying the key pressed. A keyboard library translates the scan code into ASCII data and commands.
 

Hi,

You ask questions about libraries and keyboards. Still you don't give enough information, thus we are not able to give useful answers.
To me it's even unclear whether you want to design a (USB) keyboard or you want to use a (USB) keyboard for your "filling project"
...and whether you want to use the libraries for the microcontroller inside the keyboard or inside the filling project.

I agree with FenTrac that PS/2 is simpler (interface, protocol) than USB.
But a PS/2 keyboard does neither work with a 4x4 matrix keyboard library nor with a USB keyboard library.
Wasn't this the initial question in your headline?

I don't want to annoy you with repeated asking for informations. I just try to help, but this way I (we?) simply am not able to.
Don't blame it on us, if you don't get good assistance.

..it seems so..

I honestly wish you good luck for your project.

Klaus


Hello

Respected Sir,

Firstly thanks for wishes,

This micro-controller subject and programming with is very new to me, may be this is reason i am able to give accurate technical words and also i got only partial project needs. Complete project need and its functionality is not yet disclosed by my senior.

I need to function a 4x4 keypad with LCD as dispaly, inside the microcontroller only. And this keypad must be a alpha-numeric one. That is keypad handler subroutie in level 0 must be number keypad and in level 1 must be alphabetic one.

example : As in Dynamic keypad sample program of keypad library of Arduino
@file DynamicKeypad.pde
|| @version 1.2
|| @Author Mark Stanley
|| @contact mstanley@technologist.com
for 4x3 membrane keypad

char alphaKeys[ROWS][COLS] = {
{ 'a', 'd', 'g' },
{ 'j', 'm', 'p' },
{ 's', 'v', 'y' },
{ ' ', '.', '#' }
};

char numberKeys[ROWS][COLS] = {
{ '1', '2', '3' },
{ '4', '5', 6' },
{ '7', '8', ' 9' },
{ ' ', '0', '#' }
};

where '#' key is used to toggle between two keymaps that is once # is pressed, the keymap goes to alpha keymap and another # press results in keymap entering into the number keymap. I want to use the keypad in almost similar fashion. But in available keypad library i don't have multiple key press function as in " usb keyboard " built in library of Arduino.

Do combining both keypad library and keyboard library gives errror or is it is feasible to work. I have even written a sample code only to check the feasibility of two libraries but i am getting this as error.

" exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560. "

Help me in selecting the library or give me suggestion on what can be done to do to use multiple pressing a key.

Thanking you
with regards
Madhurakshi B S
--- Updated ---

Hello

Respected Sir,

Firstly thanks for wishes,

This micro-controller subject and programming with is very new to me, may be this is reason i am able to give accurate technical words and also i got only partial project needs. Complete project need and its functionality is not yet disclosed by my senior.

I need to function a 4x4 keypad with LCD as dispaly, inside the microcontroller only. And this keypad must be a alpha-numeric one. That is keypad handler subroutie in level 0 must be number keypad and in level 1 must be alphabetic one.

example : As in Dynamic keypad sample program of keypad library of Arduino
@file DynamicKeypad.pde
|| @version 1.2
|| @Author Mark Stanley
|| @contact mstanley@technologist.com
for 4x3 membrane keypad

char alphaKeys[ROWS][COLS] = {
{ 'a', 'd', 'g' },
{ 'j', 'm', 'p' },
{ 's', 'v', 'y' },
{ ' ', '.', '#' }
};

char numberKeys[ROWS][COLS] = {
{ '1', '2', '3' },
{ '4', '5', 6' },
{ '7', '8', ' 9' },
{ ' ', '0', '#' }
};

where '#' key is used to toggle between two keymaps that is once # is pressed, the keymap goes to alpha keymap and another # press results in keymap entering into the number keymap. I want to use the keypad in almost similar fashion. But in available keypad library i don't have multiple key press function as in " usb keyboard " built in library of Arduino.

Do combining both keypad library and keyboard library gives errror or is it is feasible to work. I have even written a sample code only to check the feasibility of two libraries but i am getting this as error.

" exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560. "

Help me in selecting the library or give me suggestion on what can be done to do to use multiple pressing a key.

Thanking you
with regards
Madhurakshi B S

complete error message...


Arduino: 1.8.5 (Windows XP), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

E:\Madhurakshi\pg3\pg3.ino:7:22: fatal error: keyboard.h: No such file or directory

#include "keyboard.h"

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 

The keyboard.h file not found compiler error means that the compiler could not find the file. Libraries can be installed with the library manager.
They can also be manually installed by moving the keyboard library's folder into the "sketchbook\libraries" folder. That is where the compiler will look for them.
Also try:
Code:
#include <keyboard.h>
 
It seems to me that you are still at the early stages of learning about embedded programming.
Start small and build up from there.
It seems that you are trying to program the complete system all at once. Take one component - say the LCD - and get that working on its own. You can create a small program that generates known text on the display by calling the appropriate library functions.
Then select the next component - say the 4X4 pushbutton keyboard - and get that working on its own. You can use a debugger to check that the program can respond to and interpret each key press correctly if you need to.
Then combine them so that you can press a keyboard key and see something on the LCD. Again, this may not operate exactly how you need in the end but now know that you can call each library separately, you can have them both in the same application and have something working.
If something stops working, then you can go back a step to work out the problem.
Susan
 
A further note on the keyboard.h file not found error: The Arduino reference page for the library states:

https://www.arduino.cc/reference/en/language/functions/usb/keyboard/

The keyboard library is for 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port.
These core libraries allow the 32u4 and SAMD based boards (Leonardo, Esplora, Zero, Due and MKR Family) to appear as a native Mouse and/or Keyboard to a connected computer.

So it does not work with a Mega, and it is not for connecting a keyboard to an arduino, but makes one of the above boards appear as a keyboard to
a host computer.
 
Hello Sir,

Thanks for all your informative guide.

In this case for 4x4 matrix or membrane keypad library and keyboard library cannot be used together. The 4x4 matrix or membrane keypad analyze the key press when both the Row and Column pins are high. Initially the Row pins are low and column pins are high when key is pressed the column pins becomes low expect at the column where press is occurred, now each row is made high to know where in which column the key is pressed. later it decodes the key press based on the keymap defined by the user. This is 8 line output.

The keyboard is basic 8048 micro-controller the key press is analysed with make and break codes. That is make code is a unique code occurs at the point key press and break code is generated when the pressed key is released and this break code is general one. For example lets say Capital A is pressed make code for A is "1C" and break controller is "F0" is generated code is clubbed together say "1C,F0" and read my micro-controller. This is two line output clock and data.

Since reading pattern of the both USB or PS2 keyboard and 4x4 matric or membrane keypad is different we cannot combine both the libraries.

I am very thankful to all you who responded even though in my asked question there were less technical words, gave me the link, shared me the studying material, this helped me in going through the subject again and again.

I studied both the library and even asked my senior the same doubt regarding this matter hence understood that both the libraries cannot be clubbed as their working is different. Hope this short note may help people like me with similar doubt.

Thanking all of you for your support...

with regards
Madhurakshi B S
 
Last edited:

I don't agree that they can't be used together. Because they are using different resources they won't interfere with one another. Your description above as to how they work is accurate. For the 4x4 keypad the program scans I/O pins and decodes the results. For the full keyboard it looks for a serial input, and then decodes those results. These operations don't preclude one another. The program needs to be designed to handle both operations.
You are already planning to do more than one operation in the program, scan a 4x4 keypad and output data to an LCD. The mega has sufficient memory and I/O capabilities to handle all these operations in a single program. As recommended above, get one part of the program working and then add another. A microcontroller or computer can handle multitasking because is it operating fast enough to handle different jobs, one at a time. The programmers job is to come up with the appropriate method of doing it, to control the sequence and timing to run each job.
Begin looking at the resources an AVR microcontroller has to do mutlitasking. For a couple of examples, It has "pin change interrupt" capability that can sense when the input line connected to a 4x4 keypad changes state. An interrupt service routine can then handle the keypad. The Serial controllers for SPI or UART can also generate an interrupt when data is available to be read, and the interrupt service routine can handle the keypress.
Or, the program can just run in a loop, scan the keypad for an input, check if serial data is available from a keyboard input, and respond if a key has been pressed. The programmer needs to approach the programming task in similar fashion. Get one part of the program working and then work on adding the next part.
A library is just someone else's program that was written to handle a particular task. It provides convenient functions to use so that one does not have
to reinvent the wheel and can get a program up and running quickly. It does not define what is or is not possible. The downside of using a library is that
one does not really understand what it is doing or how it is doing it. The person who wrote the library has done that and come up with their particular solution. Don't be limited by what you think a library will do.;
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top