Arduino nodeMCU soros kommunikáció

Az Arduino UNO egy DHT22 szenzort olvas, és írja át az adatokat a soros porton a nodeMCU-nak.

Arduino - nodeMCU pinek:

  • DHT22 input: pin 2
  • Serial Tx: Pin 10 → nodeMCU Rx
  • Serial Rx: Pin 11 → nodeMCU Tx

Arduino Kód

#include "DHT.h"
#include "SoftwareSerial.h"
 
#define DHTTYPE DHT22
#define DHTPIN 2
 
 
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial Serial1(10, 11); // Rx, Tx
 
int temp,humi;
String str;
 
void setup(){
 
 Serial.begin(115200);
 Serial1.begin(115200);
 dht.begin();
 delay(2000);
}
void loop()
{
  humi = dht.readHumidity()*100.0;
  temp = dht.readTemperature()*100.0;
  delay(200);
  Serial.print("H: ");
  Serial.print(humi); 
  Serial.print("% ");
  Serial.print(" T: ");
  Serial.print(temp); 
  Serial.println("C");
  str =String('H')+String(humi)+String('T')+String(temp);
  Serial1.println(str);
  delay(5000);
}

nodeMCU Kód

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}
 
void loop() { // run over and over
  if (Serial.available()) {
    Serial.write(Serial.read());
  }
}