I was successful in recording something like a wave form with the following code:
from machine import I2S, Pin
import array
mic = I2S(I2S.NUM0, ws=Pin(0), sdin=Pin(34), mode=I2S.MASTER_PDM, dataformat=I2S.B16, channelformat=I2S.ONLY_RIGHT, samplerate=16000, dmacount=16, dmalen=256)
b2 = array.array("h", 4096 * [0])
mic.readinto(b2)
However, there seems to be a systematic offset around ~+1000. Not sure what is going on here. Could it be related to PDM encoding and the I2S clock? Also, I experience values that are larger than the 12bit precision documented somewere
def eval():
mic.readinto(b2)
print(min(b2), max(b2), sum(b2)/len(b2))
for i in range(1000): eval()
...
48 1963 1017.062
811 1237 1027.727
927 1122 1021.952
849 1286 1023.281
763 1719 1029.73
102 1966 1015.185
-903 2878 1012.832
-788 2683 984.9133
-1524 2761 982.3828
-815 3075 986.0596
-864 3044 980.6567
-713 2904 993.0678
-669 2615 1014.595
-138 2182 1022.794
-73 1954 1018.482
...