Esp32에 dht11 센서를 연결후 hmi(dwin)와 통신이 안됨

#define DWIN_SERIAL Serial2
#define DWIN_RX_PIN 16
#define DWIN_TX_PIN 17
#define Relay1 22

#include <stdint.h> // int16_t, uint16_t 사용을 위한 헤더 파일 추가

int16_t temp;   // 2바이트 정수형 온도 데이터
uint16_t humid;  // 2바이트 정수형 습도 데이터 (음수 값 없을 경우)

#include <DHT.h>
#define DHTTYPE DHT11     // DHT 11
#define DHTPIN 18 // D8  pin connected with DHT
DHT dht(DHTPIN, DHTTYPE);

/* Adresses of all sensors  temp vp 5000  humid  5200 switch 5500*/
unsigned char Buffer[9];
#define temp_address   0x55
#define hum_address    0x56
#define switch_address   0x54

unsigned char   Temperature[8] = {0x5A, 0xA5, 0x05, 0x82, temp_address , 0x00, 0x00, 0x00};
unsigned char      Humidity[8] = {0x5A, 0xA5, 0x05, 0x82, hum_address, 0x00, 0x00, 0x00};

void setup() {
  Serial.begin(115200); // 디버깅용 시리얼
  DWIN_SERIAL.begin(115200); // DWIN HMI 시리얼

  dht.begin();

  pinMode(Relay1, OUTPUT); 
  digitalWrite(Relay1,LOW);
}

void loop() {
  temp = dht.readTemperature();
  humid = dht.readHumidity();

  while (DWIN_SERIAL.available()) {
    relay_Switch();
  }

  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.println(" *C");

  Serial.print("Humidity: ");
  Serial.print(humid);
  Serial.println(" %");

  Serial.println();
  delay(1000);
  Data_Arduino_to_Display();
}

void Data_Arduino_to_Display() {
  delay(1000);
  int t = temp;
  int h = humid;

  Temperature[4] = temp_address;  // 주소 동적 설정
  Humidity[4] = hum_address;   // 주소 동적 설정

  // 데이터 유효성 검사
  if (isnan(t) || isnan(h)) {
    Serial.println("Invalid temperature or humidity data!");
    return;
  }

  /*------Send Data to Display------*/
  Temperature[6] = highByte((uint16_t)t); // 명시적 캐스팅
  Temperature[7] = lowByte((uint16_t)t);
  Humidity[6] = highByte((uint16_t)h); // 명시적 캐스팅
  Humidity[7] = lowByte((uint16_t)h);

  // 데이터 전송 및 확인
  Serial.print("Sending Temperature: ");
  for (int i = 0; i < 8; i++) {
    Serial.print(Temperature[i], HEX); Serial.print(" ");
  }
  Serial.println();

  if (DWIN_SERIAL.write(Temperature, 8) != 8) {
    Serial.println("Error sending temperature data!");
  } else {
    Serial.println("Temperature data sent successfully.");
  }

  Serial.print("Sending Humidity: ");
  for (int i = 0; i < 8; i++) {
    Serial.print(Humidity[i], HEX); Serial.print(" ");
  }
  Serial.println();

  if (DWIN_SERIAL.write(Humidity, 8) != 8) {
    Serial.println("Error sending humidity data!");
  } else {
    Serial.println("Humidity data sent successfully.");
  }

  delay(1000);
}

void relay_Switch() {
  if (DWIN_SERIAL.available()) {
    for (int i = 0; i <= 8; i++) {
      Buffer[i] = DWIN_SERIAL.read();
    }

    if (Buffer[0] == 0x5A) {
      switch (Buffer[4]) {
        case 0x54:   //for Relay1
          if (Buffer[8] == 1) {
            digitalWrite(Relay1, LOW);  // switch ON relay1 , loww enabled
            Serial.println("Relay1 ON");
          } else {
            digitalWrite(Relay1, HIGH);
            Serial.println("Relay1 OFF");            
          }
          break;

        default:
          Serial.println("No data..");
      }
    }
  }
  delay(1000);  //must include delay
}

이 코드를 이용해서 ESP32와 DHT11을 연결 DWIN HMI에 표시를 하려고하는데.
ESP32의 시리얼 모니터에는 data sent successfully 가 뜨는데
DWIN HMI에는 데이터가 표시 안되고있다.
HMI의 RX는 16핀에 TX는 17핀에 연결하였으며 반대로도 해봤다.
어떤점을 더 확인해봐야할까

포럼의 영어 섹션에서는 영어를 사용하세요.


Translation of opening post:

I'm trying to connect ESP32 and DHT11 using this code and display it on DWIN HMI.
ESP32's serial monitor says data sent successfully,
but DWIN HMI doesn't display the data.
I connected HMI's RX to pin 16 and TX to pin 17, and tried the opposite.
What else should I check?

Verify your ESP32 and DWIN TFT LCD use the same voltage level on the TX and RX.
Verify TX and RX on both devices are connected to the correct pin (TX to RX).
Verify all devices share a ground potential.

Show your wiring diagram.

Show what you have wired. Pin numbers are important.

1 Like

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