Go Down

Topic: TimerFreeTone Library v1.5: Play tones without timers and therefore no conflicts (Read 19834 times) previous topic - next topic

teckel

Hi, I stumbled upon your tone libraries and they are great, but both I tested after playing a melody left humming sound in a speaker.
With toneAC I solved it, with one noToneAC() afterwards, but this one I like better because it uses no timers - a part of bigger project, I need my timers... :o)
So, this library has no command to turn sound off (right?), and I tried writing low digitally, (you can see it), it didn't help, so, what happens is:
after playing a tune speaker buzzes quite low in frequency, and for some 10 seconds, then it goes silent for my delay of 2 seconds, starting all over.
Any idea why this buzzing and why so long?
It will only hold the note for the duration specified.  There's no reason to do anything to end the note as it always ends the note when complete.  What hardware are you running on?

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

carlsopa

I came across your library while looking for a way to both play a buzzer and flash a neopixel.  Your library is well done.  What I would like to do is be able to take your library, but play my own song.  For example my project I want to play Happy Birthday.  I was attempting to use the following code:
https://create.arduino.cc/projecthub/trduunze/piezo-happy-birthday-7ea362

They are of course going about it in a complete different way then you.  But I was thinking that taking their melody notes, and putting them in to replace your melody notes, would work.  However, that gave me a song that was not Happy Birthday.

Would I be right in thinking that it comes down to you dividing the notes by 1,000,000 and then a volume?  This is what I see in your .h file. 

Any suggestions, or help would be greatly appreciated.

Paul

teckel

I came across your library while looking for a way to both play a buzzer and flash a neopixel.  Your library is well done.  What I would like to do is be able to take your library, but play my own song.  For example my project I want to play Happy Birthday.  I was attempting to use the following code:
https://create.arduino.cc/projecthub/trduunze/piezo-happy-birthday-7ea362

They are of course going about it in a complete different way then you.  But I was thinking that taking their melody notes, and putting them in to replace your melody notes, would work.  However, that gave me a song that was not Happy Birthday.

Would I be right in thinking that it comes down to you dividing the notes by 1,000,000 and then a volume?  This is what I see in your .h file. 

Any suggestions, or help would be greatly appreciated.

Paul
The example script shows how you would play a melody:

https://bitbucket.org/teckel12/arduino-timer-free-tone/wiki/Home#!example

The molody[] array is the frequency in Hz of the note, the duration[] array is the time in ms to play the note.  A frequency of 0 would be a pause.  There's no dividing of 1,000,000 and no volume at all.  Nothing to change in the .h file whatsoever.  Just take the example script and change the arrays.  You'll need some knowledge of music and note frequency, but it's not rocket science.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

carlsopa

Thanks for the quick response Tim! 

I made a simple mistake, by putting the wrong tone frequencies in.  After I found a reference to the frequencies, I was able to correct it, and works like I wanted.

Paul

jirm

Good day.

I`m a happy user that your nice TimerFreeTone libray for years with several esp8266 projects, but now I need to update ESP core to lastest 2.4.2 release and your library seems have issues to compile propperly.
When I try to compile arduino IDE raise several errors about it:

C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp: In function 'void TimerFreeTone(uint8_t, long unsigned int, unsigned int, uint8_t)':

C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:18:56: error: no matching function for call to 'min(uint8_t&, int)'

  uint32_t duty = frequency / _tft_volume[min(volume, 10) - 1]; // Calculate the duty cycle (volume).

                                                        ^

C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:18:56: note: candidates are:

In file included from c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\algorithm:62:0,

                 from C:\Users\IEUser\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/Arduino.h:255,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.h:59,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:8:

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4226:5: note: template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)

     min(initializer_list<_Tp> __l, _Compare __comp)

     ^

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4226:5: note:   template argument deduction/substitution failed:

C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:18:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned char'

  uint32_t duty = frequency / _tft_volume[min(volume, 10) - 1]; // Calculate the duty cycle (volume).

                                                        ^

In file included from c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\algorithm:62:0,

                 from C:\Users\IEUser\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/Arduino.h:255,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.h:59,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:8:

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4221:5: note: template<class _Tp> _Tp std::min(std::initializer_list<_Tp>)

     min(initializer_list<_Tp> __l)

     ^

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4221:5: note:   template argument deduction/substitution failed:

C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:18:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned char'

  uint32_t duty = frequency / _tft_volume[min(volume, 10) - 1]; // Calculate the duty cycle (volume).

                                                        ^

In file included from c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\algorithm:61:0,

                 from C:\Users\IEUser\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/Arduino.h:255,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.h:59,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:8:

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:239:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)

     min(const _Tp& __a, const _Tp& __b, _Compare __comp)

     ^

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:239:5: note:   template argument deduction/substitution failed:

C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:18:56: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned char' and 'int')

  uint32_t duty = frequency / _tft_volume[min(volume, 10) - 1]; // Calculate the duty cycle (volume).

                                                        ^

In file included from c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\algorithm:61:0,

                 from C:\Users\IEUser\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/Arduino.h:255,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.h:59,

                 from C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:8:

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:193:5: note: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)

     min(const _Tp& __a, const _Tp& __b)

     ^

c:\users\ieuser\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:193:5: note:   template argument deduction/substitution failed:

C:\Users\IEUser\Documents\Arduino\libraries\TimerFreeTone\TimerFreeTone.cpp:18:56: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned char' and 'int')

  uint32_t duty = frequency / _tft_volume[min(volume, 10) - 1]; // Calculate the duty cycle (volume).

                                                        ^

I dont know if you have any way to solve it, because I like so much your library and always had worked like a charm.

Thank you

teckel

Good day.

I`m a happy user that your nice TimerFreeTone libray for years with several esp8266 projects, but now I need to update ESP core to lastest 2.4.2 release and your library seems have issues to compile propperly.
When I try to compile arduino IDE raise several errors about it:
Sounds like you don't have something setup correctly with the 2.4.2 release as TimerFreeTone isn't doing anything complicated that would fail almost totally like that.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

jirm

Tim, so many thanks for your quick reply.

OK, but all my others sketches (some of them with tons of other libraries) are compiled without issues, but maybe you are right and I now I have some trouble on my arduino IDE setup, this in that moment is a upgrade from other esp old core setups.

I give again a try with some clean arduino IDE and esp core install, and I report what I have, because I want maintain use your nice TimerFreeTone library.

Best regards

Jose.
 

polymorph

Always start with the first error. All the other errors may flow from that first error.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Nuno_Lima

hi..
im new at this, so sorry if im doing a lot of stupid questions..
im doing a project where i use 2 shift registers to control 14 LEDs and i also want to play a song using a buzzer but when i try to do that at the same time, it just plays the song and only then the LEDs work. I tried to use your library because i thought it could be because of timers but it doesnt work anyway.. what can i do ?   

Grumpy_Mike

Quote
what can i do ?   
Start a new thread and post your code in it.

It sounds like you have not written your software correctly. Nothing to do with the Tone library.

Go Up