Attiny85

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
aggroz
 
Posts: 32
Joined: Sun Sep 08, 2013 8:22 pm

Attiny85

Post by aggroz »

So I programmed an Attiny85 with a simple blink sketch via my homemade programming board. All went well, it seems to have taken the code. Funny thing is, the simple blink sketch that is supposed to flash on and off ever second, takes about 8 seconds. It is not the code. Am I programming it incorrectly? I set the board as Attiny 85 with an 8 MHZ internal clock. Any other thoughts?

Thanks
Adam
Attachments
photoCA8UXBPK.JPG
photoCA8UXBPK.JPG (96.6 KiB) Viewed 2782 times

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Attiny85

Post by 1chicagodave »

So I programmed an Attiny85 with a simple blink sketch
Could we see that, please?
Can you post code?

aggroz
 
Posts: 32
Joined: Sun Sep 08, 2013 8:22 pm

Re: Attiny85

Post by aggroz »

Sure thing.

Code: Select all

/* Blink without Delay
 
 Turns on and off a light emitting diode(LED) connected to a digital  
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.
 
 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.
 
 
 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
 
 This example code is in the public domain.

 
 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used here to 
// set pin numbers:
const int ledPin =  1;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the 
  // difference between the current time and last time you blinked 
  // the LED is bigger than the interval at which you want to 
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Attiny85

Post by Franklin97355 »

What clock rate does the 85 run at?

aggroz
 
Posts: 32
Joined: Sun Sep 08, 2013 8:22 pm

Re: Attiny85

Post by aggroz »

All of my research states the 85 has an internal 8.0 MHz RC oscillator.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Attiny85

Post by adafruit_support_mike »

The clock itself runs at 8MHz, but the signal goes through a 'prescaler' before reaching the CPU. The prescaler can reduce the frequency all the way down to 32kHz, but 4MHz, 2MHz, and 1MHz are other options.

The details are on pages 32-33 of the ATtiny85 datasheet: http://www.atmel.com/Images/Atmel-2586- ... asheet.pdf

The prescaler's behavior is configured with 'fuse bits' that are set by the programmer, but aren't part of the code per se.

aggroz
 
Posts: 32
Joined: Sun Sep 08, 2013 8:22 pm

Re: Attiny85

Post by aggroz »

So any idea what I am doing wrong? I can seem to load sketches to this chip but they do not want to function properly. I an becoming sad, very fast :( I have no idea why this simple blink sketch is running 8 times slower than it should. I am assuming what ever is causing it, is causing my other sketches not to run as well.

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Attiny85

Post by 1chicagodave »

How are you programming it? Or...how did you program it? Are you using Arduino IDE? Which "programmer" option did you use?
What is your homemade programming board?

IF it is a clock issue, (which, if it takes exactly eight times longer to execute code....) this thread may shed some light.
http://forum.arduino.cc/index.php?topic=182138.0

aggroz
 
Posts: 32
Joined: Sun Sep 08, 2013 8:22 pm

Re: Attiny85

Post by aggroz »

Hey Dave,

I have an update for you. I selected a different board in the Arduino IDE. I selected the Attiny 85 1mhz board. When this is selected the timing is correct. The blink sketch functions properly. However, the more complicated sketches for the Neopixel will not run at 1 Mhz. It needs a little more.


Bottom line is I am closer but I think something is still wrong...


Thanks
Adam

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Attiny85

Post by 1chicagodave »

Yeah...
I just found your other threads with more info. Changing the clock speed does all kinds of interesting things of which I am not very familiar. I typically avoid messing with fuses unless I have to.

But, check out the thread I linked to in previous post. Your issue sound at least 'similar' enough that it may spark some ideas.

aggroz
 
Posts: 32
Joined: Sun Sep 08, 2013 8:22 pm

Re: Attiny85

Post by aggroz »

I stumbled across that thread earlier this evening. Thanks.

aggroz
 
Posts: 32
Joined: Sun Sep 08, 2013 8:22 pm

Re: Attiny85

Post by aggroz »

Dave and Forum,

Well after searching around on other forums, I have the answer. In none of the tutorials did I see this step. What needs to be accomplished is to set the board in the IDE to the Attiny85 (8Mhz). Then you click on tools in the IDE, and scroll to the bottom and select Boot loader. This then tells the 85 to operate at 8 Mhz. This only has to happen one time. After this step was completed, I was then able to load the sketch that required the 8 mhz chip option. All works perfectly.


Thanks for the help.

Adam

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”