Go Down

Topic: Trouble with ATTiny85 attachInterrupt. (Read 2010 times) previous topic - next topic

cimon

Sep 21, 2012, 02:46 am Last Edit: Sep 21, 2012, 02:48 am by cimon Reason: 1
Hello

Below is my code (debug code) that I am trying to make work with ATTiny85. I am trying to use this sensor (http://www.seeedstudio.com/depot/datasheet/water%20flow%20sensor%20datasheet.pdf)
I was able to detect and work with sensor on an arduino uno.

I use the attachInterrupt function with Arduino using the  external interrupt 0 which is available on digital pin 2 of arduino .

Quote
attachInterrupt(0,chk, RISING);


Now I am trying to make this sensor work on ATTiny85 but ATtiny does not seem to detect the sensor.
I was thinking that to use the attachInterrupt with Attiny we need to know which pin is the interrupt 0 . In the data sheet for Attiny (http://www.atmel.com/Images/doc2586.pdf) on page 50 it says that INT0 is the External Interrupt Request 0 and from the ATTiny diagram on page 2 it shows that INT0 is PB2 pin, so I attached hall sensor to PB2 but that does not seem to detect the sensor.

I checked that my Arduino and Attiny85 are working fine using the blink code and then modified it.
Quote

/*
 ATTINY85
 Blink
 Turns on an LED on for one second, then off for one second, repeatedly.

 This example code is in the public domain.
*/


int led = PB0;
int led2= PB1;
int Sensor = PB2;
volatile int val;

void chk ()
{
 val++;
 digitalWrite(led2, HIGH);
}
 
// the setup routine runs once when you press reset:
void setup() {                
 // initialize the digital pin as an output.
 pinMode(led, OUTPUT);  
 pinMode(led2, OUTPUT);
 pinMode(Sensor,INPUT);
 attachInterrupt(0,chk, RISING);
}

// the loop routine runs over and over again forever:
void loop() {
 digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(1000);               // wait for a second
 digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
 delay(1000);     // wait for a second
 sei();
}



Can anyone help with using the interrupt with Attiny85.

Thank you

Coding Badly


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy