ESP32C3's 2 DAC channel to control 2 DC motors
2025.07.10 22:49
I asked Google's Gemini, "How to control 2 DC motors with ESP32's two DAC, not with PWM?"
AI Overview
To code a Digital-to-Analog Converter (DAC) on an ESP32C3 using the Arduino IDE, you'll primarily use the
dacWrite()
function, specifying the DAC channel and the desired output value (0-255). The ESP32C3 has two DAC channels, GPIO25 and GPIO26, which can be used as analog outputs.
This video explains how to use the DAC pins on the ESP32:
Here's a basic example:
You can watch this video to see an example of using DAC on ESP32:
Explanation:
-
Use
#define
to assign meaningful names (likeDAC_CH1
,DAC_CH2
) to the GPIO pins you'll be using for the DAC channels (25 and 26). -
In this simple example, no specific setup is required for the DAC itself. If you were using the DAC with a more complex system (like I2S for audio), you might need to initialize it in
setup()
. -
dacWrite(DAC_CH1, 127);
writes the value 127 (an 8-bit value) to DAC channel 1, corresponding to a voltage of approximately 1.65V (half of the ESP32's 3.3V supply).dacWrite(DAC_CH1, 255);
writes the value 255 to DAC channel 1, resulting in a voltage of approximately 3.3V.dacWrite(DAC_CH2, 64);
writes the value 64 to DAC channel 2, resulting in a voltage of approximately 0.825V.dacWrite(DAC_CH2, 0);
writes the value 0 to DAC channel 2, resulting in a voltage of 0V.
-
The
delay()
function is used to pause the execution of the loop, allowing you to observe the voltage changes on the DAC pins.
Key points:
- The ESP32C3's DAC is an 8-bit DAC, meaning it can output 256 different voltage levels (0-255).
- The output voltage is proportional to the value written to the DAC. The relationship is roughly
output_voltage = (value / 255.0) * 3.3
. - You can use the
dacWrite()
function with either DAC channel (GPIO25 or GPIO26). - For more complex applications, you might need to consider using the I2S peripheral for higher-quality audio output with the DAC.
Comment 0
No. | Subject | Author | Date | Views |
---|---|---|---|---|
14 | Solve problem with 2D Lidar | me | 2025.07.17 | 24 |
» | ESP32C3's 2 DAC channel to control 2 DC motors | me | 2025.07.10 | 300 |
12 |
Project Moomalengi 무말랭이 (Seasoned Dried Radish)
![]() | me | 2025.01.19 | 71 |
11 |
Circuit Python 실험.
[1] ![]() | me | 2023.09.25 | 255 |
10 |
Speedybee F405 WING
![]() | me | 2023.09.05 | 277 |
9 |
Orange Pi Zero 3 with Debian
![]() | me | 2023.09.02 | 273 |
8 |
Logitech G Extreme 3D Pro USB Joystick
![]() | me | 2023.08.26 | 280 |
7 | Beagle Bone Blue as flight controller | me | 2023.08.26 | 374 |
6 | Ardupilot (Ardu-Rover) with Lidar | me | 2023.08.10 | 271 |
5 |
2D Lidar enabled Rover Tutorial Project
[1] ![]() | me | 2023.07.17 | 282 |
4 |
Beagle Bone Blue for ArduPilot (Rover, Plane, Drone, Submersible, etc)
![]() | me | 2023.07.11 | 290 |
3 | Souther California R/C Flying Clubs | me | 2023.07.05 | 225 |
2 |
Project : Rover One
![]() | me | 2023.01.18 | 311 |
1 | My SBCs that I have installed Lazarus IDE on them. | me | 2022.10.17 | 299 |