Pages: [1]   Go Down
Author Topic: [SOLVED] ATtiny85 - It's not working for me.  (Read 893 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-sad

Kind regards

Lewis

« Last Edit: June 12, 2013, 07:38:57 am by LifesAuthentic » Logged

Wahiawa, Hawaii
Online Online
God Member
*****
Karma: 30
Posts: 633
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13027
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


...and schematic.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: June 11, 2013, 05:20:57 am by LifesAuthentic » Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6637
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6637
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6637
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Regards

Lewis
Logged

Pages: [1]   Go Up
Jump to: