[SOLVED] ATtiny85 - It's not working for me.

Well after developing my code for a High-Power LED Controller on a Pro Mini 3.3v 8mhz board, it seems porting it to the Attiny85 isn’t working. I’ve downloaded and installed the Attiny_master cores from the High-Low Tech tutorial and uploaded my code via Arduino as ISP, with no issues. But when power is applied, it does absolutely nothing. I’ve also tried a second Attiny85, with the same results.

I’ve set Pins 2, 3 and 4 to digital inputs using the PinMode() function, I also used the digitalWrite() function to set the internal pullup resistors.

Any help would be most appreciated :frowning:

Kind regards

Lewis

We can only guess at your problem, unless you post your code.

...and schematic.

Here’s my code:

const int Switch = 4;
const int Accent = 2;
const int Blade = 0;
const int Sensor = 3;
const int Flash = 1;
int state = 0;
int reading;
int previous = HIGH;
long time = 0;
long debounce = 200;
boolean running = false;
int accState = LOW;
long prevMillis = 0;
long interval = 3000;

void setup()
{
pinMode(Switch, INPUT);
pinMode(Blade, OUTPUT);
pinMode(Sensor, INPUT);
pinMode(Accent, OUTPUT);
digitalWrite(Switch, HIGH);
digitalWrite(Sensor, HIGH);
digitalWrite(Accent, HIGH);
delay(250);
digitalWrite(Accent, LOW);
}

void loop()
{

unsigned long currentMillis = millis();

if((currentMillis - prevMillis > interval) && (state == 0)) {

prevMillis = currentMillis;

if (accState == HIGH)

accState = LOW;

else

accState = HIGH;

digitalWrite(Accent, accState);

}
{

reading = digitalRead(Switch);
auxswitch = digitalRead(aux);

if (reading == LOW && previous == HIGH && millis() -

time > debounce) {
if (state == 255) {
while(state > 0) {

state–;

analogWrite(Blade, state);
digitalWrite(Accent, LOW);
delayMicroseconds(800);
}
}
else if (state == 0) {
while(state < 255) {

state++;

analogWrite(Blade, state);
digitalWrite(Accent, HIGH);
delayMicroseconds(800);
}
}
time = millis();
}
previous = reading;

{

if(digitalRead(Sensor) == LOW && (state == 255))
{
running = !running;

analogWrite(Flash, 250);
delay(30);
analogWrite(Flash, 255);
delay(20);
analogWrite(Flash, 255);
delay(20);
analogWrite(Flash, 255);
delay(30);
analogWrite(Flash, 250);
}

if(digitalRead(Sensor) == HIGH && (state == 255))
{

analogWrite(Flash, 0);

}

}

Any constructive criticism and suggestions is also appreciated

Regards

Lewis

That code is really hard to read because of the double (and greater) spacing. If you edit your post to remove most of the blank lines, then it will be easier for us to make sense of it.

Code updated. Sorry about that, it seems using the "Copy for forum" on my Linux version of Arduino doesn't work properly.

Some suggestions:

  1. Have you programmed the fuses in the ATtiny, or are you using the default 1MHz clock?

  2. Post your schematic.

  3. To check whether the programming and fuses are OK, try programming the ATtiny with the Blink sketch and see if that works.

OK, it's accepting the Blink sketch, which I tried with all the pins. However, it is not blinking for 1 second (roughly half a second) and from what I can understand; it's a timing issue. I set the fuses for 8 Mhz using the "Burn Bootloader" function, so I assume the inaccurate timing is correct when running at 8 Mhz? Even though in comparison to my 3.3v Pro Mini, it's very inaccurate.

The internal 8MHz clock should be accurate to within 10%. If it's blinking for half a second instead of 1 second, then it sounds like you compiled the sketch for 8MHz but are actually running it at 16MHz (which you could only do using an external clock or crystal), or you compiled it for 4MHz but are running it at 8MHz. What is F_CPU set to in the board configuration you used when you compiled it?

It was set to 1 Mhz, so I changed it to 8 Mhz; which solved it! Cheers dc42, much appreciated!

Regards

Lewis