start:esp32:uart
Ceci est une ancienne révision du document !
Table des matières
Connexion de 2 esp32 via Uart
Liaison UART entre 2 esp32 :
le schéma:
ESPMaster | ESPSlave |
---|---|
br 17 TX2 | br 16 RX2 |
br 16 RX2 | br 17 TX2 |
GND (A cote 5V) | GND (A cote 5V) |
br 15 LED verte | |
GND ( A cote P23) |
- Programme_Master.ino
#include <HardwareSerial.h> HardwareSerial SerialPort(2); // use UART2 void setup() { SerialPort.begin(15200, SERIAL_8N1, 16, 17); } void loop() { SerialPort.print(1); delay(5000); SerialPort.print(0); delay(5000); }
- Programme_Slave.ino
#include <HardwareSerial.h> HardwareSerial SerialPort(2); // use UART2 char number = ' '; int LED = 15; void setup() { Serial.begin(9600); SerialPort.begin(15200, SERIAL_8N1, 16, 17); pinMode(LED, OUTPUT); } void loop() { if (SerialPort.available()) { char number = SerialPort.read(); if (number == '0') { digitalWrite(LED, LOW); Serial.print("0"); /* verification reception 0 */ } if (number == '1') { digitalWrite(LED, HIGH); Serial.print("1"); /* verification reception 1 */ } } }
NOTA important :
BRANCHER les ESP32 sur des PC ou des alimentations différentes , branché sur la même alimentation cela ne fonctionne pas…. ????
j ai essayé à 115200 Bauds : cela fonctionne aussi
J ai essayé 1 secondes pour le “delay” sur l'esp32 master : cela fonctionne .
/home/chanteri/www/fablab37110/data/attic/start/esp32/uart.1728310765.txt.gz · Dernière modification : 2024/10/07 16:19 de gerardadmin