Using Dwin display generated bit in ESP32 program

Hi to everyone!
I am working on a project using ESP32 and Dwin 7" display. I am using PWM pin to generate pulse with fix duty cycle and variable frequency. My program is generating pulses when I put an integer for frequency in line no.37 i.e. const int freq = 120; // set the frequency . Here I get frequency 120 at PWM pin.
On sending any number from Dwin display (on Rx2) by pressing a button , number is received and printed in serial monitor. Please see line no.21 i.e. Serial.println(" "+ String(lastByte, DEC)+ " "); //Last byte of string in decimal .
Now I want to set frequency in line no.37 according to the number received from Dwin display. But on putting received number in line no.37 ( const int freq = "+ String(lastByte, DEC)+ "; // set the frequency ), I am getting error as "Compilation error: invalid conversion from 'const char*' to 'int' [-fpermissive]".
Please help to eliminate the error so as to set the frequency of PWM pin according to the number received from the display.
I would be very thankful.

#include <Arduino.h>
#include <DWIN.h>
#define ADDRESS_A     "1010"
#define ADDRESS_B     "1020"

#include <Mapf.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;  
  #define DGUS_BAUD     115200
  #define DGUS_SERIAL Serial2
  DWIN hmi(DGUS_SERIAL, 16, 17, DGUS_BAUD);

/* For Software serial */
//#include <SoftwareSerial.h>
//const byte rxPin = 16; //rx2
//const byte txPin = 17; //tx2
//SoftwareSerial mySerial (rxPin, txPin);

// Event Occurs when response comes from HMI
void onHMIEvent(String address, int lastByte, String message, String response){  
  Serial.println(" "+ String(lastByte, DEC)+ " ");  //Last byte of string in decimal

  if (address == "1002"){
  // Take your custom action call
  }
}
float ldrValue;
//#define eNO_PIN 39 // VN  pin connected with eNO

/* Adresses of all sensors */
unsigned char Buffer[9];
#define ldr_add   0x63
unsigned char   eNO[8] = {0x5a, 0xa5, 0x05, 0x82, ldr_add , 0x00, 0x00, 0x00};

//PWM Code Part
const int ledPin = 13;      // the PWM pin the LED is attached to
const int freq = 120;      // set the frequency 
const int ledChannel = 0;   // set the PWM channel
const int resolution = 8;   // set PWM resolution

void setup() {
  ledcSetup(ledChannel, freq, resolution);  // define the PWM Setup
  ledcAttachPin(ledPin, ledChannel);
  Serial.begin(115200);
  //mySerial.begin(115200);
  delay(100);  

    Serial.println("DWIN HMI ~ Hello World");
    hmi.echoEnabled(false);
    hmi.hmiCallBack(onHMIEvent);
    hmi.setPage(1);

  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  if (!ads.begin())
  {
    Serial.println("Failed to initialize ADS.");
    while (1); 
  }

}
void loop() {
  int16_t adc0, adc1, adc2, adc3;
  float volts0, volts1, volts2, volts3;
 
  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
 
  volts0 = ads.computeVolts(adc0);
  volts1 = ads.computeVolts(adc1);
  volts2 = ads.computeVolts(adc2);
  volts3 = ads.computeVolts(adc3);

 
  Serial.println("-----------------------------------------------------------");
  //Serial.print("AIN0: "); Serial.print(adc0); Serial.print("  "); Serial.print(volts0); Serial.println("V");
  Serial.print("AIN1: "); Serial.print(adc1); Serial.print("  "); Serial.print(volts1); Serial.println("V");
  //Serial.print("AIN2: "); Serial.print(adc2); Serial.print("  "); Serial.print(volts2); Serial.println("V");
  //Serial.print("AIN3: "); Serial.print(adc3); Serial.print("  "); Serial.print(volts3); Serial.println("V");

  
  //ldrValue = (volts1 - 0.4) * (156);
  ldrValue = mapf(volts1, .4, 2, 0, 250);
  
  Serial.print("eNO Value: ");
  Serial.println(ldrValue);
   Serial.println(freq);
//void Data_Arduino_to_Display() {
  delay(1000);
  int ldrVal = ldrValue;
  /*------Send Data to Display------*/
  eNO[6] = highByte(ldrVal);
  eNO[7] = lowByte(ldrVal);
  DGUS_SERIAL.write(eNO, 8);
  //mySerial.write(eNO, 8);
  //PWM Code Part
   ledcWrite(ledChannel,10);        // set the Duty cycle to 50 out of 255
  // Listen HMI Events
    hmi.listen();
}

Your description does not indicate that you have a problem with IDE 2.x and therefore had been moved to a more suitable location on the forum.

I can't really look at your code at the moment but why do you try to add a String to an integer?

Thanks a lot for your reply. My target is to set frequency of ESP32 PWM by sending an integer from Dwin display. For example, if 25 is sent from Dwin display then frequency of PWM should set at 25 HZ.
Thanks

String is transmitted from HMI.

I have modified the program by converting string to integer using toInt(). Now previous error i.e. "Compilation error: invalid conversion from 'const char*' to 'int' [-fpermissive]" is not generated. But on putting the value of integer in 'void Setup' section I am getting error as-
''Compilation error: 'myInt' was not declared in this scope". Can please someone help!

  #include <Arduino.h>
  #include <DWIN.h>
  #include <String.h>
  #define ADDRESS_A     "1010"
  #define ADDRESS_B     "1020"
  #include <Mapf.h>
  #include <Adafruit_ADS1X15.h>
  Adafruit_ADS1115 ads;
  #define DGUS_BAUD     115200
  #define DGUS_SERIAL Serial2
  DWIN hmi(DGUS_SERIAL, 16, 17, DGUS_BAUD);
void onHMIEvent(String address, int lastByte, String message, String response){  
  Serial.println(" "+ String(lastByte, DEC)+ " ");  //Last byte of string in decimal
  String myString = "123";
int myInt = String(lastByte).toInt();
  Serial.println(myInt) ;
    if (address == "1002"){ 
  }
}
float ldrValue;
unsigned char Buffer[9];
#define ldr_add   0x51
unsigned char   eNO[8] = {0x5a, 0xa5, 0x05, 0x82, ldr_add , 0x00, 0x00, 0x00};
const int ledPin = 13;      // the PWM pin the LED is attached to
const int freq = myInt ;      // set the frequency 
const int ledChannel = 0;   // set the PWM channel
const int resolution = 8;   // set PWM resolution
void setup() {
    Serial.begin(115200);
    Serial.println("DWIN HMI ~ Hello World");
    hmi.echoEnabled(false);
    hmi.hmiCallBack(onHMIEvent);
    hmi.setPage(1);
    ledcSetup(ledChannel, freq, resolution);  // define the PWM Setup
    ledcAttachPin(ledPin, ledChannel); 
  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  if (!ads.begin())
  {
    Serial.println("Failed to initialize ADS.");
    while (1); 
  }
}
void loop() {
  hmi.listen();
  int16_t adc0, adc1, adc2, adc3;
  float volts0, volts1, volts2, volts3;   
  adc1 = ads.readADC_SingleEnded(1);  
  volts1 = ads.computeVolts(adc1); 
  Serial.println("-----------------------------------------------------------");
  Serial.print("AIN1: "); Serial.print(adc1); Serial.print("  "); Serial.print(volts1); Serial.println("V");  
  ldrValue = mapf(volts1, .4, 2, 0, 250);  
  Serial.print("eNO Value: ");
  Serial.println(ldrValue);
  delay(1000);
  int ldrVal = ldrValue; //Send Data to HMI
  eNO[6] = highByte(ldrVal);
  eNO[7] = lowByte(ldrVal);
  DGUS_SERIAL.write(eNO, 8);
  ledcWrite(ledChannel,10);        // set the Duty cycle out of 255
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.