ATtiny85 way too slow IR

Noobian:
I also burned the bootlaoder at 8MHz while both IDE setting was at 8MHz and with "#define F_CPU 8000000" in the sketch.

If you did that then you would not be reporting (Reply #17)

I tried 8MHz before I tried 1MHz. at 8MHz the led takes forever to blibk.

Have you tried Nick Gammon's diagnostic programs to see what the Attiny settings really are?

...R

delay(50000);

50,000 ms = 50 seconds?

Noobian:
here's the new code

Don't use delay() to manage the timing because then the timing gets confused with the IR function. Have a look at how millis() is used to manage timing without blocking in Several things at a time.

And just use an LED interval of 1 second so that you can verify it easily against your watch.

...R

Johnny010:
50,000 ms = 50 seconds?

Correct, but the led is blinking at ~1 second interval.

Robin2:
Don't use delay() to manage the timing because then the timing gets confused with the IR function. Have a look at how millis() is used to manage timing without blocking in Several things at a time.

And just use an LED interval of 1 second so that you can verify it easily against your watch.

Ok , so here's what I did now. I copied the blink without delay example code into this sketch and made some observations. If I do not use the ir.send code then the led blinks at the correct interval of 1 second.
If I use that line of code then the timer goes wrong like it happened before.

I'm posting my code here.

#include <IRremote.h>

#define F_CPU  8000000
#define __AVR_ATtiny85__
#define PanasonicAddress      0x4004     // Panasonic address (Pre data) 
#define PanasonicVolumeDown   0x1008485  // Panasonic Volume Down button

IRsend irsend;  // Fixed output pin for IR LED on ATtiny85 is 1

const int ledPin =  4;
int ledState = LOW;            
unsigned long previousMillis = 0;        
const long interval = 1000;         

 
void setup()
{
    pinMode(ledPin, OUTPUT);
}
void loop() 
{
    unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) 
  {
    previousMillis = currentMillis;
    if (ledState == LOW) 
    {
      ledState = HIGH;
      irsend.sendPanasonic(PanasonicAddress, PanasonicVolumeDown);  //This line is what causes timing issues
     
    } 
    else 
    {
      ledState = LOW;
    }
    digitalWrite(ledPin, ledState);

  }

}

If I remove irsend.sendPanasonic(PanasonicAddress, PanasonicVolumeDown); line of code then the blink works without any issues.
If I don't then the timing is no longer correct and led blinks super fast. I tried changing const long interval = to 5000; (Five thousand)and now the led blinks at almost 1 second interval. Not exactly 1 second but close.
Also when I changed interval to 5000 then ATtiny takes like 10 to 15 seconds to reach the loop function after uploading the code.

1 Like