u/East_Loquat2349

Image 1 — ButtonMatrix problem on Teensy 4.1
Image 2 — ButtonMatrix problem on Teensy 4.1
Image 3 — ButtonMatrix problem on Teensy 4.1
▲ 10 r/ArduinoHelp+1 crossposts

ButtonMatrix problem on Teensy 4.1

I am working on a project replicating the omnichord which requires a custom keyboard. For this, I chose to use the Teensy 4.1 for its pins and audio capabilities. I had a previous version on ESP-32 limited by the pins where I had the keyboard functional, but upon migrating to the Teensy board I have run into troubles

On the teensy, when pressing certain buttons (mainly on row 1, a few on row 2, and none on row 3) the value and the consecutive value both trigger. I have vigourously tested if my diodes were the problem, but after these tests and considering its perfect working condition on ESP-32, I was led to the conclusion it was either something wrong with the Teensy pins (written out in program) I am using or the program itself.

I have also tried working with multiple other keyboard matrix libraries, including the one native to the Teensy, but none have the features I need for this project. I have included pictures of my matrix and wires as well as the code I currently have, and I would appriciate any input you might have. Thanks!

Specific Library link : https://github.com/ReneRichterDE/ButtonMatrix

#include <Arduino.h>
#include "ButtonMatrix.h" 
#include "Wire.h"


volatile int button = '0';
volatile int lastButton = '0';
using namespace RSys;


static const uint32_t c_uiMonitorBaud = 115200; 


const uint8_t ROWS = 3; 
  const uint8_t COLS = 13; 


  Button buttons[ROWS * COLS] = {
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 37,
  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 28,
  25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 39
};
  uint8_t rowPins[ROWS] = {38,39,40}; 
  uint8_t colPins[COLS] = {5,6,7,8,9,10,11,12,26,27,28,29,30}; 
  


ButtonMatrix matrix((Button*)buttons, rowPins, colPins, ROWS, COLS);


void setup()
{


  
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  // column pins: inputs, external pull-ups
  for (int i = 0; i < COLS; i++) {
    pinMode(colPins[i], INPUT_PULLUP);
  }


  matrix.init();  
}



void loop()
{ 
   pollKeyboard();
}



void pollKeyboard() {
  Button* pButton = NULL;
  const uint16_t numButtons = matrix.getNumButtons();
  
  /*if(!matrix.update() && button != 37){
     button = -1;
  }
  */
  //button = -1;


  if (matrix.update()) {


    for (uint16_t idx = 0; idx < (numButtons-1); idx++) {
      pButton = matrix.getButton(idx);


      if (pButton->isPressed()) {
        Serial.print("Button pressed: ");
        Serial.println(pButton->getNumber());
        button = pButton->getNumber();



      }
    }
  }
  //delayMicroseconds(10);
  
}
u/East_Loquat2349 — 11 days ago