I have this sketch which I use to control my TV volume. I tried it on my arduino nano and it works fine on my TV. The problem starts when I use the same code on my ATyiny85 the IR led sends the signal way too slow and my TV doesn't recognize it. I can see the blink using my phone camera and it's real slow.
I tried changing internal clock to 1MHz down from 8MHz and tested a red led on digital pin 4 of ATtiny85 and the interval looked like it was fixed, but when I connect that led to pwm pin 1 on ATtiny85 through a 2n2222a transistor then the red led is blinking too slow again.
What could be the problem?
here is the code
#include <IRremote.h>
#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
void setup()
{
irsend.sendPanasonic(PanasonicAddress, PanasonicVolumeDown); //IR signal Volume Down
delay(200);
irsend.sendPanasonic(PanasonicAddress, PanasonicVolumeDown); //IR signal Volume Down
delay(200);
}
void loop()
{
}
Library "Arduino-IRremote-master" attached. Documentation says this library supports Attiny85.
Additional info
-Power source = 18650 battery 3.7V 800mAh
-Components - Red led (for testing) with 150 ohm resistor, 2N2222A transistor with 500ohm base resistor connected to PWM pin 1 on ATyin85
-Arduino IDE version 1.8.4 , ATiny core by David A. Mellis v1.0.2
Robin2:
I am not going to download a huge ZIP file - it could contain stuff that is harmful to my PC.
My wild guess is that you are not compiling the Attiny code with the correct processor speed.
You can easily test that by getting the Attiny to blink an LED at 1 second intervals and check if they really are 1 second intervals.
...R
You don't have to download it, I attached it in case somebody asks me to do it. Anyways the same library can be found in Github.
First I did it with 8MHz clock speed and the Blink was way too slow at delay(1000) for red led at pin 4. Then I tried 1MHz clock speed and the blink matched the speed of the Arduino nano. But using this code on pin 1 on ATtiny85 with 1MHz clock speed and the blink is way to slow. I can literally see the red led pulsing because it's that slow.
Noobian:
First I did it with 8MHz clock speed and the Blink was way too slow at delay(1000) for red led at pin 4. Then I tried 1MHz clock speed and the blink matched the speed of the Arduino nano. But using this code on pin 1 on ATtiny85 with 1MHz clock speed and the blink is way to slow. I can literally see the red led pulsing because it's that slow.
I can't be sure I understand that.
First of all, when you say "I did it with 8MHz clock speed" do you mean that that is the clock speed you chose when compiling the program?
Then, for the piece I have marked in blue, how long was the actual blink?
And for the piece I have marked in green, how long was the delay() and how long was the actual blink?
Likewise, for the piece in red, what was the program you tried?
What clock speed do you want your Attiny to operate at and have you set the fuses in the Attiny to give you that clock speed?
Robin2:
I can't be sure I understand that.
First of all, when you say "I did it with 8MHz clock speed" do you mean that that is the clock speed you chose when compiling the program?
Then, for the piece I have marked in blue, how long was the actual blink?
And for the piece I have marked in green, how long was the delay() and how long was the actual blink?
Likewise, for the piece in red, what was the program you tried?
What clock speed do you want your Attiny to operate at and have you set the fuses in the Attiny to give you that clock speed?
...R
Yes, I selected clock speed "Internal 8MHz" in Tools->Clock setting when I uploaded the sketch using "Upload Using Programmer"
The piece in Blue -> When delay was (1000) the led turned ON for ~8seconds and then OFF for ~8 seconds when clock was set at 8MHz internal clock. Pin 4
The piece in Green -> delay was unchanged (1000) and the led turned ON for ~1 second and then OFF for ~1 second when the clock was set at 1MHz internal clock. Pin 4
The piece in Red -> I tried two programs, One was the included Example 01.Basics-Blink Sketch on both Pin 1 and Pin 4 and the Blink was successful at ~1 second delay like in "The piece in green" when at 1MHz.
Then I tried the second program, which is the IR code which I posted here and the result was the blink was way too slow. led was ON for ~3seconds and OFF for ~2 seconds. The delay was just (200) this time but it stayed OFF for like 2 seconds.
I want my ATtiny to operate at 1MHz and I have not set any fuses in my ATtiny85.
Noobian:
The piece in Blue -> When delay was (1000) the led turned ON for ~8seconds and then OFF for ~8 seconds when clock was set at 8MHz internal clock. Pin 4
The piece in Green -> delay was unchanged (1000) and the led turned ON for ~1 second and then OFF for ~1 second when the clock was set at 1MHz internal clock. Pin 4
That clearly suggests that the Attiny is operating at 1 MHz.
I am not familiar with the IRemote library. Maybe it can't work at 1MHz? However I don't see any code for an LED in the program in your Original Post. Maybe there is another program you have not been showing us?
The documentation page in Github states that ATtiny85 is supported. besides I have tried the same code with an ATtiny13a and the sketch would not upload correctly and returns with an error because ATtiny13 has only 1 timer and the library does not support ATtiny13.
Robin2:
However I don't see any code for an LED in the program in your Original Post. Maybe there is another program you have not been showing us?
I did post the code correct. Here is the code for the LED in that sketch
I have not declared any pins because it cannot be done. The pins for the Send LED is predefined for each type of boards. For ATtiny85 it happens to be pin 1. On Nano that pin is 3. This is once again mentioned in that Github page.
I misunderstood. I thought when you said (Reply #4) "the result was the blink was way too slow." that you were referring to an LED that would blink once per second to check the timing.
It would probably be a good idea to add that to the program to see what happens.
I had a quick look at the Github link and I could not see anything about the expected clock speed for the Attiny.
I think they have selected "8MHz" as the board settings and not actually uploaded an 8MHz bootloader to have the Interal Oscillator set as the CLK source at 8MHz..
Robin2:
In Reply #4 the OP said he wants it to work at 1MHz.
...R
Ah Sorry.
Then yeah, I still suggest:
Ensuring the OP has burnt the boot-loader before uploading a sketch.
defining F_CPU as 1000000 in their sketch #define F_CPU 1000000
Not sure if F_CPU gets set somehow already when burning a bootloader (is it stored in EEPROM or something)...but I once had an issue with timing on an ATTiny85 and defining F_CPU helped.
Ensuring the OP has burnt the boot-loader before uploading a sketch.
defining F_CPU as 1000000 in their sketch #define F_CPU 1000000
Not sure if F_CPU gets set somehow already when burning a bootloader (is it stored in EEPROM or something)...but I once had an issue with timing on an ATTiny85 and defining F_CPU helped.
I tried it exactly like you've said and still no change.
Maybe there is something in the library code which needs changing.
I saw another post where a user says he also added
You could just take parts of the code you need to write your own functions. Set up timer0 yourself and make your own function for the data protocol using their library function?
I have a feeling now this isn't a library problem. Upload a schamtic please. Also a screenshot of your settings and a a step-by-step "clean install" procedure you are following and also your code.
Robin2:
The first thing you need to do is confirm that the library code is intended to work on an Attiny running at 1MHz.
If you can't find any documentation about that then maybe you should set up your Attiny to run at 8MHz and see if the library works properly then.
I tried 8MHz before I tried 1MHz. at 8MHz the led takes forever to blibk. Tried bootlaoder on both clock speeds, no change.
Johnny010:
I have a feeling now this isn't a library problem. Upload a schamtic please. Also a screenshot of your settings and a a step-by-step "clean install" procedure you are following and also your code.
Robin2:
That is because you have NOT changed the Attiny to work at 8MHz. Just telling the IDE that the Attiny is working at 8MHz does not change the Attiny.
I also burned the bootlaoder at 8MHz while both IDE setting was at 8MHz and with "#define F_CPU 8000000" in the sketch.
There has been some interesting developments after I did like what you suggested in post #7. I added another led to pin 4 to see the result and here's what I found out.
I moved the IR code from setup to loop so that I can observe more easily. Then I changed the delay to (50000) and the led on pin 4 blinks at ~1 second (Not exactly 1 second but close). The led on pin 1 lights up for ~50 milli seconds maybe and turns off for ~1 second and does this again. I believe the pwm is executed but the timing is not yet correct as I tried with IR led and my tv still doesn't recognize the signal.
The issue might be with the timing?? The board is set to run at 8MHz.
I'm uploading my schematic and screenshot of settings.