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


Below is my code (debug code) that I am trying to make work with ATTiny85. I am trying to use this sensor (
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 .

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 ( 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.
  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 ()
  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);
  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

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
Offline Offline
Shannon Member
Karma: 176
Posts: 12283
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which core are you using?

Pages: [1]   Go Up
Jump to: