Go Down

Topic: ATTiny85 tone() core? (Read 3 times) previous topic - next topic


Jan 23, 2013, 01:16 pm Last Edit: Jan 23, 2013, 01:18 pm by Dr_Ugi Reason: 1
I'm having a similar issue - at least it seems so.

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.


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


Hi Ugi

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 !)
Code: [Select]
const int testPin = 3;

void setup() {
  pinMode(testPin, OUTPUT);                   

void loop() {
  for(int val = 30; val < 3000; val++) {
  tone(testPin, val);
    for(int val = 3000; val >30; val--) {
  tone(testPin, val);

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


Thanks Geoff - I was also finding the "hard flash" effect - analogWrite(3,128) and analogWrite(3,0) are both equivalent to digitalWrite(3,LOW) but analogWrite(3,255) is equivalent to a digital HIGH.

I've got to work for a few hours now but will try out your test sketch this evening.




I just ran strykeroz sketch, and tone is working on all 5 pins
Also I checked PWM and ADC pins

Working PWM pins: PB4,PB0 and PB1

Working analogRead() on pins A1,A2 and A3


Thanks Guys - I tried swapping PB1 & PB3 (only one needs to be PWM) and it works fine on PB1.  Odd that - I'm sure I checked the datasheet when I was planning this project.

Anyhow, tone works on PB4 (&PB3) - I think that may have been down to my old version before - and PWM works on PB1, which will do me fine.

I don't understand how tone works on PB3 if PWM doesn't, but maybe that's a cunning interrupt-based version.

Thanks for your help.


Go Up