Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ESP32 DAC with web server #7889

Unanswered
cob555 asked this question in Q&A
Feb 25, 2023 · 1 comments · 1 reply
Discussion options

Hello all :-)

Currently I am trying to get a simple DAC up and running which is controlled by a web server.
This code was used as a template (and works fine): https://microcontrollerslab.com/esp32-pwm-slider-web-server-control-led-brightness/

This is the modified code (the LED-commands were deleted and DAC-commands added)

#define DAC_CH1 25
string slider_value = "0";
const char* input_parameter = "value";
AsyncWebServer server(80);
....web-server part is all the same....
String processor(const String& var){
 if (var == "SLIDERVALUE"){
 return slider_value;
 }
 return String();
}
void setup(){
 Serial.begin(115200);
 dacWrite(DAC_CH1, slider_value);
 Serial.println("DAC Value 0");
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
 delay(1000);
 Serial.println("Connecting...");
 }
 Serial.println(WiFi.localIP());
 server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
 request->send_P(200, "text/html", index_html, processor);
 });
 server.on("/slider", HTTP_GET, [] (AsyncWebServerRequest *request) {
 String message;
 if (request->hasParam(input_parameter)) {
 message = request->getParam(input_parameter)->value();
 slider_value = message;
 ledcWrite(DAC_CH1, slider_value.toInt());
 }
 else {
 message = "No message sent";
 }
 Serial.println(message);
 request->send(200, "text/plain", "OK");
 });
 server.begin();
}
 void loop() {}

Apparently there is problem with the definition of the variables and the compiler gives an error message.
"slider_value" is string, but DAC requires uint8_t as an input.
How can this problem be solved?

Thanks in advance.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Two issue there:

  1. You have dacWrite(DAC_CH1, slider_value); in the code and slider_value is string. Line should be dacWrite(DAC_CH1, slider_value.toInt());
  2. In the /slider callback you have ledcWrite(DAC_CH1, slider_value.toInt());, but you want DAC, so change that to dacWrite(DAC_CH1, slider_value.toInt());
You must be logged in to vote
1 reply
Comment options

Thanks a lot. Very embarrassing, I totally overlooked the second command, which needed to be changed.
Now it works just as fine as the PWM-code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /