Skip to content

Conversation

@xuancong84
Copy link
Contributor

This uses ESP-IDF continuous ADC driver to perform continuous ADC sampling and stream the data to an IP:PORT over UDP

Summary

Continuous ADC is very useful in practical applications. For example, you can use it to stream PCM audio (voice recording needs only 16kHz) without the need of MP3 codec chip, plot voltage/current waveforms (as an oscilloscope), or view raw signals.

Example

The following code streams ADC channel (ADC_channel_number) to 1.2.3.4:8888 via UDP for 5 seconds.

machine.config_adc_udp_stream(ADC_channel_number, ADC_attenuation, ADC_unit);
machine.start_adc_udp_stream(44100, "1.2.3.4", 8888);
time.sleep(5)
machine.stop_adc_udp_stream();

This uses ESP-IDF continuous ADC driver to perform continuous ADC
sampling and stream the data to an IP:UDP_PORT
@peterhinch
Copy link
Contributor

MicroPython has a mechanism for performing continuous asynchronous stream reading in asyncio.StreamReader. A means of instantiating a StreamReader from an ADC would have applications beyond sourcing UDP data and might be more likely to win approval from the maintainers.

@xuancong84
Copy link
Contributor Author

Thanks for suggesting asyncio.StreamReader. I am actually implementing a voice recorder (without audio codec chip) which uploads to a smart-home compute node. Since audio sampling rate is typically 16000Hz or 44100Hz, execution speed is critical. That is why even TCP might not be fast enough because of all the handshake and acknowledgement packets. I think the only reasonable application case is to either store it locally (e.g., 5 seconds speech at 16kHz will take ~160KB) or send over UDP. But someone can try to see how to fit into the StreamReader framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants