Author Topic: An INPUT_PULLUP pin always reading low.  (Read 6376 times)

thule.arch@gmail.com

  • Newbie
  • *
  • Posts: 6
An INPUT_PULLUP pin always reading low.
« on: September 12, 2016, 08:40:42 am »
Hi there

I am trying to make a digispark read a pin that has been pulled up and then act if the pin has been grounded. I read that attiny does have internal pullup resistors. In my following code, if I test for input on sw1 being LOW, it never activates. Where is if I test for high, understandably, it runs all the time. May be I got something wrong. However similar code, with bza changed to 13, runs on arduino uno and behaves with the onboard led as expected. Turning on the LED when the sw1 is grounded and off when pulled high, that is.

Am I missing something or attiny does not have the pullup resistors ?


Code: [Select]
int sw1=5; //momentary switch to pull down the pin 1
int bza=1; //ping buzzer/led is connected to LED on digistump
 
void setup() {
  pinMode(sw1, INPUT_PULLUP);
  pinMode(bza,OUTPUT);
}



void buzzer(){
  digitalWrite(bza, HIGH);
  delay(500);
  digitalWrite(bza, LOW);
  delay(500);
}

void monpins(){
  if (digitalRead(sw1)==LOW) {buzzer();}
}


void loop() {
 monpins();
}


Thanks a lot.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: An INPUT_PULLUP pin always reading low.
« Reply #1 on: September 14, 2016, 01:15:56 am »
No, not missing anything code-wise. The code makes the P1 LED on my digispark blink (500ms on, 500ms off) if I connect P5 to GND. Double check you are wiring your button to P5, as that is the IO pin referenced by your code (whereas the comment says 1, which is the LED ;).

thule.arch@gmail.com

  • Newbie
  • *
  • Posts: 6
Re: An INPUT_PULLUP pin always reading low.
« Reply #2 on: September 15, 2016, 08:13:37 pm »
Hi

Thanks for the reply. I didn't update the comment as I was desperately swapping it between pins to see if any of them work! The same code on a nano/uno works find with similar connects.

I will retry and see. May be I killed the board with my soldering  :P

Thanks