4 x 4 keypad not working

Hi everyone! i am trying to make a very simple 4 x 4 keypad, as my keyboard doesn’t have a number keypad on it.I do a lot of trading and require typing in numbers a lot into my broker,so I want to make a simple keypad Hid using a Xiao rp2040 and a generic 4 x 4 key pad. i have tried every which way and cannot get the keypad to work. nothing comes up in serial monitor when i press a button i can load the code and it compiles OK. if i use an Arduino Uno it works fine to serial monitor so keypad is working.
My code is bellow and i have wired the keypad directly to the Xiao. many thanks for your help

#include <Keypad.h>

#include <Adafruit_TinyUSB.h>

const byte ROW_NUM = 4; //four rows

const byte COL_NUM = 4; //four columns

char keys[ROW_NUM][COL_NUM] = {






byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad

byte pin_column[COL_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COL_NUM);

// USB HID object

Adafruit_USBD_HID usb_hid;

// HID report descriptor using TinyUSB’s template

// Single Report (no ID) descriptor

uint8_t const desc_hid_report[] = {



void setup() {



usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));


// wait until device mounted

while( !USBDevice.mounted() ) delay(1);


void loop() {

char key = keypad.getKey();

if (key) {


uint8_t keycode[6] = { 0 };

keycode[0] = key - '0';

usb_hid.keyboardReport(1, 0, keycode);