Open BoLiu97 opened 1 month ago
However, I am unable to send data through the code above. By adding a timesleep, I am able to send but having a different sample rate.
time.sleep()
and for how longHowever, I am unable to send data through the code above. By adding a timesleep, I am able to send but having a different sample rate.
- Could you elaborate? What exactly fails with the code above?
- Where did you add the
time.sleep()
and for how long- What do you mean by "having a different sample"?
WARNING:root:Expected 320 bytes, received 0 bytes.
2,3. By using
mic.record(samples, len(samples)) data = struct.pack('<' + 'H' * len(samples), *samples) print('something') usb_cdc.data.write(data)
or
mic.record(samples, len(samples)) data = struct.pack('<' + 'H' * len(samples), *samples) usb_cdc.data.write(data) time.sleep(10)
I was able to receive data for my PC. However, It took about 15 seconds to receive a 3 seconds audio sample and the sound is abnormal.
Instead of trying to read 320 bytes at once with a 10-second timeout, try reading much smaller chunks, or read with timeout=0
.
I am thinking that the reader on the PC side might get out of sync and miss some of the initial bytes. That would make it be out of sync from then on, waiting and waiting, when the microcontroller side has already sent everything. To test this, I would change the microcontroller side to send some known test data, and not do PDMIn for now. Instead, send some packets that are numbered sequentially in some way so you can see if and what gets dropped on the receiving side. You could also do some synchronization. For instance, don't send anything until you've received a "go ahead" signal from the PC. That could be just a single byte indicator.
CircuitPython version
Code/REPL
Behavior
I am trying to collect PDM microphone data and send to my PC. I am using Feather M4 express. However, I am unable to send data through the code above. By adding a timesleep, I am able to send but having a different sample rate.
Description
No response
Additional information
Having this code to receive data from my PC side