Interrupts on PB0 or PB1 on ATTiny45 using Arduino IDE.

Hello and welcome - my first post here!

I've got a problem with my project. I had it workin ot ATMega328 but now I wont to port in to ATTiny45. Can anyony help me with attaching interrupt on PB0 or PB1?

This doesn't work:

pinMode(1, INPUT);
attachInterrupt(1, pchange, HIGH); //I have tried with 0 and checked both pins.

Thank you!

Ekci: Hello and welcome - my first post here!

I've got a problem with my project. I had it workin ot ATMega328 but now I wont to port in to ATTiny45. Can anyony help me with attaching interrupt on PB0 or PB1?

This doesn't work:

pinMode(1, INPUT);
attachInterrupt(1, pchange, HIGH); //I have tried with 0 and checked both pins.

I'm not sure if/how the tiny cores support attachInterrupt but I think the Tiny45 has only one pin compatible to it's use and that's PB2 (INT0). If the core supports it then it would mean using attachInterrupt(0, pchange, HIGH);

Right! It’s working - I haven’t seen it before because my delays were too fast. Now I’ve set fuses for 8MHz and it’s better, but still delay(1000) looks like 250-500ms. Is there any way to fix it?

BTW: Is there any chance to unbricked AVR with fuses set to external crystal without actually having it?

Ekci: Now I've set fuses for 8MHz and it's better, but still delay(1000) looks like 250-500ms. Is there any way to fix it?

There is either a bug in your code, you have the wrong board selected, or you did not set the fuses correctly.

BTW: Is there any chance to unbricked AVR with fuses set to external crystal without actually having it?

Yes. You only need to provide a reasonable clock signal on XTAL1. Lady Ada (aka Ada Fruit) has published a version of ArduinoISP that outputs such a clock signal. I believe Nick Gammon also has something that works. Or, TinyISP available from the following will work (after making a configuration change)... http://code.google.com/p/arduino-tiny/downloads/list http://code.google.com/p/arduino-tiny/source/browse/?repo=isp

Great! Lady Ada's software has helped me :) Thank you!

Ok, back to my delay... This is simple code in interrupt (looped):

  digitalWrite(3, HIGH);
  delay(1000);
  digitalWrite(3, LOW);
  delay(1000);

I have burned bootloader using ATTiny45 @ 1MHz board from: https://code.google.com/p/arduino-tiny/

And then load my app. It's blining 4-5 times per second. With 8MHz it is blinking so fast that I almost can't see it. The best setting was burning bootloader using 1MHz and then sending application with 8MHz selected - it gave me about 200-500 ms delay with delay(1000).

What am I doing wrong? :)

EDIT: Or maybe not... I'm confused. Every time I'm changing something it seems different smiley Now it works, thank you again!

Ah, another problem with ATTiny… I will ask here, I don’t want to spam this forum with new topics.

analogWrite works only as HIGH and LOW. 0 is LOW and 1-255 is treated like HIGH with same % of voltage output.
This means that dimming diode with this code doesn’t work:

    for (greenIntensity = 0; greenIntensity <= 255; greenIntensity++) {
      analogWrite(GREEN_LED_PIN, 3);
      delay(220);
    }

Is there any way to force it to work? For example ATMega328 works like a charm with my code.

Ekci: I have burned bootloader using ATTiny45 @ 1MHz board from: https://code.google.com/p/arduino-tiny/

And then load my app. It's blining 4-5 times per second. With 8MHz it is blinking so fast that I almost can't see it.

After changing the board setting you have to execute Burn Bootloader to change the fuses on the processor.

Ekci:
analogWrite works only as HIGH and LOW. 0 is LOW and 1-255 is treated like HIGH with same % of voltage output.
This means that dimming diode with this code doesn’t work:

    for (greenIntensity = 0; greenIntensity <= 255; greenIntensity++) {

analogWrite(GREEN_LED_PIN, 3);
      delay(220);
    }

GREEN_LED_PIN does not support pulse-width modulation. Use a pin that does.