Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

[support] M5stick-c doesn't seem to work #6

@DimmKirr

Description

@DimmKirr

First of all, great kudos for such work, Mike!

I'm trying to make my m5stick-c, which is based on ESP32-PICO, and I'm getting no signal

I've merged your changes to the main branch of micropython and built it. Module inclusion, class instantiation works fine, but the wav file has only a header, and the signal is all zeroes.

I would appreciate if you or anyone could give me a hint where to look and troubleshoot. Thanks again!

Here's the latest iteration of the snippet (not that m5stick-c documentation doesn't provide any info on bck, and examples refer to I2S_PIN_NO_CHANGE

from machine import I2S
from machine import Pin

SAMPLE_BLOCK_SIZE = 4096
BITS_PER_SAMPLE = 16
BYTES_PER_SAMPLE = BITS_PER_SAMPLE // 8
SAMPLES_PER_SECOND = 16000
RECORD_TIME_IN_SECONDS = 8
DMA_LEN = 512

WAV_DATA_SIZE = RECORD_TIME_IN_SECONDS * SAMPLES_PER_SECOND * BYTES_PER_SAMPLE
wav_header = gen_wav_header(SAMPLES_PER_SECOND, BITS_PER_SAMPLE, 1, SAMPLES_PER_SECOND * RECORD_TIME_IN_SECONDS)

bck_pin = Pin(0)
ws_pin = Pin(0)
sdin_pin = Pin(34)

audio_in = I2S(I2S.NUM0, bck=bck_pin, ws=ws_pin, sdin=sdin_pin,
               standard=I2S.PHILIPS, mode=I2S.MASTER_RX,
               dataformat=I2S.B16,                                                         # Each sample will only take up 2bytes in DMA memory
               # NOTE: ONLY_RIGHT actually samples left channel.
               channelformat=I2S.ALL_RIGHT,                                               # Only sample single left channel (mono mic)
               samplerate=SAMPLES_PER_SECOND,
               dmacount=16,
               dmalen=DMA_LEN
               )

s = open('/mic_recording.wav', 'wb')
s.write(wav_header)

mic_samples = bytearray(SAMPLE_BLOCK_SIZE)

TOTAL_BYTES = RECORD_TIME_IN_SECONDS * SAMPLES_PER_SECOND * BYTES_PER_SAMPLE
bytes_written = 0

# Keep recording until enough samples are written
while bytes_written < TOTAL_BYTES:
    try:
        numread = 0
        numwrite = 0
        numread = audio_in.readinto(mic_samples, timeout=0)
        # If there were samples available in DMA, persist to flash
        if numread > 0:
            numwrite = s.write(mic_samples[:numread])
            bytes_written += numwrite
    except KeyboardInterrupt:
        break

s.close()
audio_in.deinit()

print('Done %d bytes written to flash' % bytes_written)

M5Stick-C specific Arduino Example One
M5Stick-C specific Arduino Example Two

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions