Keypad not printing to PC applications.

Arduino Nano. What do I need to add to this to print the outputs to a PC? Right now the outputs only print to serial monitor.

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{’*’,‘0’,’#’,‘D’}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();

if (customKey){
Serial.println(customKey);
}
}

You need a board with a 32U4 or some other processor that can emulate a USB keyboard. There is library support for that. But the Nano lacks the USB hardware, so it can't work.

What is the most simplistic model to get just for creating a custom keypad you provide inputs to a PC?

The Arduino Leonardo?

Leonardo, or Pro Micro. However, I’m taking a wild guess at what you mean by “simplistic”. You didn’t explain anything about your project.

It’s called an “HID”, Human Interface Device.

I an a novice for Arduinos and programming in general.

I am building a custom keypad for gaming. A 4x4 or 4x5 grid that I can customize what keypress is being sent to the PC.

Yes, but... enclosure? Size? Or you can decide. If it was me, I would go for the Pro Micro. I have a few kicking around that I use when I need two serial ports (I haven't played with HID yet). It's smaller and easier to connect to than the Leonardo, for a permanent project. I think a "Blue Pill" will do it also, but it's not as easy to program.

The good news is - you actually picked a pretty easy project.

Alright, I have the Arduino Leonardo now.

All I want to do is have the 4x4 grid below print to applications on a PC. Is this possible with Keyboard.print() or something similar? Or can this not be done with the keypad 4x4 grid?

#include <Keypad.h>

const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6}; 
byte colPins[COLS] = {5, 4, 3, 2}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
  }
}

it is a huge difference between sending a byte over a serial connection based on a virtual comport or sending a "USB-signal" that shall have the meaning of a HID (human interface device). To make it even more clear a serial-connection is a NOT-HID-connection.

For sending keypresses the same way as from a USB-keyboard the connection must be a HID-connection. This requires a microcontroller-board with USB-HID-capabilities like Arduino-leonardo.

Inside your program you are totally free to program whatever you want to cause sending "keystrokes" it just depends on your code. So you could even make a program that measures the moisture of a hamburger and based on the moisture-value send different USB-Keyboard-keystrokes,

There is one part in your program read-in (whatever)

and another part based on some rules (if-conditions) what USB-keyboard-keystrokes shall be send.

This is called: Input processing output principle.

Sending USB-keyboard-Keystrokes is done by other commands than Serial.print. It has to be done with function-calls of functions of a USB-HID-library (which I don't know the names because I haven't used one ever yet.

EDIT: I have looked up the examples: there is a entry called USB this entry has subentries keyboard-messages etc.

best regards Stefan

dougn0782: Alright, I have the Arduino Leonardo now.

All I want to do is have the 4x4 grid below print to applications on a PC. Is this possible with Keyboard.print() or something similar? Or can this not be done with the keypad 4x4 grid?

Look at the examples of the Keyboard library. Yes, it can be done.

I found this code in another forum and it functions just as I am hoping. I just need to modify the row and columns. Thanks for the inputs.

#include <Keypad.h>
#include <Keyboard.h>

const byte ROWS = 2; //two rows
const byte COLS = 2; //two columns

char keys[ROWS][COLS] = {
{‘1’,‘2’},
{‘3’,‘4’}
};
byte rowPins[ROWS] = {3, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
//Keyboard.write(“key”);
Serial.println(customKey); }

if (customKey == ‘1’){
Keyboard.write (‘A’);
}

if (customKey == ‘2’){
Keyboard.write (‘B’);
}

if (customKey == ‘3’){
Keyboard.write (‘C’);

}

if (customKey == ‘4’){
Keyboard.write (‘D’);

}
}