Differences
This shows you the differences between two versions of the page.
— |
hu:project:ard_esp_serial [2022/04/21 15:04] () |
||
---|---|---|---|
1: | 1: | ||
+ | ====== 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 === | ||
+ | <code c> | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | #define DHTTYPE DHT22 | ||
+ | #define DHTPIN 2 | ||
+ | |||
+ | |||
+ | DHT dht(DHTPIN, DHTTYPE); | ||
+ | SoftwareSerial Serial1(10, 11); // Rx, Tx | ||
+ | |||
+ | int temp,humi; | ||
+ | String str; | ||
+ | |||
+ | void setup(){ | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | void loop() | ||
+ | { | ||
+ | humi = dht.readHumidity()*100.0; | ||
+ | temp = dht.readTemperature()*100.0; | ||
+ | delay(200); | ||
+ | Serial.print(" | ||
+ | Serial.print(humi); | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(temp); | ||
+ | Serial.println(" | ||
+ | str =String(' | ||
+ | Serial1.println(str); | ||
+ | delay(5000); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === nodeMCU Kód === | ||
+ | <code c> | ||
+ | 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()); | ||
+ | } | ||
+ | } | ||
+ | </ |