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

    Getting Microphone Data (decibels) from M5StickC Plus or AtomU

    Micropython
    2
    2
    4.0k
    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.
    • B
      blissend
      last edited by

      I have the M5StickC Plus (https://shop.m5stack.com/products/m5stickc-plus-esp32-pico-mini-iot-development-kit) and soon the AtomU (https://shop.m5stack.com/products/atomu-esp32-development-kit-with-usb-a). My goal is to write something to capture noise levels in decibels and graph that data externally. However I want to do that with Micropython since I'm more familiar with python or even blockly at this point. I just can't figure out how. Here's the blockly/micropython code to just capture data on button press and nothing more...

      from m5stack import *
      from m5ui import *
      from uiflow import *
      from easyIO import *
      
      setScreenColor(0x111111)
      
      while True:
        if btnA.isPressed():
          M5Led.on()
          lcd.clear()
          lcd.print((analogRead(34)), 0, 0, 0xffffff)
        else:
          M5Led.off()
          lcd.clear()
        wait_ms(2)
      

      The problem is that it shows a number 1270 but that doesn't fluctuate based on sound. It's a constant number. Why?

      Looking at https://docs.m5stack.com/en/core/m5stickc_plus it shows that GPIO34 is the pin. Do you need to activate/enable this pin?

      Also, I don't see any mention of analogRead in github https://github.com/m5stack/M5Stack_MicroPython/search?q=analogRead&type=code so I don't even know where to look for this in code. Closest example of using microphone I can find is in Arduino https://github.com/m5stack/M5StickC-Plus/blob/master/examples/Basics/Micophone/Micophone.ino but can't figure out how to translate that into micropython. There is no i2s_read in the micropython library which is what Arduino uses. Maybe it's some permutation of machine.ADC or machine.Pin?

      1 Reply Last reply Reply Quote 0
      • R
        robalstona
        last edited by

        You cannot read data from this microphone via analog read. This microphone is digital and has two digital pins. One of them is clock signal (probably connected to gpio0) which you should drive with 1MHz signal. Second is digital output which give a signal similiar to pwm signal (pulse density modulation) . So only walues which you read are 0V or 3.3V.

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