Search code examples
esp32adcnanoframeworki2s

ESP32 I2S in nanoFramework


I'm trying to replicate a C++ project I found for sampling sound data on the ESP32 using I2S, but using C# and nanoFramework.

In the ADCSampler.cpp file the following headers are loaded

#include <Arduino.h>
#include "driver/i2s.h"
#include "driver/adc.h"

nanoframework has the namespace Windows.Devices.Adc that I understand as more or less the same as driver/adc.h.

However I cannot find anything that is the same as I2S, there is a library for I2C

The specific code I'm struggling with is:

void ADCSampler::configureI2S()
{
    //init ADC pad
    i2s_set_adc_mode(m_adcUnit, m_adcChannel);
    // enable the adc
    i2s_adc_enable(getI2SPort());
}

I have found that you can configure the ADC in nanoFramework as follow:

Configuration.SetPinFunction(35, DeviceFunction.I2S1_MDATA_IN);

and getting the ADC Channel

..
 AdcChannel _adcChannel7;
..
..
 _adc = AdcController.GetDefault();
 _adcChannel7 = _adc.OpenChannel(7);//GPIO pin 35 is adc channel 7
..
..
_mV = _adcChannel7.ReadValue();
..

but that is about as much as I can figure out.

I'm pretty new to microcontrollers and the ESP32 platform, so still learning a lot.

Have I missed something or is this still in the works?

Are there other options that can be used instead of I2S?


Solution

  • You're getting close! A couple of clarifications:

    1. despite the namespace looks similar it has to be added to the build. It's calling other functions that are required to exposed ADC features to the managed application.
    2. In the current version, we are using pre-compiled ESP32 IDF libraries and I2S is not part of them. Meaning that you won't be able to use anything that's I2S related. Good news is that we'll be releasing a new version this week that includes I2S and a brand new C# library for I2S it's in the works and will be available shortly after.

    So please follow our Twitter account or join the Discord community so you get notified of all that.