buzzer player

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

buzzer player

Postby sdalu » Fri Aug 05, 2016 9:50 pm

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

acr
Posts: 14
Joined: Tue Nov 18, 2014 3:52 am

Re: buzzer player

Postby acr » Tue Aug 09, 2016 6:33 am

volume is missing in BuzzerConfig

acr
Posts: 14
Joined: Tue Nov 18, 2014 3:52 am

Re: buzzer player

Postby acr » Tue Aug 09, 2016 6:42 am

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

sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

Re: buzzer player

Postby sdalu » Tue Aug 09, 2016 10:04 pm

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

rmozel
Posts: 2
Joined: Fri Feb 17, 2017 11:43 am
Has thanked: 1 time

Re: buzzer player

Postby rmozel » Fri Feb 17, 2017 11:52 am

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

sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

Re: buzzer player

Postby sdalu » Tue Feb 28, 2017 10:55 am

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);
}


User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: buzzer player

Postby tfAteba » Tue Feb 28, 2017 11:30 pm

Hi all,

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

Theo.

rmozel
Posts: 2
Joined: Fri Feb 17, 2017 11:43 am
Has thanked: 1 time

Re: buzzer player

Postby rmozel » Mon Mar 06, 2017 7:06 am

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


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 5 guests