This requires to look at the data sheet for the processor and investigate any hardware timers in it. By changing the value of N you can change the frequency and make it work like a tone function. The way to do it in software would be to have an interrupt being triggered at a fast rate say in the region of 40KHz and use the ISR to count and toggle a pin every N interrupts. Then you can work out the current it will draw at the highest frequency you want to use. The important parameter is the capacitance of the buzzer. Without knowing the details of the exact buzzer you use it is hard to tell if you need a transistor to drive it or if you can just connect it to a pin. Hence my assumption you were a beginner, sorry. Now you don’t “find” a schematic if you know anything about hardware. I have found schematics on how to drive one of these It appears I have to live with the simple tones I'm generating now, unless I want to add an audio shield. I see the pins labelled for PWM on the Arduino UNO. const int buzzer = 13 // Buzzer pinĭigitalWrite(LED_BUILTIN, LOW) // turn the LED on (HIGH is the voltage level)ĭigitalWrite(LED_BUILTIN, HIGH) // turn the LED on (HIGH is the voltage level)Īnd looking at the pin-out diagram of the ESP-32, I don't see any pins for PWM. This was my goal for now, though I'll want to do better later. PWM would be better, but I've at least got a tone out of it. If there is a finer resolution timer then I could generate more frequencies. This relies on the granularity of the delay() function, which is 1 ms. Using just the delay() function I have got my ESP-32 to emit tones using the piezo buzzer. I have been searching for this information myself, but I haven't yet found the type of documentation that I need to generate tones on the ESP-32. I may have to ask some further questions, but maybe not. If it is possible to do this with the ESP-32, via PWM (pulse width modulation) or otherwise, I will just need to be pointed to the proper documentation and I can probably do it. The questions I ask are to find out the proper way to do things, and to not damage the hardware that I do have. I know software, but I have only dabbled in hardware. I have programmed from assembly language to 4-GL. I am a professional programmer who has been programming for a few decades. Let me give you some more information about myself. I am speaking (writing) in good faith, and assume that you are doing so as well. There is so much of communication that occurs non-verbally when people talk in person, so that is why I stated this. There is no way to know a person's level of knowledge on these forums, so I don't have any problem with you stating this with what you currently know about me. Without looking in detail at the processor you have, I am not even sure if this is possible. You add extra code to the tone library, a task I think that is beyond you with your current state of knowlage.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |