Lab 1: DAC Output with ESP32
Lab 1: DAC Output with ESP32
Lab 1: DAC Output with ESP32
A DAC code selects an output level. Predict several values and compare them with an unloaded meter reading; errors and load affect the real output.
Materials:
Use a classic ESP32 board, a high-impedance multimeter, and jumper wires.
Circuit:
Connect the meter between GPIO25 and board ground. Leave the DAC otherwise unloaded. To drive an LED, use a suitable current-limited driver and check its input and supply limits.
ESP32 DAC sweep code
The loop steps through codes and prints an ideal voltage prediction. Compare those predictions with an unloaded meter reading; the real output may differ.
void setup() {
// DAC channels: 25 and 26
Serial.begin(115200);
}
void loop() {
// Sweep from 0V to 3.3V
for (int i = 0; i <= 255; i += 5) {
dacWrite(25, i); // 8-bit DAC (0-255)
float voltage = (i / 255.0) * 3.3;
Serial.print("DAC Value: ");
Serial.print(i);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.println("V");
delay(100);
}
}Measurements:
Predict the unloaded voltage from the ideal model, then measure several codes with the meter. Record the difference; real output depends on the device and load.
Expected Learning:
The code selects one of 256 output levels. Compare the measured levels with the ideal prediction and the error allowed by your design.