Using the tone library with ATTiny85

Hi everyone,

I’m currently trying to make an RTTTL player out of an ATTiny85, using an Uno as a programmer.

I’m having trouble getting the RTTTL example of the tone library to work on the ATTiny. Here are the types error messages I’m getting back, there are more but that would exceed the character limit for my post:

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:480:9: note: in expansion of macro 'bitWrite'

         bitWrite(TIMSK1, OCIE1A, 1);

         ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:483:9: error: 'OCR2A' was not declared in this scope

         OCR2A = ocr;

         ^

In file included from C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:43:0:

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:485:18: error: 'TIMSK2' was not declared in this scope

         bitWrite(TIMSK2, OCIE2A, 1);

                  ^

C:\Users\JHE_B\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.1.5\cores\tiny/Arduino.h:87:30: note: in definition of macro 'bitSet'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                              ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:485:9: note: in expansion of macro 'bitWrite'

         bitWrite(TIMSK2, OCIE2A, 1);

         ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:485:26: error: 'OCIE2A' was not declared in this scope

         bitWrite(TIMSK2, OCIE2A, 1);

                          ^

C:\Users\JHE_B\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.1.5\cores\tiny/Arduino.h:87:49: note: in definition of macro 'bitSet'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                                 ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:485:9: note: in expansion of macro 'bitWrite'

         bitWrite(TIMSK2, OCIE2A, 1);

         ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::stop()':

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:521:7: error: 'TIMSK1' was not declared in this scope

       TIMSK1 &= ~(1 << OCIE1A);

       ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:524:7: error: 'TIMSK2' was not declared in this scope

       TIMSK2 &= ~(1 << OCIE2A);

       ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:524:24: error: 'OCIE2A' was not declared in this scope

       TIMSK2 &= ~(1 << OCIE2A);

                        ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'bool Tone::isPlaying()':

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:552:22: error: 'TIMSK0' was not declared in this scope

       returnvalue = (TIMSK0 & (1 << OCIE0A));

                      ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:557:22: error: 'TIMSK1' was not declared in this scope

       returnvalue = (TIMSK1 & (1 << OCIE1A));

                      ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:560:22: error: 'TIMSK2' was not declared in this scope

       returnvalue = (TIMSK2 & (1 << OCIE2A));

                      ^

C:\Users\JHE_B\Documents\Arduino\libraries\Tone\Tone.cpp:560:37: error: 'OCIE2A' was not declared in this scope

       returnvalue = (TIMSK2 & (1 << OCIE2A));

                                     ^

Using library Tone at version 1.0.0 in folder: C:\Users\JHE_B\Documents\Arduino\libraries\Tone 
exit status 1
Error compiling for board ATtiny25/45/85.

The ATTIny core I’m using is the DrAzzy core which I read should support the Tone library, but clearly something has gone wrong.

Any help would be greatly appreciated. Thanks!

I was in a very similar position a while back, it got real frustrating real fast for something so simple to get so complicated.

Check out my previous thread on this issue.

TL;DR: after each implementation of tone(), add a 1 mS delay to reset timer bit. Or alternatively, you can use the TimerFreeTone library.

Amazing thank you! I found that thread before but I must say the tl;dr definitely made it more understandable. I found that the serial outputs from the tone() RTTTL example could be written in to the TimeFreeTone example to produce the same sound. It's a bi more long winded but it gets it on to an ATTiny so that's all I care about for now. Thanks!