Page 1 of 1

buzzer player

Posted: Fri Aug 05, 2016 9:50 pm
by sdalu
I've written a small code to allow basic control of a buzzer and to play "melody" (using a compact format)

I'm putting the link here, if it can be useful to someone else.

https://github.com/sdalu/kakapo

Re: buzzer player

Posted: Tue Aug 09, 2016 6:33 am
by acr
volume is missing in BuzzerConfig

Re: buzzer player

Posted: Tue Aug 09, 2016 6:42 am
by acr
i get from ruby

kakapo.rb:184: syntax error, unexpected '.'
... return if delta_error&.< edlt # Ensure ac...
... ^
kakapo.rb:185: syntax error, unexpected '.'
return if pct_error&.< epct # Ensure ...
^
kakapo.rb:184: syntax error, unexpected '.'
... return if delta_error&.< edlt # Ensure ac...
... ^
kakapo.rb:185: syntax error, unexpected '.'
return if pct_error&.< epct # Ensure ...
^
kakapo.rb:184: syntax error, unexpected '.'
... return if delta_error&.< edlt # Ensure ac...
... ^
kakapo.rb:185: syntax error, unexpected '.'
return if pct_error&.< epct # Ensure ...
^
kakapo.rb:184: syntax error, unexpected '.'
... return if delta_error&.< edlt # Ensure ac...
... ^
kakapo.rb:185: syntax error, unexpected '.'
return if pct_error&.< epct # Ensure ...
^

i really hate ruby

Re: buzzer player

Posted: Tue Aug 09, 2016 10:04 pm
by sdalu
Hi.

You need to use ruby 2.3, due to the &. syntax and some of the Enumerable methods

Volume is currently not handled by the driver as it is not possible to control it by using only the pwm driver.
It would requires additional circuitry to control it using the voltage. If you can provide me with the schematic, I could add the code.
If I'm wrong let me now, as electronic is not my strength.

Sincerly

Re: buzzer player

Posted: Fri Feb 17, 2017 11:52 am
by rmozel
Dear sdalu,

I have some difficulties to make your kakapo library to work with my STM32F401 Nucleo based board. It successfully executes buzzer_init() but gets stuck at buzzer_melody, _ring, or _beep. If you kindly provide your main.c together with appropriate configuration files, e.g., halconf, mcuconf, and board.h), I will be appreciated.

Regards,
Renan

Re: buzzer player

Posted: Tue Feb 28, 2017 10:55 am
by sdalu
Hi,

That's what I'm using
(sorry for the delay, these times, I'm not actively reading the forum)

I'm using standard halconf/mcuconf for the STM32F042K6 with PWM enabled

Code: Select all

// PWM
static const PWMConfig pwm_cfg = {
    .frequency = 1000000,             /* 1MHz PWM clock frequency.   */
    .period    = 250,                 /* Initial PWM period 250µs.   */
    .channels  =  {
   { .mode = PWM_OUTPUT_ACTIVE_HIGH },
    }
};


// Buzzer
static const BuzzerConfig buzzer_cfg = {
    .pwm     = &PWMD1,
    .channel = 0,
};

char melody_zelda[] = {
    0xfa, 0xfa, 0xfd, 0x8d, 0x51, 0x02, 0x4a, 0x04,
    0x4d, 0x02, 0x51, 0x02, 0x4a, 0x04, 0x4d, 0x02,
    0x51, 0x01, 0x54, 0x01, 0x53, 0x02, 0x4f, 0x02,
    0x4d, 0x01, 0x4f, 0x01, 0x51, 0x02, 0x4a, 0x02,
    0x48, 0x01, 0x4c, 0x01, 0x4a, 0x83, 0x00, 0xff };

struct buzzer  BZZR1;

main() {
    palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(2));
    pwmStart(&PWMD1, &pwm_cfg);
    pwmDisableChannel(&PWMD1, 0);

    buzzer_init (&BZZR1, &buzzer_cfg);
    buzzer_melody(&BZZR1, melody_zelda);
}


Re: buzzer player

Posted: Tue Feb 28, 2017 11:30 pm
by tfAteba
Hi all,

It seems realy cool, I want to test this one day when I will have a buzzer.

Re: buzzer player

Posted: Mon Mar 06, 2017 7:06 am
by rmozel
Hi,

With the help of the given configuration file, I managed to get it work. The problem was with my PWM configuration structure, but now it chirps perfectly :)

Thanks a lot.

Renan