Serial overload- Sensor readout in conflict with Nextion display communication?

Post Reply
marcel00
Posts: 7
Joined: Tue Jul 02, 2019 5:03 pm

Serial overload- Sensor readout in conflict with Nextion display communication?

Post by marcel00 » Wed Nov 06, 2019 8:05 am

Hello

an .ino file shall establish the communication between I2c sensors, Nextion display and a Controllino Maxi Automation.The Serial2 port is set at 115200 baud. Initially I am trying to readout a BME280 sensor and want to display the values on a Nextion enhanced display. Therefore I use void pressure_temperature_humidity(). Next to reading out the values I also want to let follow actions on touching buttons.
If pressure_temperature_humidity(); is commented out in the loop() the button touching is followed by correct actions(i.e.setting Digital outputs).
The serial monitor returns no recvRetNumber err for Nextion com. This is not the case if pressure_temperature_humidity();
is implemented. So I guess that the serial communication is overloaded and correct messaging is not possibly anymore. How can I prevent such overload. I already added a delay behind the bme readouts without success. Unfortunetaly I cannot attach the ino file.

Code: Select all

void pressure_temperature_humidity() {
  float tempoffset = -3.0;
  float temperatureC = bme.readTemperature() + tempoffset;
  //delay(10);
  Serial.print("Temp ="); Serial.println(temperatureC);
  /*
  float pressureKPA = bme.readPressure();
  //delay(10);
  Serial.print("Press. ="); Serial.println(pressureKPA);
  float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  //delay(10);
  Serial.print("Alt. ="); Serial.println(altitude);
  float humidity = bme.readHumidity();
  //delay(10);
  Serial.print("humidity ="); Serial.println(humidity);
  
  String pre_TXT = String(pressureKPA / 100.0, 0); //Will show no decimal place
  memset(buffer, 0, sizeof(buffer));
  pre_TXT.toCharArray(buffer, 10);
  if (strcmp(buffer, buffer_pres)) //compares buffer with previous set buffer_pres. If it differs buffer_pres will be updated
  {
    t16.setText(buffer);
    strcpy(buffer_pres, buffer);
  }
  delay(10);
  memset(buffer, 0, sizeof(buffer));
  String temp_batTXT = String(temperatureC, 0); //Will show no decimal place
  temp_batTXT.toCharArray(buffer, 10);
  if (strcmp(buffer, buffer_temp_bat))
  {
    t6.setText(buffer);
    strcpy(buffer_temp_bat, buffer);
  }
  delay(10);
  memset(buffer, 0, sizeof(buffer));
  String humidityTXT = String(humidity, 0); //Will show no decimal place
  humidityTXT.toCharArray(buffer, 10);
  if (strcmp(buffer, buffer_humidity))
  {
    t23.setText(buffer);
    strcpy(buffer_humidity, buffer);
  }
  delay(10);*/
}

Post Reply