Raspberry PI input problem

I’m just trying to do a simple demo of two push buttons with two leds - each button will turn on a led when pushed, and turn off the led when not pushed.
My “blue” led button is working great, connected to GPIO 20 on the Raspberry PI. My “red” button is not working at all.
I’ve tried different GPIO for the “red” button, and swapped buttons and wires so I know my buttons are working. But the sketch is not working.
Does the Raspberry PI only support one GPIO input or is there something I am missing.

Here is my code:

// constants won't change. They're used here to set pin numbers:
const int blueButtonPin = 20;// the number of the pushbutton pin
const int redButtonPin = 4;
const int blueLedPin =  14;      // the number of the LED pin
const int redLedPin = 18;

// variables will change:
int blueButtonState = 0;         // variable for reading the pushbutton status
int redButtonState = 0;

void setup() {
  // initialize the LED pin as an output:
  pinMode(blueLedPin, OUTPUT);
  pinMode(redLedPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(blueButtonPin, INPUT);
  pinMode(redLedPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  blueButtonState = digitalRead(blueButtonPin);
  
  // check if the pushbutton is pressed. If it is, the blueButtonState is HIGH:
  if (blueButtonState == LOW) {
    // turn LED on:
    digitalWrite(blueLedPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(blueLedPin, LOW);
  }
  redButtonState = digitalRead(redButtonPin);
  if (redButtonState == LOW) {
    digitalWrite(redLedPin, HIGH);
  } else {
    digitalWrite(redLedPin,LOW);
  }
  
}

Any help would be great. Thanks - LeRoy, KD8BXP

Can you try using the Particle pin designators as shown in this pinout?

https://docs.particle.io/datasheets/kits-and-accessories/raspberrypi-datasheet/#pin-out-diagram

Does this make any difference?

Thanks for the reply…
I tried, it doesn’t make a difference.
My changes:
// constants won’t change. They’re used here to set pin numbers:
const int blueButtonPin = D15; //20;// the number of the pushbutton pin
const int redButtonPin = D0; //4;
const int blueLedPin = TX; //14; // the number of the LED pin
const int redLedPin = D11; //18;

I tried a different sketch - it is a toggle and it works fine with two buttons. So There is a problem I am not seeing in the original code, and I just don’t see it.
Since the “toggle” code works I will use it for my demo, and come back to the original code when I have some time.

Toggle Code:

#define BLED 14
#define RLED 18
#define SW1 20
#define SW2 4

int button1state = 0;
int button2state = 0;
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  //Console.println("Starting...");
  pinMode(BLED, OUTPUT);
  pinMode(RLED, OUTPUT);
  pinMode(SW1, INPUT);
  pinMode(SW2, INPUT);
  digitalWrite(BLED, LOW);
  digitalWrite(RLED, LOW);
}

// the loop function runs over and over again forever
void loop() {
  /*
  //Console.println("Blink");
  digitalWrite(BLED, HIGH);
  digitalWrite(RLED, LOW); 
  delay(50);                       // wait for a second
  digitalWrite(BLED, LOW);
  digitalWrite(RLED, HIGH);
  delay(50);                       // wait for a second
  */
  int readsw1 = digitalRead(SW1);
  int readsw2 = digitalRead(SW2);
  
delay(100);
  if (readsw1 == LOW) {
   button1state = !button1state;
  // Console.print("SW1 ");
  // Console.println(button1state);
    }
delay(100);
  if (readsw2 == LOW) {
   button2state = !button2state;
  }
  delay(100);
  digitalWrite(BLED, button1state);
  digitalWrite(RLED, button2state);
}

PS - I did see a mistake in the original code where I set the redLedPin to both OUTPUT and then later to INPUT - I fixed that and the original sketch still doesn’t work.

Just a little simplification

void loop() {
  digitalWrite(blueLedPin, !digitalRead(blueButtonPin));
  digitalWrite(redLedPin , !digitalRead(redButtonPin ));
}

And I’d suggest using INPUT_PULLUP or INPUT_PULLDOWN instead of INPUT to prevent floating pins on open switch.

I will give it a try.
I have resistors on the buttons, so didn’t think I needed the internal PULLUPs or PULLDOWNs - but I can also give that a try.
Thanks again for the help and info.
LeRoy

Didn’t know about your external pull-resistors. So you can stick with INPUT