Electrical – interfacing external push button to msp430 using energia

energiamsp430pullupserial

I am writing code in Energia using the mso430g2553 launchpad and an external pushbutton with a pullup resistor. The code should simply display the state of the button on the serial monitor, 1 for pressed, 0 for unpressed. This is the code I am using:

int pushButton = 5;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
// NOTE this is different from the on-board pushbutton
pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {

// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1);        // delay in between reads for stability
}  

This is the circuit configuration I am using:

enter image description here

My problem is that when I run the program, I always get 0 no matter if the button is pressed or not. It seems like the program is not reading the input from the button, or I connected the button wrong way. However I can't seem to find the problem, I tried turning the button for 90 degrees and I connected opposite legs of the button to ground and to the pin. Would a solution be to add a debouncing capacitor maybe? Any help would be much appreciated!

Best Answer

Per OP in comments, as questioned by @TomCarpenter, the issue was the orientation of the 4 pin tact switch OP was using. The switched connection was not being used, tying P1.3 to ground permanently.