Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Betaflight CLI " set beeper_frequency" ?
#1
I have old ears and a hearing problem mostly due to tinnitus ( ringing in my ears ) and the ringing is just about the same frequency as most electronic beepers and buzzers. I don't care how loud they are , I can't hear them unless the are close to and pointing at my ears.

I have tried setting my beeper frequency with the above CLI command but it will not save. I googled around and found a few forum posts about it, none were very helpful and I'm not really sure how it all works but I did read something about if the hardware ( available timer) is not available it won't save and therefore won't work. I also read about active and passive beepers and tested mine on an Arduino with the Tone() sketch and my beepers will produce different tones via pwm input.

So I guess the question is can I do some resource remapping and get pwm output for the beeper ?

On my Mobula I checked resources and have  Motors 1-5  , will motor 5 work for what I want ?

This is from the Mobula

# resource
resource BEEPER 1 C15
resource MOTOR 1 B08
resource MOTOR 2 B09
resource MOTOR 3 A03
resource MOTOR 4 A02
resource MOTOR 5 B06
resource LED_STRIP 1 B04
resource SERIAL_TX 3 B10
resource SERIAL_RX 3 B11
resource LED 1 B03
resource RX_BIND_PLUG 1 A09
resource SPI_SCK 1 A05
resource SPI_SCK 2 B13
resource SPI_MISO 1 A06
resource SPI_MISO 2 B14
resource SPI_MOSI 1 A07
resource SPI_MOSI 2 B15
resource ADC_BATT 1 A00
resource ADC_CURR 1 A01
resource OSD_CS 1 B01
resource SPI_PREINIT_IPU 1 A04
resource SPI_PREINIT_IPU 2 B12
resource SPI_PREINIT_IPU 3 B01
resource RX_SPI_CS 1 B12
resource GYRO_EXTI 1 C13
resource GYRO_CS 1 A04


Thanks

Scott
Reply
Login to remove this ad | Register Here
#2
Here are the links I found, but don't really understand  Sad

https://github.com/betaflight/betaflight/pull/2757  

https://github.com/betaflight/betaflight/issues/5754

Do any of you guys think this is doable ?

Scott
Reply
#3
OK, to get to the bottom of this I had a look through the Betaflight source code and the ability to control beeper frequency does indeed require a resource that has an available timer assigned to it, as you made mention of in your first post. The below analysis that I've done explains exactly why that is.

Below is the pinout of the STM32F303C microcontroller used on the Crazybee F3.

[Image: Vu1nXUx.jpg]

In the Betaflight target file for the Crazybee F3, the beeper is assigned to pin PC15 of the STM32F3 by the following code (source HERE). This is pin #4 on the pinout image above. 

Code:
#define BEEPER_PIN              PC15

The following code (source HERE) is used to assign available timers on the Crazybee F3. As you can see, timers are only assigned to motor pins PB8, PB9, PA2, PA3 & PA4, and LED Strip pin PB4. No timers are assigned to beeper pin PC15.

Code:
const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {
   // TIM8_UP, DMA2_CH1
   DEF_TIM(TIM8, CH2, PB8, TIM_USE_MOTOR, 0),
   DEF_TIM(TIM8, CH3, PB9, TIM_USE_MOTOR, 0),
   // TIM2_UP, DMA1_CH2
   DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 0),
   DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 0),
   DEF_TIM(TIM4, CH1, PB6, TIM_USE_MOTOR, 0), //PB6 for servo
   DEF_TIM(TIM3, CH1, PB4, TIM_USE_LED,   0), //LED_STRIP
};

The value of "beeper_frequency" set within the CLI determines if a digital signal or a PWM signal is used for the beeper when it is activated, as shown by the code below (source HERE). A value of zero means that a digital signal is used for the beeper (via use of the "IOWrite" function), and a value other than zero means that a PWM signal is used for the beeper (via the "pwmWriteBeeper" function).

Code:
void systemBeep(bool onoff)
{
#ifdef USE_BEEPER
    if (beeperFrequency == 0) {
        IOWrite(beeperIO, beeperInverted ? onoff : !onoff);
    } else {
        pwmWriteBeeper(onoff);
    }
#else
    UNUSED(onoff);
#endif
}

However, you cannot set "beeper_frequency" to a value other than zero if there is no timer associated with the beeper pin (PC15 in the case of the Crazybee F3). If you do, then it will just get reset back to zero as you've discovered. The following code (source HERE) checks if "beeper_frequency" is a non-zero value and if a timer has been associated with the beeper pin. If it hasn't (as in the case of the Crazybee F3) then it will automatically reset the "beeper_frequency" to zero.

As we know from the code above, when the value of "beeper_frequency" is zero, it prevents the use of PWM (due to no available timer on that pin) and forces the beeper pin to use a digital signal. This is why you can't use a PWM frequency output on the beeper pin of the Crazybee F3.

Code:
if (beeperDevConfig()->frequency && !timerGetByTag(beeperDevConfig()->ioTag)) {
   beeperDevConfigMutable()->frequency = 0;
}

As motor 5 pin (PB6) has a timer associated with it as can be seen from the timer association code above, you can try remapping that for the beeper as you suggested using the commands below in the CLI, however be aware that not all resources can be remapped to other pins so trying to do that might fail. The only way to find out is to try. Make sure you take a complete backup of your settings first in the CLI using the "diff all" command so that if something gets screwed up you can revert back to your original config.

Code:
resource beeper 1 none
resource motor 5 none
resource beeper 1 B06
save

Another option you have is to try remapping the LED Strip pin for the beeper instead because that also has a timer associated with it using the CLI commands below.

Code:
resource beeper 1 none
resource led_strip 1 none
resource beeper 1 B04
save

Failing that, then the last resort would be to compile custom firmware using the following code which replaces the assignment of a timer to the motor 5 pin with a timer assignment to the beeper pin instead.

Code:
const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {
   // TIM8_UP, DMA2_CH1
   DEF_TIM(TIM8, CH2, PB8, TIM_USE_MOTOR, 0),
   DEF_TIM(TIM8, CH3, PB9, TIM_USE_MOTOR, 0),
   // TIM2_UP, DMA1_CH2
   DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 0),
   DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 0),
   DEF_TIM(TIM4, CH1, PC15, TIM_USE_BEEPER, 0), // BEEPER PWM
   DEF_TIM(TIM3, CH1, PB4, TIM_USE_LED,   0), //LED_STRIP
};

Hopefully I haven't bamboozled you too much with all of the above Confused Big Grin
[-] The following 2 users Like SnowLeopardFPV's post:
  • izzy26, Scott_M
Reply
#4
Wow Snow !  That is really above and beyond ! You are a gentleman and a scholar. ( can't find a "hats off " emoji )

My code skills are kind of weak , but when someone explains the code as you have it all makes sense and is readable.

Plugging in the mobula now, I will report back shortly.....


Scott
Reply
#5
Motor 5 remap worked



[Image: Hn8dsYol.jpg]



set frequency   saved




[Image: 0P5IJIbl.jpg]



Beeper does not work  Sad

I did not test this one and I am not sure if it is active or passive. I am going to test it now.

I'll be back

Scott
Reply
#6
Let me see if I can explain this. I hope my information is correct.

Active beeper only requires a voltage to active the beeper. All the circuitry is built in into the beeper. Including the oscillating signal. An active beeper only generates a set tone. Changing beeper_frequency value will not make beeper change tone. In fact, changing it to anything other than 0 for an active beeper likely will not generate any sound. Most FC is designed for active beeper, that is why the default frequency is 0. When beeper_frequency = 0, it tells the FC you are using an active beeper.

To use beeper_frequency, you will need to set up a passive beeper. A simple setup will require one resistor and one transistor. The other requirements is a timer is assigned to the beeper in the target firmware. If you know how to modify the target code and have an available timer, you can make a custom compile the firmware. Most of the time, either the beeper timer is shared with some other things. So when you start changing the beeper_frequency, you can screw up whatever the other thing that shares the timer. Or does not have a timer. That is why, in the second link, the developer purpose that when a timer is not detected, it defaults back to 0. So it is hard to know which FC can do passive beeper. You can make the effort to remap buzzer resource to a free pin that has it owe timer.

Some FC like the CL Racing F4 version 1 has a built-in beeper. In that situation, the changing the frequency will change the tone. But unfortunately, the timer is tied down to the ESC and cannot be changed.

Edit:
I took to long to write this post and just realized that Snow beat me to it and did a more thorough job. Haha.
Reply
#7
The beeper works with a PWM signal from the Arduino.

I set the frequency back to "0" and it does not work that way either  Sad

Double checked in the modes tab that I was flipping the right switch , I was.

Hmmmm

Scott
Reply
#8
Scott  you need a passive beeper. See photo below. D4 is where you would connect to the motor 5 pad. That is generating the signal you need to make a sound.


[Image: XQ66xkbl.png]
[-] The following 1 user Likes voodoo614's post:
  • Scott_M
Reply
#9
Hi voodoo

I'm not really sure what you are saying. I was running a Tone() sketch on the Arduino just to see if the beeper would respond to a PWM signal, and it does. I am not sure if that means it is passive. It was not very loud. I was just connected to D8 and gnd. no resistor or transistor. But it did change pitch with different values in the sketch.

Or were you saying that I should be hooking up the buzzer to motor 5 pads on the FC ?

Scott
Reply
#10
(02-Feb-2019, 11:27 PM)Scott_M Wrote: Hi voodoo

I'm not really sure what you are saying. I was running a Tone() sketch on the Arduino just to see if the beeper would respond to a PWM signal, and it does. I am not sure if that means it is passive. It was not very loud. I was just connected to D8 and gnd. no resistor or transistor. But it did change pitch with different values in the sketch.

Or were you saying that I should be hooking up the buzzer to motor 5 pads on the FC ?

Scott

Nevermind about motor 5 pad. I didn't read Snow remap very carefully.

One way to test whether you have an active beeper or passive. Just hook a 5v source to the beeper. If it makes a loud sound, then it is active. If it makes little or no sound, then it is passive.
[-] The following 1 user Likes voodoo614's post:
  • Scott_M
Reply
#11
(02-Feb-2019, 11:27 PM)Scott_M Wrote: Or were you saying that I should be hooking up the buzzer to motor 5 pads on the FC ?

Yes, you need to hook the buzzer up to the motor 5 pad instead of the buzzer pad because that is the pad that you've now remapped the beeper resource to. The beeper resource is now mapped to pin PB06 on the STM32F303C microcontroller which goes to the motor 5 pad on the circuit board.
[-] The following 1 user Likes SnowLeopardFPV's post:
  • Scott_M
Reply
#12
I was under the impression that you have to remap the buzz- to a pin that have a timer and not how Snow suggested. For example you want to remap buzz- to motor 5 pad and not motor 5 to buzz-.

Edit:
So I think moving buzz- to led_strip will work. But you solder to led_strip and not buzz-. I think.
[-] The following 1 user Likes voodoo614's post:
  • Scott_M
Reply
#13
Ok that explains it, I did not move the beeper.
I hooked it to 5 volts and it is loud ( if I put my ear by it )

None of the pads are labeled, I will have to do some research on this board and find out if there are pads for motor 5
If not , hopefully there will be for the LED strip and I can remap those.

Thanks a bunch guys !!

Scott
Reply
#14
(02-Feb-2019, 11:42 PM)voodoo614 Wrote: I was under the impression that you have to remap the buzz- to a pin that have a timer and not how Snow suggested. For example you want to remap buzz- to motor 5 pad and not motor 5 to buzz-.

Yes, Scott has remapped the buzzer resource from pin C15 to pin B04 on the microcontroller. Pin B04 used to be for motor 5 but is now for the buzzer instead (due to the remapped resource). Pin B04 goes to the pad for motor 5 so he now needs to connect the buzzer to the motor 5 pad. The buzz- pad is still connected to pin C15 on the microcontroller but that pin now has no resource mapped to it so is effectively defunct.

Pin B04 has a timer assigned to it whereas Pin C15 didn't. This has proven to be true by the fact that Scott has now been able to set beeper_frequency to something other than 0. You can only do this if the pin that the beeper resource is assigned to has a timer associated with it, which it now does. So in theory, a passive buzzer should work in PWM mode when connected to the motor 5 pad.
Reply
#15
So I was correct. Solder to PWM 5,which is on the backside next to the led_strip.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Bringing an old betaflight target into 4.4.0 husafreak 10 1,928 22-Nov-2023, 02:45 PM
Last Post: Pathfinder075
  What happens when I load a Betaflight Preset Tune in my FC? husafreak 6 759 07-Nov-2023, 02:56 AM
Last Post: husafreak
  No betaflight connection with just USB aerokam 5 556 20-Oct-2023, 05:44 PM
Last Post: SnowLeopardFPV
  Help Facing problem installing betaflight firmware from ardupilot Prashant9316 5 589 09-Oct-2023, 08:33 AM
Last Post: voodoo614
  Help Betaflight telemetry output smartport paulno 24 1,526 05-Oct-2023, 06:23 PM
Last Post: SnowLeopardFPV


Login to remove this ad | Register Here