Pages: [1]   Go Down
Author Topic: Trouble with ATTiny85 attachInterrupt.  (Read 1732 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: September 20, 2012, 07:48:15 pm by cimon » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12910
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Which core are you using?
Logged

Pages: [1]   Go Up
Jump to: