Help with school project with Arduino Pro Micro

Hello all, I am currently working on a macropad project for school. It is essentially a 2x3 arrangement of Cherry MX Switches that are connected to an Arduino Pro Micro that output letters, words, macros etc. when the switches are pressed. I am using the Keyboard library, with the keymap defined by a 2D matrix of the keys. Originally, I had problems uploading the code to the Arduino as it was giving me some errors named "butterfly" or something similar, I can't exactly remember. However, resetting the board whilst uploading the code had fixed it. The code has uploaded to the board with no errors, but pressing the switches does not work. Occasionally, random characters will be outputted that arent even in the code. Now whenever plugged in, all three red lights on the Arduino turn on. Resetting the board (connecting rst to grnd) does not do anything as the three red lights still turn on after a few seconds. I am very new to Arduino, so I'm not sure how to work around this problem. Also warning, I am very bad at soldering lol. I have provided the code and pictures of the wiring. Any help is super appreciated! Thanks.

#include <Keyboard.h>

const int numRows = 2;
const int numCols = 3;
const int rowPins[numRows] = {10, 16};
const int colPins[numCols] = {15, 18, 19};

// Define the keymap
char keys[numRows][numCols] = {
  {'1', '2', '3'},
  {'4', '5', '6'}
};

void setup() {
  Keyboard.begin();
  for (int i = 0; i < numRows; i++) {
    pinMode(rowPins[i], INPUT_PULLUP);
  }
  for (int i = 0; i < numCols; i++) {
    pinMode(colPins[i], OUTPUT);
    digitalWrite(colPins[i], HIGH); // Add this line to set columns to HIGH initially
  }
}

void loop() {
  for (int col = 0; col < numCols; col++) {
    digitalWrite(colPins[col], LOW);
    for (int row = 0; row < numRows; row++) {
      if (digitalRead(rowPins[row]) == LOW) {
        Keyboard.write(keys[row][col]); // Use Keyboard.write to simplify keypress
        delay(200); // Adjust for debounce
      }
    }
    digitalWrite(colPins[col], HIGH);
  }
}

First,,,read the instruction details at the beginning of the forum on how to post etc.
Second...supply a drawing ( no fritzing) of your complete ( including power supply) circuit.
Third.....details on how you uploaded code using what as programmer and how you did it.
Fourth.....use a simple code such as modified blink to ensure you are uploading correctly.

1 Like

Did you intend to use "Keyboard.h" library for a six-button matrix? Your "keymap" looks more like a "Keypad"... but you would need to change your sketch where "keyboard" keywords are used.

https://dronebotworkshop.com/keypads-arduino

And your compiler might not like the following defined as const int ... try byte

const int rowPins[numRows] = {10, 16};
const int colPins[numCols] = {15, 18, 19};

This error:

Was addressed here... (they also say to reboot, but add more)

Hello dominokiddingg

Welcome to the worldbest Arduino forum ever.

I´m curious.

Why aren't the buttons read in and processed with an arduino-standard button manager?

Have a nice day and enjoy coding in C++.

this spare 16 bytes of flash. not really much in this case.

I think the problem was the library method wanted "byte"

Keyboard.h ?

Keypad.h

With only 6 keys you do not need to do a matrix as it appears you still have a lot of GPIO available.


You can pass an integer to a function expecting a byte. Try this:

unsigned char aByte;
short int anInteger;
unsigned short int anUnsignedInteger;

# include <stdio.h>

void function(unsigned char argument)
{
    printf("%d\n", argument);
}

int main()
{
    printf("Hello World\n");
    
    aByte = 42;
    function(aByte);
    
    anInteger = 512 + 42;
    function(anInteger);
    
    anInteger = 0xf007;
    function(anInteger);
    
    anUnsignedInteger = 0xfffff007;
    function(anUnsignedInteger);

    return 0;
}

Produces a warning because the online compiler uses 4-byte ints.

In all cases, the value used in the function appears to be the least significant 8 bits. As you might hope and expcet.

I think this is part of a hole world of C/C++ implicit type conversions we enjoy around calling functions.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.