DWIN dGUS to NPK sensor

//ultrasonic display data on DWIN display
//https://youtu.be/SdKTSLY3sW8
//www.alselectro.in

#include <SoftwareSerial.h>
const byte rxPin = 7;
const byte txPin = 8;

// Set up a new SoftwareSerial object
SoftwareSerial dwinSerial (rxPin, txPin);
SoftwareSerial mod(4,5);  // RX, TX

/* Data frame for sensor */
unsigned char nitrogen[8]={0x5A, 0xA5, 0x05, 0x82, 0x51, 0x00, 0x00, 0x00};
unsigned char phosphorus[8]={0x5A, 0xA5, 0x05, 0x82, 0x52, 0x00, 0x00, 0x00};
unsigned char potassium[8]={0x5A, 0xA5, 0x05, 0x82, 0x53, 0x00, 0x00, 0x00};
unsigned char phlevel[8]={0x5A, 0xA5, 0x05, 0x82, 0x54, 0x00, 0x00, 0x00};
unsigned char electrical[8]={0x5A, 0xA5, 0x05, 0x82, 0x55, 0x00, 0x00, 0x00};
unsigned char moisture[8]={0x5A, 0xA5, 0x05, 0x82, 0x56, 0x00, 0x00, 0x00};

float moist, ec, pH, nitroValue, phosValue, potas;
String season,texture,variety;
void setup() 
{
  Serial.begin(115200);
  dwinSerial.begin(115200);
  mod.begin(4800);
}

void loop() 
{
  byte queryData[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x04, 0x08};
  byte receivedData[19];
  mod.write(queryData, sizeof(queryData));  // Send the query data to the NPK sensor
  delay(1000);  // Wait for 1 second

  if (mod.available() >= sizeof(receivedData)) {  // Check if there are enough bytes available to read
    mod.readBytes(receivedData, sizeof(receivedData));  // Read the received data into the receivedData array

    // Parse and print the received data in decimal format
    unsigned int soilHumidity = (receivedData[3] << 8) | receivedData[4];
    unsigned int soilTemperature = (receivedData[5] << 8) | receivedData[6];
    unsigned int soilConductivity = (receivedData[7] << 8) | receivedData[8];
    unsigned int soilPH = (receivedData[9] << 8) | receivedData[10];
    unsigned int nitrogen = (receivedData[11] << 8) | receivedData[12];
    unsigned int phosphorus = (receivedData[13] << 8) | receivedData[14];
    unsigned int potassium = (receivedData[15] << 8) | receivedData[16];

    moist = (soilHumidity / 10.0);
    // temp = soilTemperature;
    ec = (soilConductivity / 1000.0);
    pH = (soilPH / 10.0);
    nitroValue = (nitrogen / 1000.0 * 10.0);
    phosValue = (phosphorus);
    potas = (potassium / 1000.0 / 39.0983 * 100.0);
    // Serial.print("Nitrogen");
    // Serial.println(nitroValue);
    // Serial.print("Phosphorus:");
    // Serial.println(phosValue);
    // Serial.print("Potassium");
    // Serial.println(potas);
    // Serial.print("EC");
    // Serial.println(ec);
    // Serial.print("PH");
    // Serial.println(pH);
    // Serial.print("Moisture");
    // Serial.println(moisture);

    delay(5000);
  }
  int n = static_cast<int>(nitroValue * 100);  
  int p = static_cast<int>(phosValue * 100);  
  int k = static_cast<int>(potas * 100);  
  int h = static_cast<int>(pH * 100);  
  int e = static_cast<int>(ec * 100);  
  int m = static_cast<int>(moist * 100);  

  nitrogen[6] =highByte(n);
  nitrogen[7] =lowByte(n);
  dwinSerial.write(nitrogen,8); 
  
  phosphorus[6] =highByte(p);
  phosphorus[7] =lowByte(p);
  dwinSerial.write(phosphorus,8); 
  
  potassium[6] =highByte(k);
  potassium[7] =lowByte(k);
  dwinSerial.write(potassium,8); 

  phlevel[6] =highByte(h);
  phlevel[7] =lowByte(h);
  dwinSerial.write(phlevel,8); 

  electrical[6] =highByte(e);
  electrical[7] =lowByte(e);
  dwinSerial.write(electrical,8); 

  moisture[6] =highByte(m);
  moisture[7] =lowByte(m);
  dwinSerial.write(moisture,8); 
  delay(500);
}

can anyone help me in my code I am using DWIN DGUS lcd display , its working perfectly but the mositure,pH,phosphorus is not showing only nitrogen potassium and ec but if i comment this out the other three is showing then. can you help me with the code thanks.

I moved your topic to an appropriate forum category @mj4w.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

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