Reading 6 Buttons with Common ground

Hello.

I am using a Teensy 3.1 as an HID Keyboard, and I am trying to read input from 6 different buttons. To save space and make my soldering easier and less time consuming, I tried to create a common ground and input voltage for all of my buttons (3v from the teensy). However, although I have an analog stick sending input and know that the code is correct, I am getting no input from the buttons.

Here is the code I am trying to use (YES, I have tried testing the input with Serial, there is no change):

int a_value = digitalRead(aPin);
if(a_value == HIGH)
  Keyboard.set_key3(KEY_A);
  
int b_value = digitalRead(bPin);
if(b_value == HIGH)
  Keyboard.set_key4(KEY_B);
  
int x_value = digitalRead(xPin);
if(x_value == HIGH)
  Keyboard.set_key5(KEY_X);
  
int y_value = digitalRead(yPin);
if(y_value == HIGH)
  Keyboard.set_key6(KEY_Y);

Keyboard.send_now();

// Key 1 and 2 were the Arrow Key sends from analog stick
Keyboard.set_key1(0);
Keyboard.set_key2(0);
Keyboard.set_key3(0);
Keyboard.set_key4(0);
Keyboard.set_key5(0);
Keyboard.set_key6(0);

Here is a diagram of the button setup attached (same colors connect at junctions but don’t with different colors):

EDIT:: Turns out there was a voltage wired to a data line.

Now that I've rewired it and place the voltage to the correct place on the button, all inputs are set to ON. It just keeps typing abxyabxyabxy... forever. And I don't mean that they're all set to high and I have to read low, I mean that all of the buttons are stuck on HIGH.

It seems that your inputs are always HIGH. Why not pare back and get just one switch to do one simple thing first?

It would help immensely if you posted all the code. By definition you don't know what is wrong because you are asking what is wrong. So why do you think you know enough to be able to pick out the bit of your code where the error is? Let me tell you, you can't.

Rest of code:

#define JOY_X_AXIS A0
#define JOY_Y_AXIS A1

const int xMin = 150; // left
const int xMax = 800; // right
const int yMax = 800; // up
const int yMin = 300; // down

//const int move_speed = 10;

const int aPin = 1;
const int bPin = 2;
const int xPin = 3;
const int yPin = 4;

const int startPin = 5;
const int selectPin = 6;
/*const int lPin = 7;
const int rPin = 8;*/

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

  // First send keys
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);

  // Second send keys
  pinMode(startPin, INPUT);
  pinMode(selectPin, INPUT);
//  pinMode(lPin, INPUT);
//  pinMode(rPin, INPUT);
}

void loop() {
  /* FIRST KEY SEND */
  int x_axis_value = analogRead(JOY_X_AXIS);
  int y_axis_value = analogRead(JOY_Y_AXIS);
  
  if(x_axis_value < xMin) { // left
    Keyboard.set_key1(KEY_LEFT);
  } else if(x_axis_value > xMax) { // right
    Keyboard.set_key1(KEY_RIGHT);
  }

  if(y_axis_value < yMin) { // down
    Keyboard.set_key2(KEY_DOWN);
  } else if(y_axis_value > yMax) { // up
    Keyboard.set_key2(KEY_UP);
  }

  int a_value = digitalRead(aPin);
//  if(a_value == HIGH)
//    Keyboard.set_key3(KEY_A);
    
  int b_value = digitalRead(bPin);
//  if(b_value == HIGH)
//    Keyboard.set_key4(KEY_B);
    
  int x_value = digitalRead(xPin);
//  if(x_value == HIGH)
//    Keyboard.set_key5(KEY_X);
    
  int y_value = digitalRead(yPin);
//  if(y_value == HIGH)
//    Keyboard.set_key6(KEY_Y);

  
  Serial.print("A: ");
  Serial.println(a_value);
  Serial.print("B: ");
  Serial.println(b_value);
  Serial.print("X: ");
  Serial.println(x_value);
  Serial.print("Y: ");
  Serial.println(a_value);
  
  Keyboard.send_now();

  /* RESET KEYS FOR SECOND KEY SEND */
  Keyboard.set_key1(0);
  Keyboard.set_key2(0);
  Keyboard.set_key3(0);
  Keyboard.set_key4(0);
  Keyboard.set_key5(0);
  Keyboard.set_key6(0);
  
  delay(100);
}

Thanks for the code.

The topic title says "common ground" but you have not got a common ground the common point is the other side of the resistor from ground.

Simply connect your push buttons between the input and ground. The enable the internal pull up resistors on the inputs, like this:-

// FirstEnable the inputs
  pinMode(aPin, INPUT_PULLUP);
  pinMode(bPin, INPUT_PULLUP);
  pinMode(xPin, INPUT_PULLUP);
  pinMode(yPin, INPUT_PULLUP);

  // Second send keys
  pinMode(startPin, INPUT_PULLUP);
  pinMode(selectPin, INPUT_PULLUP);
//  pinMode(lPin, INPUT_PULLUP);
//  pinMode(rPin, INPUT_PULLUP);

Thank you. After finally rewiring it seems that the inner pullup resistor was what I needed to do. I t seems to be working now.

Thank you. After finally rewiring it seems that the inner pullup resistor was what I needed to do. I t seems to be working now.

I don't know if it was intentional, but I think you should know , they are not called "inner pullups". They are called INTERNAL pullups. That may mean absolutely nothing to you but I can tell for a fact that if you repeat that in the presence of any experienced engineer he is going to look at you funny. . Maybe it's a language thing. I don't know but let's just say, if you don't want to sound "inexperienced", say "Internal PUllups" .

Nothing personal you understand. Just consider it an "FYI" . It would be like a chemist saying "beaker " instead of "testtube". Nobody outside the industry would have a clue. But to the people who know it would "raise eyebrows" shall we say, if you know what I mean. I mean , you wouldn't tell your mother , for example. It is what it is. You dropped in. I'm here, just though I'd let you know , just in case you cared. (not that you should) For all I know it was a typo and you already knew. Consider it a "freebie".

Hope your not sensitive , ha ha.

Yes I know. I was fumbling for the right word, but I decided to go ahead and post where it would make sense at least. About 20 minutes later I realized the right word was "internal," and needless to say I gave myself a good facepalm! :) :P