Go Down

Topic: [SOLVED] ATtiny85 - It's not working for me. (Read 1 time) previous topic - next topic

LifesAuthentic

Jun 10, 2013, 03:45 pm Last Edit: Jun 12, 2013, 02:38 pm by LifesAuthentic Reason: 1
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  :(

Kind regards

Lewis


hiduino

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


Coding Badly


LifesAuthentic

#3
Jun 10, 2013, 04:14 pm Last Edit: Jun 11, 2013, 12:20 pm by LifesAuthentic Reason: 1
Here's my code:

Quote

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

dc42

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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

LifesAuthentic

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

dc42

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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

LifesAuthentic

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.

dc42

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?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

LifesAuthentic

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

Regards

Lewis

Go Up