Go Down

Topic: Button (digitalRead) not working on pin 39? (Read 1 time) previous topic - next topic

KurtE

I have a shield, that I mentioned in a different thread.  I have a button on IO pin 39, which if I watch with Logic Analyzer is pulled down to zero when I press the button.  However my code is not detecting it.  I will double check it again with Analyzer, but here is a simple test case:
Code: [Select]
#define LED1  13
#define BUTTON1 39
unsigned long lLast;
boolean fLedOn;

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(BUTTON1, INPUT);
  Serial.begin(38400);
  Serial.println("Test Start");
  fLedOn = false;
  lLast = millis();
}

void loop() {
  if (!digitalRead(BUTTON1)) {
    Serial.println("Button pressed");
    while (!digitalRead(BUTTON1)) {
      delay(50);
    }
  }
  if((millis()-lLast) > 250) {
    fLedOn = !fLedOn;
    digitalWrite(13, fLedOn);
    lLast = millis();
  }
}
   

I never get the button pressed message... Suggestions?
Thanks
Kurt


Grumpy_Mike

Is it only pin 39 or will it not work with any input pin?

retrolefty

And is your button on pin 39 using a needed and proper pull-up or pull-down method? I don't see the internal pull-up being enabled for pin 39?

Lefty

KurtE

Thanks,

I am not sure yet about other IO pins.  I do have buttons on 2 other IO ins 41 and 43, but found I was short on parts.  Order with those should arrive next day or so.

I do have a 10K PU resistor connected to IOREF voltage and the IO line side of the button.  The other side of button connected to ground.  I have also tried with configuring the pin as INPUT_PULLUP, no difference.

Thanks
Kurt




KurtE

So far it is looking to me like I am not getting input on any of the IO pins.  I tried removing the shield and the like and use a jumper wire, I tried, for example looping from IO pins 2-12 doing a digitalInput and print out a message if it goes low.  I used pinMode(i, INPUT_PULLUP); on these pins.  Did not get any inputs that worked here...

Suggestions?  Is my due screwed up?  I believe I tested some yesterday or the day before to show that I could do output to these pins.

Kurt

Go Up