How do I access the mic on the m5stickc?

  • The posts are very confusing! Half say that it is i2s, and the Arduino code seems to support that. But the other half say that it is just an adc on port 34, and the micropython examples seem to support that!
    I'm interested in using micropython.

  • Hello @dclaar

    looking at the specifications for M5StickC the microphone is listed as SPM1423. Search results for SPM1423 indicate that it is has a PDM encoding output (CLK/DAT) which seems to be a special I2S case.

    I have found this github project, which add the I2S-PDM mode to micropython.

    Here you can find a description of the differences between I2S and PDM.


  • Thanks! Going off that, I found this post, which points to the M5GO blob, which has

    from machine import I2S

    Going into REPL:

     from machine import I2S
    >>> dir(I2S)
    ['__class__', '__name__', 'read', 'start', 'stop', 'write', '__bases__', '__dict__', 'CHANNEL_ALL_LEFT', 'CHANNEL_ALL_RIGHT', 'CHANNEL_ONLY_LEFT', 'CHANNEL_ONLY_RIGHT', 'CHANNEL_RIGHT_LEFT', 'DAC_BOTH_EN', 'DAC_DISABLE', 'DAC_LEFT_EN', 'DAC_RIGHT_EN', 'FORMAT_I2S', 'FORMAT_I2S_LSB', 'FORMAT_I2S_MSB', 'FORMAT_PCM', 'FORMAT_PCM_LONG', 'FORMAT_PCM_SHORT', 'I2S_NUM_0', 'I2S_NUM_1', 'MODE_ADC_BUILT_IN', 'MODE_DAC_BUILT_IN', 'MODE_MASTER', 'MODE_PDM', 'MODE_RX', 'MODE_SLAVE', 'MODE_TX', 'adc_enable', 'bits', 'deinit', 'init', 'nchannels', 'sample_rate', 'set_adc_pin', 'set_dac_mode', 'set_pin', 'volume']
    >>> import wave
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: no module named 'wave'

    So at least part of it is there! I found a listing of the class, but no documentation.

    Then I found some examples, but they say Micropython after June 2021, so may not apply??

    That talks about a "WS" pin, which I found described here.

    The schematic shows only 2 pins however: SCL & SDA. The Unit unit :) appears to have WS tied to ground. Mouser indicates that the pin is tied low internally, and that is the left channel, but the arduino code sets it to I2S_CHANNEL_FMT_ALL_RIGHT.
    Here's an I2S tutorial.
    So, time to play I guess!

  • Thinking about how to test it: the M5StickC has no speaker.
    OK, I have the Core Gray: It has a speaker! But no mic.
    Maybe I could hook both of them together...
    This is getting way too complicated for the idea I had in mind, which was some responsive blinky lights for Halloween. (Yes, it's next week. Your point?) :) I think I'll use the accelerometer instead.

  • Hi is spent a long time to find how use PDM microphone in m5stickC and finally i pass. I find some code thats should work, but its not working.

    from machine import I2S, Pin
    mic = I2S(I2S.NUM0, ws=Pin(0), sdin=Pin(34), mode=I2S.MASTER_PDW, dataformat=I2S.B16, channelformat=I2S.ONLY_RIGHT, samplerate=16000, dmacount=16, dmalen=256)
    buffer = bytearray(7168)
    while True:
        # read data into buffer
        # do something with data stored in buffer

  • @robalstona pin 0 is the clock, not ws, according to the sticker on the back. Don't know if that helps.