element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Forum how to read mic in esp32 s3 sense using micropython
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 4 replies
  • Subscribers 46 subscribers
  • Views 1282 views
  • Users 0 members are here
  • python
  • micropython
Related

how to read mic in esp32 s3 sense using micropython

manojroy123
manojroy123 10 months ago

Does anyone knows how to read microphone in esp32 s3 sense development board using micropython. 

  • Sign in to reply
  • Cancel
Parents
  • dougw
    0 dougw 10 months ago

    You could check ESP BOX at Adafruit to see if it is compatible.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • manojroy123
    0 manojroy123 10 months ago in reply to dougw

    There are micropython code that are available but it is showing pin error in it.

    Please check the bellow code

    import machine
    import time
    import ustruct

    # Configure I2S for the built-in microphone
    # Pin definitions for ESP32-S3 (based on ESP32-S3 Sense specs)
    # These may vary depending on the board revision. Check the datasheet.
    I2S_SCK = 18 # Serial clock pin
    I2S_WS = 19 # Word select (left/right channel)
    I2S_SD = 21 # Serial data input pin (microphone data)

    # Set up I2S
    i2s = machine.I2S(
    id=0, # I2S interface 0
    sck=machine.Pin(I2S_SCK), # Serial clock pin
    ws=machine.Pin(I2S_WS), # Word select pin
    sd=machine.Pin(I2S_SD), # Serial data input pin
    mode=machine.I2S.MASTER, # Mode is master
    bits=16, # Data bits per word (16-bit audio)
    format=machine.I2S.MONO, # Mono audio (single channel)
    rate=16000, # Sampling rate in Hz (typically 16kHz for mic)
    dma=True # Use DMA (Direct Memory Access) for efficient data transfer
    )

    # Buffer to store audio data (e.g., 256 bytes for each read)
    buffer = bytearray(256)

    while True:
    # Read audio data from the microphone
    bytes_read = i2s.readinto(buffer)

    if bytes_read:
    # Process the data (e.g., printing first 10 bytes for debugging)
    print("Data read from mic:", [ustruct.unpack('<h', buffer[i:i+2])[0] for i in range(0, bytes_read, 2)])

    # Delay to allow for continuous reading at a reasonable rate
    time.sleep(0.1)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • manojroy123
    0 manojroy123 10 months ago in reply to dougw

    There are micropython code that are available but it is showing pin error in it.

    Please check the bellow code

    import machine
    import time
    import ustruct

    # Configure I2S for the built-in microphone
    # Pin definitions for ESP32-S3 (based on ESP32-S3 Sense specs)
    # These may vary depending on the board revision. Check the datasheet.
    I2S_SCK = 18 # Serial clock pin
    I2S_WS = 19 # Word select (left/right channel)
    I2S_SD = 21 # Serial data input pin (microphone data)

    # Set up I2S
    i2s = machine.I2S(
    id=0, # I2S interface 0
    sck=machine.Pin(I2S_SCK), # Serial clock pin
    ws=machine.Pin(I2S_WS), # Word select pin
    sd=machine.Pin(I2S_SD), # Serial data input pin
    mode=machine.I2S.MASTER, # Mode is master
    bits=16, # Data bits per word (16-bit audio)
    format=machine.I2S.MONO, # Mono audio (single channel)
    rate=16000, # Sampling rate in Hz (typically 16kHz for mic)
    dma=True # Use DMA (Direct Memory Access) for efficient data transfer
    )

    # Buffer to store audio data (e.g., 256 bytes for each read)
    buffer = bytearray(256)

    while True:
    # Read audio data from the microphone
    bytes_read = i2s.readinto(buffer)

    if bytes_read:
    # Process the data (e.g., printing first 10 bytes for debugging)
    print("Data read from mic:", [ustruct.unpack('<h', buffer[i:i+2])[0] for i in range(0, bytes_read, 2)])

    # Delay to allow for continuous reading at a reasonable rate
    time.sleep(0.1)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • bidrohini
    0 bidrohini 10 months ago in reply to manojroy123

    The ESP32-S3 Sense has a built-in PDM microphone. For I2S, verify that the pins you've defined (I2S_SCK, I2S_WS, and I2S_SD) match the board's actual pinout. Not all pins on the ESP32-S3 support I2S. Verify that your selected pins are valid I2S pins by consulting the ESP32-S3 datasheet or technical reference manual. You may also want to check this Raspberry pi passed voice control project for some references: www.theengineeringprojects.com/.../voice-control-project-using-raspberry-pi-4.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube