-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using the duration parameter of tone, the sound will be distorted #193
Comments
@qwqoffice |
I am using Arduino UNO R3 board, with ATMEGA328P-PU, and a passive buzzer for tone.
It sounds like there's some noise. 98ca6a1932454e17755544c6f173e427.mp4And then, I deleted the initialization code for pulsesensor, and add tone code in
dcaafb5541257af0c34d95a3271cf2e2.mp4I noticed a note in the
Is it related to this? I want the sound to play for a longer time and sound like a monitor in a hospital, just like the second video |
@qwqoffice Please try following the example that we have and see if that still gives you the noisy beep? Second, it is clear that you are using a 'knock-off' PulseSensor. Our PulseSensor comes with a 24" cable with Red, Black, Purple wire colors. Also, our PulseSensor kit comes with a clear vinyl sticker to place on the front face to keep skin oils and sweat from interfering with the electronics. |
@biomurph WeChat_20240416034445.mp4As you said, my sensor is indeed a a 'knock-off' PulseSensor, but when I completely disconnected the sensor, the problem still exists, proving that the problem is not related to whether a original makers of PulseSensor is used or not. My following code calls a 10 second
And It does not require the connection of sensor, the noise still exists: 902e186773c1bc8588ff866cb159fd49.mp4
My English is weak and I don't understand the meaning. Does it mean that code support also requires the use of original makers of PulseSensor? I also tried other frequencies for the tone, such as 2000, 3000, 4000. There is a significant difference in sound when calling and not calling the sensor initialization code. using timer code:
254e2c5efca2c65cc29e910ed4b0691b.mp4not using timer, loop instead:
db38874119c8344186b2fc3129d6ec58.mp4 |
@biomurph 6e46db7ac32500ad6e180811a160fccf.mp4while the normal sound waveform frequency remains stable. 66189dca694acd14e157ab28ead6e28f.mp4 |
@qwqoffice The tone() command in Arduino makes extensive use of hardware timer interrupts in order to generate the tone, as well as turning off the tone when the duration parameter us used. Producing the tone uses one timer, and setting the duration uses another. PulseSensor Playground library also uses interrupts to time the accurate sampling of the PulseSensor. The duration parameter timer use crashes with the PulseSensor timer use, so that is why there is distortion in the audible tone. The easiest way to get around this issue is to turn on the tone when a heartbeat happens, and then turn off the tone some time later. In our example, we are using the sawStartOfBeat function to turn on the tone and the isInsideBeat function to turn off the tone. The isInsideBeat function will return true as long as the pulse signal wave is above the THRESHOLD value. As you have noticed, the length of the tone is limited. Another way to set the time length of the tone without using the duration parameter would be to use a software timer. Here is an example of a software timer that you can use in your code. Above the setup() declare some global variables:
In the loop:
Please let us know if this software timer works to solve the problem? |
@biomurph WeChat_20240416034445.mp4 |
@qwqoffice Please provide a link to the components you are using? |
@biomurph |
@qwqoffice I have setup an Arduino UNO in my lab, with a speaker just like the tutrorial found here I can confirm that the beep sound does have a small amount of noise in it. I have not found the source of the noise, but I am going to do more tests to see where the bug is coming from. |
@biomurph |
This fixes the noisy tone issue #193 Tone interrupt collides with our interrupt, noisy tone is the result, and likely bad BPM values. In order to fix this problem and use tone() the Arduino core needs to be updated so that the tone library operates 'hands free' like the PWM library. Or, the PWM library needs to be updated to accept a frequency parameter to ensure a clean(er) note. There are some architectures upon which the Tone library might work: nRF52? ESP32?
@qwqoffice In order to fix this problem and use tone() the Arduino core needs to be updated so that the tone library operates 'hands free' like the PWM library. Or, the PWM library needs to be updated to accept a frequency parameter to ensure a clean(er) note. There are some architectures upon which the Tone library might work: nRF52? ESP32? Please try the new example, and let us know if it works for you? |
I added the duration parameter to the tone function:
tone(Buzzer, 932, 150);
The sound sounds a bit strange.
But when I don't use
pulseSensor.begin()
, the sound is normalWhat is the problem?
The text was updated successfully, but these errors were encountered: