Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I am trying to "shrink" my arduino project to an Attiny85. But for some reason I cannot get an input button to work on the Attiny85? To simply the circuit and to make sure I didnt make a mistake somewhere I took everything off except for a button and an LED. First I tried it on the Arduino and used the example from http://arduino.cc/en/tutorial/button to try a simple example. I changed the ledPin to 10 which I plugged into my breadboard, through a resistor, to the LED and to ground. I plugged the button into pin 2 on the arduino and connected the ground wire of the button to a 10k resistor, then to ground. All of that works.

So then before I upload it to the tiny I changed the ledPin to 0 or 1 (it works on either one - I uploaded a simple blink sketch without the button code to test the LED) and then left the button pin to 2 as is shown by the diagram here http://www.pighixxx.com/pgdev/Temp/attiny.pdf or http://hlt.media.mit.edu/?p=1695 but nothing happens when the button is pressed. If I reverse the logic so the LED is on unless the button is pressed, then the LED is always on.

I cannot figure out what I am doing wrong. The same wiring works with the arduino, but I cannot get the attiny to register the button press. The final goal with the button would be to use the attachInterrupt(0, increment, CHANGE); for the button, but I cannot get even a simple sketch to work.

Any help is much appreciated! Thanks in advance!

Edit1:

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  1;      // the number of the LED pin

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

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

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}
share|improve this question
    
Show the code. I've managed to get both the button and debounce sketches working on an '85. –  Ignacio Vazquez-Abrams Sep 21 '13 at 4:20
    
That code works perfectly here. Verify operation and pinout of the switch, as well as continuity of the wires. –  Ignacio Vazquez-Abrams Sep 21 '13 at 4:38
    
But if it works as expected with the Arduino and I am not changing anything then all that should be fine? I will look into that though now that I know that the code is correct and I didnt miss an important step. –  Elmer Sep 21 '13 at 4:43
    
your description of the button connection sounds wrong. You should connect one terminal of the button to ground, and the other to the input pin, then connect a resistor from the input pin to Vcc (or switch to Vcc and resistor to ground, if you prefer). Your description says you have the switch and resistor in series between the input pin and ground, which is unlikely to work. –  Peter Bennett Sep 21 '13 at 5:11
    
@PeterBennett I was following the steps as shown here http://arduino.cc/en/tutorial/button is this incorrect? I might add that it works as expected using the Arduino... –  Elmer Sep 21 '13 at 5:27
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.