Pages: 1 2 [3] 4   Go Down
Author Topic: Attiny85 tone issue  (Read 9154 times)
0 Members and 1 Guest are viewing this topic.
Philadelphia
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you using Arduino IDE 1.0?

Yes.
Logged

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


http://arduino.cc/forum/index.php/topic,82011.0.html

Lowering the baud rate works...
http://code.google.com/p/arduino/issues/detail?id=661
https://github.com/arduino/Arduino/tree/master/build/shared/examples/ArduinoISP
https://github.com/arduino/Arduino/commit/80a2154279a02fd69f995ef6ff9eb889363c73ca

http://arduino.cc/forum/index.php/topic,84095.msg632561.html#msg632561
Logged

Philadelphia
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, I followed your advice and lowered the baud rates. It seemed to work...key word being "seemed". After making the changes, I restarted the IDE, loaded the ArduinoISP example and loaded it to the Arduino UNO with no errors.

Then I wired up the ATtiny85 to the UNO, set the programmer to "Arduino as ISP", and board to "ATtiny85 (internal 8MHz clock)" which I downloaded from here, as per the tutorial on the MIT HLT site.

I successfully burned the bootloader (save the "acceptable" error message: avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85.

Then I uploaded the sketch, getting only that same error message that, supposedly, shouldn't matter. However, the sketch did not load successfully, as when I hooked up my piezo, there was no sound. What's also odd is, I tried it a second time with the piezo still wired to the circuit on pin 0 (the designated pin for the tone() function in the sketch) and as the sketch was loading, I could hear beeps. It sounded like the progression of tones that are supposed to be generated, only at a MUCH slower pace, and no looping...but then again, it could have just been signals from the UNO passing through the circuit and generating bleeps and bloops as a result.

I'm severely stumped.
Logged

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


Does a Blink sketch work?
Logged

Philadelphia
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does a Blink sketch work?

No, as far as I can tell, but I lack LED's at the moment to test the sketch - I get the same error for the Blink sketch that I do with my own sketch:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
Logged

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


The PAGEL / BS2 warning is actually irrelevant (a cosmetic bug in avrdude).  You can ignore them.

Use the LED on the Uno.  Connect the Uno to the ATtiny85 for programming.  Upload a sketch to the '85 to blink on pin 2.  Leave all the programming wires in place.  The pin 13 LED on the Uno should blink.
Logged

Philadelphia
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have gotten the blink sketch to work before (using the Attiny85 core from the MIT HLT tutorial). But that's moot now, I have another update on the progress...

I got the sketch to upload and it plays through the iteration on a piezo! However, it iterates only once through the "void loop" function then sticks on that last "note" in the list. It's as if the loop function isn't working (or like the ATtiny85 doesn't support the loop function?). Can anyone see anything wrong with the code itself or is this still a hardware issue with the Attiny85? I haven't changed the code at all (except for the pin out # to match the corresponding ATtiny85 pin) since I successfully tested it on the Arduino UNO board.

Here's the code again for reference:

Code:
#include "pitches.h"

int melody[] = {
  NOTE_CS4, 0, NOTE_CS8, 0, NOTE_CS4, 0, NOTE_CS8, 0, NOTE_EE, 0, NOTE_DS8, 0, NOTE_EE, 0, NOTE_DS8, 0,
  NOTE_CS4, 0, NOTE_CS8, 0, NOTE_CS4, 0, NOTE_CS8, 0, NOTE_EE, 0, NOTE_DS8, 0, NOTE_EE, 0, NOTE_DS8, 0,
      NOTE_DS7, 0, NOTE_DS8, 0, NOTE_DS7, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0,
      NOTE_DS7, 0, NOTE_DS8, 0, NOTE_DS7, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0,
          NOTE_CS5, 0, NOTE_DS8, 0, NOTE_CS5, 0, NOTE_DS8, 0, NOTE_GG, 0, NOTE_DS8, 0, NOTE_GG, 0, NOTE_DS8, 0,
          NOTE_CS5, 0, NOTE_DS8, 0, NOTE_CS5, 0, NOTE_DS8, 0, NOTE_GG, 0, NOTE_DS8, 0, NOTE_GG, 0, NOTE_DS8, 0,
      NOTE_DS7, 0, NOTE_DS8, 0, NOTE_DS7, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0,
      NOTE_DS7, 0, NOTE_DS8, 0, NOTE_DS7, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0, NOTE_FF, 0, NOTE_DS8, 0, };

int noteDurations[] = {
  30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80,
  30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80,
  30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80,
  30, 80, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
  30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80,
  30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80,
  30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80, 30, 80,
  30, 80, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, };

void setup() {

}

void loop() {

  for (int thisNote = 0; thisNote < 128; thisNote++) {

    int noteDuration = 100/noteDurations[thisNote];
    tone(0, melody[thisNote],noteDuration);

    int pauseBetweenNotes = noteDuration * 1.20;
    delay(pauseBetweenNotes);

    noTone(0);
  }
}
Logged

Philadelphia
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And one more thing I just noticed - the tone stops after about 2-3 minutes. Not sure if that's a hardware issue, maybe even a voltage issue since the ATtiny85 is still hooked up to the Arduino 5v supply and the transistor is still in place?
Logged

Offline Offline
Edison Member
*
Karma: 56
Posts: 2183
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thisNote < 128

thisNote < 127  ?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

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


Storage space required by melody: 16*8*2 = 256
Storage space required by noteDurations: 16*8*2 = 256
Total = 512

From the datasheet...
Non-volatile Program and Data Memories ... 512 Bytes Internal SRAM

Your sketch is using too much SRAM.  I suspect melody and noteDurations could both be byte cutting the memory used in half.
Logged

Washington
Offline Offline
God Member
*****
Karma: 30
Posts: 779
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

melody and noteDurations should be in PROGMEM.
Any static array bigger then a few bytes should be in PROGMEM on a microcontroller.
http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html
http://arduino.cc/en/Reference/PROGMEM
http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Does the HLT core not support Tone?

I don't know for sure, at the bottom of the page on the HLT site, it includes this statement:
Quote
The following Arduino commands should be supported:

    pinMode()
    digitalWrite()
    digitalRead()
    analogRead()
    analogWrite()
    shiftOut()
    pulseIn()
    millis()
    micros()
    delay()
    delayMicroseconds()
By the time I had finally figured out how to actually get the !@#$%!@# thing to program via Arduino as ISP (dealing with the baud rate issue you have now posted) I was not feeling charitable enough to the HLT core to give it the benefit of the doubt. I had come across other threads of yours resolving my other issues and saw you state in this thread that it absolutely did support tone. I therefore switched.

Is there a list of commands that your core supports, or failing that, can you tell me if it supports random()?

Lazy Glen
Logged

Washington
Offline Offline
God Member
*****
Karma: 30
Posts: 779
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Does the HLT core not support Tone?

I don't know for sure, at the bottom of the page on the HLT site, it includes this statement:
Quote
The following Arduino commands should be supported:

    pinMode()
    digitalWrite()
    digitalRead()
    analogRead()
    analogWrite()
    shiftOut()
    pulseIn()
    millis()
    micros()
    delay()
    delayMicroseconds()
By the time I had finally figured out how to actually get the !@#$%!@# thing to program via Arduino as ISP (dealing with the baud rate issue you have now posted) I was not feeling charitable enough to the HLT core to give it the benefit of the doubt. I had come across other threads of yours resolving my other issues and saw you state in this thread that it absolutely did support tone. I therefore switched.

Is there a list of commands that your core supports, or failing that, can you tell me if it supports random()?

Lazy Glen
random() is quite easy to implement:
Code:
long random(unsigned long min, unsigned long max){
        if(min > max){return 0;}
        return min + (rand() % (max - min));
}
Note: untested
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

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


The Tiny Core is 100% compatible with Arduino 0022.  random is available.  As a bonus, tone supports "direct hardware output"; quality is better and no CPU time is needed.  Just use an output pin for the timer.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Excellent, thank you.

I realize this may be more of a hardware question, but you have been very helpful.

I'm trying to use PIN 0 and PIN1 as PWM outputs to drive an LED, as well as use the TONE function to output a frequency on pin 3. PWM does not appear to be working though. The sketch works fine (with changed pins) on a DCBoArduino. Is this an issue of expecting too much from the timer in such a small chip or am I not doing something right in my code?

Code:
  const int RED = 0;
  const int GRN = 1;
  const int BLU = 2;
  int RedVal = 0;
  int GrnVal = 0;
  int BluVal = 0;

void setup() {               
  // Define LED pins, set them to outputs and write a high to them, this turns OFF the Common Anode
  // LED's.
 
  unsigned long duration;

  pinMode(RED, OUTPUT);
  digitalWrite(RED, HIGH);

  pinMode(GRN, OUTPUT);
  digitalWrite(GRN, HIGH);

  pinMode(BLU, OUTPUT);
  digitalWrite(BLU, HIGH);

  delay(1000);  //give things a second to calm down

}
void loop() {
  int i = 0;
 
  pinMode(3, OUTPUT); 
  tone(3, 1000);
 
  for (i = 0; i <=255; i++)
    {
      analogWrite(RED, i);
      analogWrite(GRN, (255 - i));
      delay(25);
    }
  for (i = 0; i <=255; i++)
    {
      analogWrite(GRN, i);
      analogWrite(RED, (255 - i));
      delay(25);
    }
   
   
 /*
  RedVal = random(0, 250);
  analogWrite(RED, RedVal);   // set the LED (common anode)
  GrnVal = random(0, 250);
  analogWrite(GRN, GrnVal);   // set the LED (active low)
//delay(random(100,1000));            // wait for a bit
  delay (1000);
*/
}

The random portion was not working so I backed up to a simple constant change on red and green. What I get is a fairly constant Orange, then a Red flash, constant Orange, Green flash repeat.

Thank you

Lazy Glen
Logged

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