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.
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.
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.
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!!!!!!!!
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.
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.
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
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.
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!
Anyone have any insight into why analogWrite would stop working on PB4 when tone() function is used in the sketch?
analogWrite still works on PB0 and PB1, but if I use the tone() command anywhere, even if its ended by a call to noTone(), analogWrite on PB4 is still dead.
Anyone have any insight into why analogWrite would stop working on PB4 when tone() function is used in the sketch?
analogWrite still works on PB0 and PB1, but if I use the tone() command anywhere, even if its ended by a call to noTone(), analogWrite on PB4 is still dead.
Which core is it? Is it my core?
If it's my core, please make an issue here: Issues · SpenceKonde/ATTinyCore · GitHub - my guess from the problem description is that it's an x5 series, but please confirm that. I also love code that reproduces problems, even really simple ones.