How to Generate a Beep?

  • @bricoms Thank you for the reply. I tried that example, but it did not work for me. I am using an M5 Stack core2 and that seems to be a library for just the Stack.

  • @jesse-schein haha wow, there's certainly a lot there. Thanks for this info. I just need to generate a simple beep once every few seconds, but it seems like I can only generate sound from from a wav or other file type? I was hoping there would be a tone() function, but I guess i'll just have to go through a few extra steps to get what I need.
    Edit: I just tried uploading some of these examples and they would not generate sound. I'll have to take a closer look at what's going on

  • @akaf24 You can try look at this:
    It use the same chip as Core2 and play beeps ;-) so you migth be able to just change the i2S pins and the you go ;-)

  • Just did a test, it will/can play a Beep om CORE2, just change Atom to CORE2 include, change the i2s pins and make one line a comment, the line not supported by CORE2.

    And yes, it is far to much code to get a Beep ;-)

  • thank you for the reply. I think I'm stuck on pin assignment. So on the back of my core2, it says BCLK is 12, LRCK is 0 and DATA is 0. But the example code also has "CONFIG_I2S_DATA_IN_PIN" and "SPEAKER_I2S_NUMBER" but I am not sure what to assign these as.

  • @akaf24 DATA should be 2 not 0, you dont need to change the last two items.

  • @agreedk thank you for reply. I keep getting a compile error. A beep isn't totally needed in my project so i'm just going to leave it out.

  • I haven't tried this but in the .h file there is something called Speaker.setBeep . That might just work.

    in the M5Stack.h file there is this.

        M5.Speaker.tone(uint32_t freq);
        M5.Speaker.tone(freq, time);
        M5.Speaker.setBeep(uint16_t frequency, uint16_t duration);

    And if you open up the example "FactoryTest" there is a section in the code that uses dacWrite to the speaker pin.

    void startupLogo() {
    static uint8_t brightness, pre_brightness;
    uint32_t length = strlen((char*)m5stack_startup_music);
    M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
    for(int i=0; i<length; i++) {
    dacWrite(SPEAKER_PIN, m5stack_startup_music[i]>>2);

    brightness = (i/157);
    if(pre_brightness != brightness) {
    pre_brightness = brightness;

    The startup_music.c is found on another tab when you open the example code.

    // SAMPLES: 40000,
    // CHANNELS: 1,
    // SAMPLERATE: 20000,
    const unsigned char m5stack_startup_music[] = {

    Lots of HEX here*

  • @AgreeDK Thanks a million for your solution, it does work perfectly with the Core2 !
    Just a shame there's no simple beep method in the core2 lib :(

    @Shift1313 as far as I understand, the .Speaker method you are referring to is not part of the M5Core lib, it is working with the Core but not with the Core2

  • 0_1639904411062_Screenshot 2021-12-19 at 08.59.45.png

    in UIFlow you use this block to make a bleep

  • @ajb2k3 Thanks for the tip. Unfortunately it is not that easy when not using UIFlow.
    I am using VSCode + PIO with the Arduino framework

  • I could not here any sound on my system by using the method described above by @AgreeDK. I figured out that you have to switch on the power supply for the integrated amplifier. This is controlled (like all other things needing power inside the Core2) by the APX192. To activate the Power supply use :


  • I too had this need with my Core 2 Stack, so I wrote a few little routines that make sounds based on the M5Stack Atom Speaker code examples.

    The code is at,