Pages: 1 [2] 3   Go Down
Author Topic: ATtiny85 + Arduino  (Read 5263 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you follow the instructions in the readme.txt file?

I did, although there was one step which I don't really understand:

"Open the "boards.txt" file and change both of the "upload.using" entries to the appropriate value for your setup."

I had a go at it, but I guess I was wrong.  smiley-red

The LED is connected to a pin that does not support PWM.  Or, you have a bug in your Sketch.

Aah right, not all pins support PWM! I'm learning.  smiley-razz When set to pin 0, the LED behaves the same way described in my previous post except that turning the pot low doesn't turn the LED off. However, if the circuit is powered up with the pot turned low, the LED will be off until the pot is turned up to about 10%.

My sketch runs fine on the Arduino, but is there something other than the pins that I should change?
Logged

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

I know I'm missing something incredibly obvious, I just can't figure out what it could be. My sketch runs absolutely fine on the Arduino, but on the ATtiny85 it behaves very oddly. If anyone has any sort of suggestion I'd love to hear it, no matter how simple it is! I've really been tearing my hair out trying to get it work.  smiley-cry
Logged

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It might be worth adding a filter/decoupling cap between VCC and GND pins. 0.1uf is about right.
Your house may be especially noisy or something, who knows?

What is the sketch doing now?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12944
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you follow the instructions in the readme.txt file?
I did, although there was one step which I don't really understand:
"Open the "boards.txt" file and change both of the "upload.using" entries to the appropriate value for your setup."
I had a go at it, but I guess I was wrong.  smiley-red

You will need to modify the section that starts with this...

attiny85at1.name=ATtiny85 @ 1 MHz  (internal oscillator; BOD disabled)

Remove the pound-sign from the "arduino:arduinoisp" line and add a pound-sign for the "pololu" line...

# The following DO work (pick one)...
# attiny85at1.upload.protocol=avrispv2
attiny85at1.upload.using=arduino:arduinoisp
# attiny85at1.upload.using=pololu

Logged

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

You will need to modify the section that starts with this...

attiny85at1.name=ATtiny85 @ 1 MHz  (internal oscillator; BOD disabled)

Remove the pound-sign from the "arduino:arduinoisp" line and add a pound-sign for the "pololu" line...

# The following DO work (pick one)...
# attiny85at1.upload.protocol=avrispv2
attiny85at1.upload.using=arduino:arduinoisp
# attiny85at1.upload.using=pololu



I'm now able to upload using your core for the first time! My sketch now runs almost perfectly (see below), so a huge thank you for making and sharing your core, as well as your time and patience helping me.  smiley

It might be worth adding a filter/decoupling cap between VCC and GND pins. 0.1uf is about right.
Your house may be especially noisy or something, who knows?

What is the sketch doing now?

The smallest cap I have is 1uf, which I have between the VCC and GND pins. Is that too high?

After uploading my sketch using Coding Badly's core there's been major progress. It now works almost perfectly, but the LEDs don't fade out at all. Instead, at the time they are supposed to start fading, they simply turn off. I have the LEDs connected to pin 1 (physical pin 6) which supports PWM, but maybe somehow PWM isn't enabled...?

Edit: Also tried the LED output via pin 0, and it behaves the same.
« Last Edit: June 02, 2011, 09:27:54 am by Eli_Ben » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12944
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm now able to upload using your core for the first time!

Excellent.

Quote
so a huge thank you for making and sharing your core, as well as your time and patience helping me.  smiley

You are welcome.

Quote
The smallest cap I have is 1uf, which I have between the VCC and GND pins. Is that too high?

Someone else will have to answer the actual question.  I can tell you that 0.1 uF works very well.

Quote
It now works almost perfectly, but the LEDs don't fade out at all. Instead, at the time they are supposed to start fading, they simply turn off. I have the LEDs connected to pin 1 (physical pin 6) which supports PWM, but maybe somehow PWM isn't enabled...?   Also tried the LED output via pin 0, and it behaves the same.

How does this behave...

Code:
void setup( void )
{
  pinMode( 0, OUTPUT );
  pinMode( 1, OUTPUT );
}

void loop( void )
{
  for ( int i=0; i <= 255; ++i )
  {
    analogWrite( 0, i );
    analogWrite( 1, i );
    delay( 10 );
  }
  for ( int i=255; i >= 0; --i )
  {
    analogWrite( 0, i );
    analogWrite( 1, i );
    delay( 10 );
  }
}
Logged

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

Someone else will have to answer the actual question.  I can tell you that 0.1 uF works very well.

Ok, I'll order some.

How does this behave...

Thanks for that! I think it behaves properly: The LEDs both fade up and down in unison. My fade uses millis, could the problem be something to do with that?
« Last Edit: June 03, 2011, 07:20:58 am by Eli_Ben » Logged

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If that works and yours doesn't, there must be an oddball issue with your code somewhere.  I'm using millis on my attiny85 and other than self-induced duration issues (~62k millis to a second, it's semi-intentional though) it works fine.

No clue on the capacitor, sorry.
You can always try it.
Logged

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

If that works and yours doesn't, there must be an oddball issue with your code somewhere.  I'm using millis on my attiny85 and other than self-induced duration issues (~62k millis to a second, it's semi-intentional though) it works fine.

That's weird, because my code works fine on the Arduino. I thought that the ATtiny85 will accept Arduino code, but I guess not in this case? I don't really know what else to try. I can't use delay to fade because I want the LEDs to illuminate as soon as the sound goes over the threshold, even during a fade, and I read that delay prevents anything else happening.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12944
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Your Sketch relies on analogRead so the next step is to verify that analogRead is working the way you expect. 

Start with the Arduino.  Build a simple Sketch that outputs analogRead value to Serial (with a delay).  Make certain the Sketch works and that the values seems to be reasonable.

Move the Sketch to the ATtiny85.  Are the results the same?
Logged

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

Ok, would this sketch from the Arduino IDE examples be suitable?

Code:
/*
  AnalogReadSerial
 Reads an analog input on pin 0, prints the result to the serial monitor
 
 This example code is in the public domain.
 */

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue, DEC);
}

It works on the Arduino (of course) but the serial monitor shows nothing when the sketch is uploaded to the ATtiny85. Do I need to change something to get Serial working on the ATtiny85?

Edit: Thinking about it, my sketch appears to demonstrate that analogRead does work on the ATtiny85, because the threshold can be correctly set using the potentiometer.
« Last Edit: June 05, 2011, 10:48:39 am by Eli_Ben » Logged

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You'll need to do some creative wiring to get serial out of an attiny, it won't go out via arduinoISP or another ISP setup.
Logged

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

The fact that my sketch allows correct adjustment of the sound threshold with a potentiometer using analogRead on the ATtiny85 seems to suggest that analogRead works ok. What do you guys think?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12944
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, would this sketch from the Arduino IDE examples be suitable?

Looks good to me.

Quote
It works on the Arduino (of course) but the serial monitor shows nothing when the sketch is uploaded to the ATtiny85.  Do I need to change something to get Serial working on the ATtiny85?

Difficult to say.  You haven't provided enough information.  Which core did you decide to use?  What serial-to-USB converter are you using?  How do you have the converter connected?

Quote
Edit: Thinking about it, my sketch appears to demonstrate that analogRead does work on the ATtiny85, because the threshold can be correctly set using the potentiometer.

Sounds like it.  In which case it's time to take a closer look at your Sketch.  All the code that manipulates fadeLight...

Quote
int           fadeLight   =    0 ; // LED brightness value for fading.

 fadeLight    = 0;                       // Reset the fade brightness int.

    fadeLight    = fadeLight - fadeAmount;// Reduce the LED brightness int by an amount specified by 'fadeAmount')

  analogWrite(ledPin, fadeLight);         // Set the LED brightness to the amount now specified by the 'fadeLight' int.

  fadeLight = 0;                          // Reset the 'fadeLight' int.

fadeLight is always a negative int value bounded to zero.  analogWrite does not clamp the value so, when the value changes from -256 to -257 the value actually written to the hardware goes from 0 (full off) to 255 (full on).  There is an assumption that the fading stops at -90 but that may not be true because of the next problem...

timeThen needs to be initialized in the then-clause of this if-statement...

Quote
if (soundLevel >= threshold)

Finally, I doubt the application will be running continuously for 49 days but, if it is, it will not work correctly.  millis values and addition (and direct comparison) do not mix.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12944
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You'll need to do some creative wiring to get serial out of an attiny, it won't go out via arduinoISP or another ISP setup.

It does here.

But I've modified Arduino ISP to support relaying Serial data.   smiley-grin  I also made some minor changes to Arduino ISP that make it much faster.  I'll include the modified Arduino ISP in a future update to the core.
Logged

Pages: 1 [2] 3   Go Up
Jump to: