🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to Generate a Beep?

    Core 2
    10
    19
    29.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      akaf24
      last edited by

      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.

      A 1 Reply Last reply Reply Quote 0
      • A
        AgreeDK @akaf24
        last edited by AgreeDK

        @akaf24 DATA should be 2 not 0, you dont need to change the last two items.
        ( "CONFIG_I2S_DATA_IN_PIN" and "SPEAKER_I2S_NUMBER" )

        A 1 Reply Last reply Reply Quote 0
        • A
          akaf24 @AgreeDK
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • S
            Shift1313
            last edited by

            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.

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

            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.setBrightness(0);
            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);
            delayMicroseconds(40);

            brightness = (i/157);
            if(pre_brightness != brightness) {
            pre_brightness = brightness;
            M5.Lcd.setBrightness(brightness);
            }
            }

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

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

            Lots of HEX here*

            1 Reply Last reply Reply Quote 0
            • E
              erich
              last edited by

              @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

              1 Reply Last reply Reply Quote 0
              • ajb2k3A
                ajb2k3
                last edited by

                0_1639904411062_Screenshot 2021-12-19 at 08.59.45.png

                in UIFlow you use this block to make a bleep

                UIFlow, so easy an adult can learn it!
                If I don't know it, be patient!
                I've ether not learned it or am too drunk to remember it!
                Author of the WIP UIFlow Handbook!
                M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                1 Reply Last reply Reply Quote 0
                • E
                  erich
                  last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • O
                    olliy78
                    last edited by

                    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 :

                    M5.Axp.SetSpkEnable(1);

                    1 Reply Last reply Reply Quote 0
                    • L
                      LostInSpace
                      last edited by

                      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,
                      https://github.com/Hagtronics/M5Stack-Core2/tree/main/Sound

                      I 1 Reply Last reply Reply Quote 1
                      • I
                        ioamas @LostInSpace
                        last edited by

                        @LostInSpace I am quite new to all this so could you post a simple code of making a beep with your library.
                        thank you
                        Ioannis

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post