Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
esp32:esp32_main [2020/11/17 15:40]
admin [DAC]
esp32:esp32_main [2020/11/17 16:01] (current)
admin [DAC and ADC]
Line 115: Line 115:
 ===== DAC and ADC ===== ===== DAC and ADC =====
  
 +**ADC**\\
 +   analogRead(GPIO);
 +   analogReadResolution(resolution) //set the sample bits and resolution in bits, 9 => (0 – 511) and 12 => (0 – 4095), default 12
 +
 +   analogSetWidth(width) //set the sample bits and resolution
 +   analogSetCycles(cycles) //set the number of cycles per sample, range: 1 - 255, default 8 
 +   analogSetSamples(samples) //set the number of samples in the range, default is 1 sample
 +   analogSetClockDiv(attenuation) //set the divider for the ADC clock, range: 1 - 255, default is 1
 +   analogSetAttenuation(attenuation) //sets the input attenuation for all ADC pins. Default is ADC_11db. Accepted values:
 +    ADC_0db: sets no attenuation (1V input = ADC reading of 1088).
 +    ADC_2_5db: sets an attenuation of 1.34 (1V input = ADC reading of 2086).
 +    ADC_6db: sets an attenuation of 1.5 (1V input = ADC reading of 2975).
 +    ADC_11db: sets an attenuation of 3.6 (1V input = ADC reading of 3959).
 +   analogSetPinAttenuation(pin, attenuation) //sets the input attenuation for the pin, default is ADC_11db
 +   adcAttachPin(pin) //attach a pin to ADC, returns TRUE or FALSE
 +   adcStart(pin) //starts an ADC conversion on attached pin’s bus 
 +   adcBusy(pin) //check if conversion on the pin’s ADC bus is running, returns TRUE or FALSE 
 +   adcEnd(pin) //get the result of the conversion: returns 16-bit integer
 +
 +taken from: [[https://www.malabdali.com/esp32-adc-and-dac/]]
 +
 +----
 **DAC**\\ **DAC**\\
 The ESP32 has two DAC pins, GPIO25 and GPIO26. The resolution is 8 bits.\\ The ESP32 has two DAC pins, GPIO25 and GPIO26. The resolution is 8 bits.\\
    dacWrite(25, Value); // 255=3.3V 128=1.65V 0=0.0V    dacWrite(25, Value); // 255=3.3V 128=1.65V 0=0.0V
 +For generating a sine wave one finds a good manual here: [[https://www.xtronical.com/basics/audio/dacs-on-esp32/|DAC’s on ESP32]]\\
  
 ---- ----