creatrope

If you've verified you're running sketches ok, and verified you can blink an LED on this pin, it's time to check whether the buzzer polarity might be a factor, whether the buzzer is damaged, and to try a real 8 ohm speaker (with an additional small resistor). Another reasonable step would be to try your buzzer with another Arduino.

nickelbake95

Just to rule out the piezo itself, since you have it already connected on one of the ATTiny PWM pins, can you get a sound from it using analogWrite

AnalogWrite does not produce a sound.

Quote

it's time to check whether the buzzer polarity might be a factor

It's a non polar buzzer, which works no problem with the arduino itself.

Despite these not being the problem, I found the solution: there was an older ATTiny core that I never removed. It was overriding the new core with the tone() function. Once I removed the older core, the new one took effect and now the project works fine. Thanks to everyone for their help!

I can't get tone or any PWM to work on PB3 but PWM works fine on PB0 (ATTiny85).

I was using Arduino 0022 with v 0012 of the tiny cores but I just installed the newest versions of each (1.03 & v0015) and that's made no difference. I also wondered whether it was a fuse setting but I have used "burn bootloader", which I understand sets the fuses for the 'Tiny. I've also tried two different chips - just in case I had managed to fry something - and that doesn't seem to make a difference either.

Is there some initialisation of the ATTiny that you should do on first use, or something, that I might have missed?

Any ideas appreciated.

Ugi

PS I'm running the ATTiny at 1MHz off a 3v lithium CR2032 button cell, if that could concievably make a difference

I just ran the test sketch below using tone on D3 then D4 and both results were equivalent. tone() works on PB3 and PB4 based on my tests. I used an 8Ohm speaker and two different piezos for the tests (they sounded terrible in contrast - I'll stick to speakers for this kind of thing I think !)

void loop() { for(int val = 30; val < 3000; val++) { tone(testPin, val); delay(5); } for(int val = 3000; val >30; val--) { tone(testPin, val); delay(5); } noTone(testPin);}So while that worked, analogWrite() on PB3/D3 actually didn't which agrees with your findings. It was a hard flash rather than the pulse I'd intended so acted as a digitalWrite. I'm certain analogWrite() has worked for me in the past on PB3 but when I went back through past sketches I've not kept a sketch that used it. Not at all certain on that one now.

Anyway I can confirm tone() works with the above sketch, so if it doesn't for you I'd be looking elsewhere. I tested on an ATTiny85 running at 8MHz off a CR2032 3V cell - the only other component on my test rig is a 0.1uF decoupling cap.

Cheers ! Geoff

"There is no problem so bad you can't make it worse" - retired astronaut Chris Hadfield