Hi: I am very new to this whole thing and am interested in making some simple led candles as my first project using programming written by other more experienced members. All of these have worked great when running from my Uno type clone board and look very realistic. I wanted to use an ATtiny85 to run these programs in the finished candle (small size obviously). I have succeeded in using the UNO to program the ATtiny85 (thanks to High-Low Tech!) but find that the results in the flickering candle are choppier and less realistic than I remember on the UNO even though I am using exactly the same sketches with only pin outs changed to accommodate the ATtiny.
Should the result not be the same as before? Am I expecting too much of the little device or simply missing something very obvious? Is it related to the 1 Mhz clock speed of the Attiny perhaps?
My 63 year old brain is sometimes slow to grasp some of these things and electronics are very new to me so any guidance you can give me about getting the same results with the ATtiny85 as I had with the Uno would be appreciated.
Thanks in advance.
Lee
Is it related to the 1 Mhz clock speed of the Attiny perhaps?
Yes (and no). It's a combination of the 1 MHz clock speed and the prescaler used to configure the timers. The simplest path is to change the fuses so the processor runs at 8 MHz.
Thanks so much for the very quick response. I am assuming that changing the fuse is not something that can be done via the UNO the way I did the programming? I assume from my quick googling that I need to get some kind of hardware programmer to achieve this? May be beyond my meager tech capabilities at the moment I expect!
Is it possible to do this change with what I have or is there a hardware programmer you could recommend that I should use?
Thanks again. I really appreciate the guidance.
Lee
Hey Lee,
In Arduino....Change your board to the Attiny85 @ 8Mhz (or something of that like) and then goto Tools -> Burn Bootloader. That will change the fuses so you're running at 8Mhz.
goodluck!
Wow! I think that worked. I just did what you suggested and burned the bootloader and everything seems to be working. One stupid question. Is there any way to verify that it really is running at 8Mhz (just in case I did something wrong and nothing actually changed?)
In any case thanks so much for your help. I've learned more from the two member responses than I would have done myself in a lot of searching.
Lee
leefy:
Is there any way to verify that it really is running at 8Mhz (just in case I did something wrong and nothing actually changed?)
Connect an LED + resistor to pin 4 (physical pin 3) and run this...
#include <util/delay_basic.h>
const uint8_t LedPin = 4;
void __attribute__ ((noinline)) EightMillion( void )
{
for ( uint8_t i = 31; i > 0; --i )
{
_delay_loop_2( 62499 );
}
asm volatile
(
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
);
}
void setup( void )
{
pinMode( LedPin, OUTPUT );
}
void loop( void )
{
digitalWrite( LedPin, ! digitalRead( LedPin ) );
EightMillion();
}
The code delays exactly eight million clock cycles between blinks (assuming I did the math correctly; plus the overhead from loop, digitalRead, and digitalWrite). If the processor is running at 1 MHz the LED will blink every eight seconds. If the processor is running at 8 MHz the LED will blink every second. If the processor is running at 16 MHz the LED will blink every ½ second.
Fantastic! Tried your sketch and I'm running at 8Mhz confirmed. Thanks for all your help.
Lee
You are welcome. Glad you have it working.