tone(), noTone()

Post your cool example code here.
enif
Posts: 32
Joined: Wed Jul 29, 2015 4:49 pm
Location: Switzerland
Contact:

Re: tone(), noTone()

Post by enif » Sun Jul 17, 2016 3:00 pm

@ekawahyu: No, it's still just that "code snipplet" you see in my message above. I use it in some of my programs and have not run into any problems - so far...

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: tone(), noTone()

Post by ahull » Sat Nov 19, 2016 10:39 pm

I added a couple of working examples - see this thread -> http://www.stm32duino.com/viewtopic.php ... 202#p20202

@Roger, not sure how easy it would be to add tone() noTone() to the arduino core based on enif's code, but I think it would be a useful addition.
- Andy Hull -

User avatar
RogerClark
Posts: 6896
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: tone(), noTone()

Post by RogerClark » Sat Nov 19, 2016 11:26 pm

Thanks andy

I agree that tone() and notone() should be added.

I took a quick look at that implementation and I think it seemed OK.

And as its a new file its not going to break anything as long as it compiles, so I may as well add it ;-)

User avatar
RogerClark
Posts: 6896
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: tone(), noTone()

Post by RogerClark » Sun Nov 20, 2016 7:25 am

ekawahyu wrote:@enif: What is the status of this work? Is it available somewhere on github and stable?
I've added enif's code to the libmaple core


@enif... Thanks

Nutsy
Posts: 240
Joined: Sun Jul 24, 2016 4:26 pm

Re: tone(), noTone()

Post by Nutsy » Wed Dec 07, 2016 12:13 am

hias, So ive been playing with Tone a little, i have a piezo on my project now. And i wanted a nice little beep sound for startup and menu button presses... But! I cant get any decent sounds from my piezo using tone. I did a little code to scale through the notes defined, and while there is a slight harmonic tone going up the scale its mostly distorted loud beeps.

ill try and record something to show at some point.

Im powering the piezo at 12v and triggered from the maple mini via a standard 2n4001 transistor.

Going by the specs 12V should be fine. I think it said 3-20v or something like that.

At this stage i guess im not really asking for help. More just saying my experience so far. But if you have any ideas on how to improve it let me know.

User avatar
RogerClark
Posts: 6896
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: tone(), noTone()

Post by RogerClark » Wed Dec 07, 2016 12:23 am

I'm not sure you are ever going to get a nice sound from a piezo. I know some of them are harmonically tuned to work best at one specific frequency (or harmonics of that frequency), so they sometimes have 2 peaks in their audio spectrum.

If you are driving via a transistor you may want to look at an alternative device which is more like a normal speaker. There are some small beepers which are not piezo which you could use, (but they often take a lot of current - e.g. 50 to 100mA and need a driver transistor)

Even then, if you feed with a square wave, you are going to get a specific type of sound, but you could try adding an RC network between the STM32 and the transistor to form a low pass filter e.g. set to 10kHz or perhaps 5kHz, as that would give things a more pleasing sound.

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: tone(), noTone()

Post by ahull » Wed Dec 07, 2016 11:03 am

If you only want a specific frequency of "beep", you could convert the square wave to a sine wave with passives.

http://www.learningaboutelectronics.com ... ircuit.php

You may also find that PWM of the tone gives better results, (attenuation control to remove might lessen the worst of the distortion) but that would involve more work on the tone() functions, or writing your own.

You could of course just use a 12V beeper designed to produce a single tone. Let us know how you get on.
- Andy Hull -

Nutsy
Posts: 240
Joined: Sun Jul 24, 2016 4:26 pm

Re: tone(), noTone()

Post by Nutsy » Wed Dec 07, 2016 12:51 pm

Thanks for the advice guys, just to throw a spanner into the works *cries* Ive reread the listing. Since I ordered the buzzers the listings been updated 3-5v... So the voltage was listed wrong before. And im supplying 12v to a 5v buzzer. no wonder it sounds distorted.

Oh well I can live with this for now. Something to change on the final design.

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: tone(), noTone()

Post by ahull » Wed Dec 07, 2016 3:06 pm

Nutsy wrote:Thanks for the advice guys, just to throw a spanner into the works *cries* Ive reread the listing. Since I ordered the buzzers the listings been updated 3-5v... So the voltage was listed wrong before. And im supplying 12v to a 5v buzzer. no wonder it sounds distorted.

Oh well I can live with this for now. Something to change on the final design.
What, no magic smoke? Must be a pretty robust buzzer. :lol:
- Andy Hull -

Nutsy
Posts: 240
Joined: Sun Jul 24, 2016 4:26 pm

Re: tone(), noTone()

Post by Nutsy » Wed Dec 07, 2016 4:02 pm

i guess piezos are pretty robust... I mean hit one they can generate a thousand volts... So i guess it wont smoke it... but just distorts :p

I dont think theres any active circuitry in the thing. Just wired into a peizo... i might be able to hack the piezo and wire it to the 5v rail... rather than the 12v

Post Reply