Go Down

Topic: ATtiny and tone() (Read 14471 times) previous topic - next topic

Mixe

No worries, I haven't. Like I wrote: the errors are automatically corrected by the compiler, like it says in the error message, and the code compiles anyway. So I haven't done anything to correct them.

silly_cone

Weird, mine would not compile using that core; it gave a "Problem compiling for ...." message.   I'll go back and give it another go, then report back.

Coding Badly

I too get error messages when compiling...
That is a warning.  The IDE produces it.  It can be ignored.


silly_cone

here is the complete compiler output:

Code: [Select]

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -hardware "C:\Users\Alan\AppData\Local\Arduino15\packages" -hardware "C:\Users\Alan\Documents\Arduino\hardware" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -tools "C:\Users\Alan\AppData\Local\Arduino15\packages" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "C:\Users\Alan\Documents\Arduino\libraries" -fqbn=tiny:avr:attiny85at16p -ide-version=10609 -build-path "C:\Users\Alan\AppData\Local\Temp\build6b670ed53e9cccc2da9fe5b6ba847dfa.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "C:\Users\Alan\AppData\Local\Temp\arduino_modified_sketch_850444\sketch_feb07a.ino"
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -hardware "C:\Users\Alan\AppData\Local\Arduino15\packages" -hardware "C:\Users\Alan\Documents\Arduino\hardware" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -tools "C:\Users\Alan\AppData\Local\Arduino15\packages" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "C:\Users\Alan\Documents\Arduino\libraries" -fqbn=tiny:avr:attiny85at16p -ide-version=10609 -build-path "C:\Users\Alan\AppData\Local\Temp\build6b670ed53e9cccc2da9fe5b6ba847dfa.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "C:\Users\Alan\AppData\Local\Temp\arduino_modified_sketch_850444\sketch_feb07a.ino"
Warning: Board tiny:avr:attiny85at16p doesn't define a 'build.board' preference. Auto-set to: AVR_ATTINY85AT16P
Warning: Board tiny:avr:attiny85at8 doesn't define a 'build.board' preference. Auto-set to: AVR_ATTINY85AT8
Warning: Board tiny:avr:attiny85at1 doesn't define a 'build.board' preference. Auto-set to: AVR_ATTINY85AT1
Warning: Board tiny:avr:attiny85at16e doesn't define a 'build.board' preference. Auto-set to: AVR_ATTINY85AT16E
WARNING: Spurious .github folder in 'Adafruit MMA8451 Library' library
Warning: platform.txt from core 'Arduino Tiny' contains deprecated tools.avrdude.cmd.path={runtime.ide.path}/hardware/tools/avr/bin/avrdude, automatically converted to tools.avrdude.cmd.path={path}/bin/avrdude. Consider upgrading this core.
Warning: platform.txt from core 'Arduino Tiny' contains deprecated tools.avrdude.config.path={runtime.ide.path}/hardware/tools/avr/etc/avrdude.conf, automatically converted to tools.avrdude.config.path={path}/etc/avrdude.conf. Consider upgrading this core.
Warning: platform.txt from core 'Arduino Tiny' contains deprecated recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}", automatically converted to recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}". Consider upgrading this core.
Warning: platform.txt from core 'Arduino Tiny' contains deprecated recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm, automatically converted to recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{archive_file_path}" "-L{build.path}" -lm. Consider upgrading this core.
"avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections  -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16000000L -DARDUINO=10609 -DARDUINO_AVR_ATTINY85AT16P -DARDUINO_ARCH_AVR  "-IC:\Users\Alan\Documents\Arduino\hardware\tiny\avr\cores\tiny" "C:\Users\Alan\AppData\Local\Temp\build6b670ed53e9cccc2da9fe5b6ba847dfa.tmp\sketch\sketch_feb07a.ino.cpp" -o "nul"
"avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections  -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16000000L -DARDUINO=10609 -DARDUINO_AVR_ATTINY85AT16P -DARDUINO_ARCH_AVR  "-IC:\Users\Alan\Documents\Arduino\hardware\tiny\avr\cores\tiny" "C:\Users\Alan\AppData\Local\Temp\build6b670ed53e9cccc2da9fe5b6ba847dfa.tmp\sketch\sketch_feb07a.ino.cpp" -o "nul"
"avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections  -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16000000L -DARDUINO=10609 -DARDUINO_AVR_ATTINY85AT16P -DARDUINO_ARCH_AVR  "-IC:\Users\Alan\Documents\Arduino\hardware\tiny\avr\cores\tiny" "C:\Users\Alan\AppData\Local\Temp\build6b670ed53e9cccc2da9fe5b6ba847dfa.tmp\sketch\sketch_feb07a.ino.cpp" -o "C:\Users\Alan\AppData\Local\Temp\build6b670ed53e9cccc2da9fe5b6ba847dfa.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
exec: "avr-g++": executable file not found in %PATH%
Error compiling for board ATtiny85 @ 16 MHz  (internal PLL; 4.3 V BOD).

silly_cone

#19
Feb 07, 2017, 06:34 pm Last Edit: Feb 07, 2017, 06:45 pm by silly_cone
Okay, I found instructions here for getting the compiler to work.  It now compiles without any errors, but I am still getting no tone.

The closest I can get is to just use PWM for the rough sounding tone.  If I set the clock speed to 1 MGHz, and the frequency to 2,000 then I get an unsteady output of clicks, but if I change the clock speed and keep everything else stable, I don't even get that.  If I keep the clockspeed at 1MGHz and set the output frequency to 10,000, then I get a buzzing, but not a clean tone.  Raising the frequency above 10,000, even as high as 50,000 makes no further change in the sound.

DrAzzy

#20
Feb 10, 2017, 08:11 pm Last Edit: Feb 10, 2017, 08:12 pm by DrAzzy
Sorry for the late reply here - I was sick in bed all week.

The compiler output indicates that you're not using my core - you may have it installed, but you also have at least one other core for the ATTiny, and you've selected a board definition from that core, not from mine.

The name of the board def supplied by my core for the Tiny85 series is "ATtiny25/45/85", and it will be under the ATTinyCore heading - you can then select the clock speed and which specific chip you're using from the tools menu.

If you use my core, Tone() should work.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

silly_cone

Hi DrAzzy, I've switched a lot of things around a few times, so to save you from having to read everything in detail, I'll sum it up for you: 

I tried using the latest version of your core at multiple clock speeds.  Everything compiled with no issues, but there was simply no tone.  I tried using several pins, and several attiny's, all with the same effect.  I even attempted multiple piezos of different types.  The piezos work when hooked up to a nano, but the attiny's won't work.  To verify that the pins were working, I tested them with PWM on an LED, which worked fine.  I'm pretty positive that your core and no others were at play because I uninstalled them from the boards manager and preferences before loading yours, then restarted arduino before compiling.

Then I switched to a different core that I linked to in an above post, which also did not work.  That was the core that produced the compiler errors that, you are correct, indicate that your core was not being used.

silly_cone

after many frustrating hours of repeated failure, I've decided the only way this is going to work is to use the TinyTone() function that can be found here

I'm beyond clueless why neither DrAzzy's core nor the Tiny Core linked to by the OP work in my setup, but they don't.  They fail at every clock speed, every frequency, on every pin, every chip, and every buzzer.

DrAzzy

I am too. I haven't had a chance to look into this, I haven't been feeling well the past week or so.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

kprims

My limited tests with attiny85 using a $.95 development board and ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager.

Code: [Select]
void setup() {
 pinMode(4, OUTPUT);
}

void loop() {
  tone(4, 2000);
}


Had to hook up buzzer to vcc and other lead to pin 4. If no tone, reverse leads.

Next sketch.

Code: [Select]
#define PIEZO 1

void setup(){
pinMode(PIEZO, OUTPUT);
}

void loop(){
tone(PIEZO,500);
delay(1000);
noTone(PIEZO);
delay(1000);
}


On this sketch it works for me with leads on gnd and pin1. Again, you may have to reverse leads to get tone.

silly_cone

SONNOFABITCH!!!!!!  It NEVER occurred to me to reverse the leads!  I've always used piezos with the the 2nd lead connected to GND, not VCC.  Even with this same buzzer and same function on a nano, the leads don't need reversed.  But for the attiny for some reason they do!?

I can't believe I've been stumped for like a week over backwards leads!!!!!

Thank you profusely for making this as easy as it should've been all along!!!!!!!!   :smiley-red:

DrAzzy

#26
Feb 15, 2017, 09:17 pm Last Edit: Feb 15, 2017, 09:18 pm by DrAzzy
*adds a piezo buzzer to his ebay shopping cart*

That's bizzaro - I've never worked with those things before (obviously - and sort of strangely, considering that I have literally hundreds of drawers of parts, plus a 2 cubic foot bin of parts in static bags because I ran out of drawers) - I know most are polarized. But if it works on the nano in either polarity, it should work on a tiny in either polarity.... Unless you just got lucky when you hooked it up to the nano?

Also kprims, thanks loads, this is one thing I don't have to do.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

silly_cone

#27
Feb 15, 2017, 09:56 pm Last Edit: Feb 15, 2017, 10:02 pm by silly_cone
okay, so polarity was NOT the problem.  I did some more testing and narrowed it down to the need for a minimum delay of 1 millisecond for the tone function to work.

This code produces a tone:
Code: [Select]

void setup(){
pinMode(4, OUTPUT);
}

void loop(){
    tone(4,2000);
    delay(1);
}


this code produces nothing except tears and anger:
Code: [Select]

void setup(){
pinMode(4, OUTPUT);
}

void loop(){
    tone(4,2000);
    //delay(1);
}


I didn't think the polarity issue made sense considering that the buzzer worked fine on the nano regardless of polarity, but who was I to question success?  Then I made some code changes and got nothing, so I knew it had to be something different.  Still not sure why the delay(1) is needed on the attiny85 and not the nano, but it works, so I'm happy.

Here is the specific buzzer I'm using, FYI: CPT-9019S-SMT

kprims

This is getting beyond my pay grade. :-)

But just to tag along. Both types of piezo's I have will work with the original sketch. I do have a small 8 ohm 2w speaker that will not work with  the original  sketch, but will work with the delay.

DrAzzy

#29
Feb 15, 2017, 11:10 pm Last Edit: Feb 15, 2017, 11:11 pm by DrAzzy
Aaaaha!

Thanks for that. I think I know what the problem is, it's gotta be resetting the timer count when tone() gets called, so you get considerably different output, it's not going to be fun to fix, since it's #ifdef hell and timer1 on the tiny85 is weird. I mean, I can't imagine what else it could be, but that explanation totally makes sense.

I suspect your tone will sound subtly different with delay(1) vs delay(10) there!

I'll make an issue for it. https://github.com/SpenceKonde/ATTinyCore/issues/111
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up