We're supposed to automatically know what those pins are?
With ESP32, it is especially important to consult the extended documentation on pin functions and configuration. It's way more complex than on the AVR.
To make matters worse, the assignment of ESP pins to board pins has never followed any standard, it's all over the map.
I have connected an ESP-WROOM-32to an ESP-CAM using serial
ESP32 code
// ESP32 Serial1 test
// for loopback test connect pins 14 and 15
#define RXD1 14
#define TXD1 15
void setup() {
// initialize both serial ports:
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);
Serial.println();
Serial.println("serial1 test Rx pin 14 Tx pin 15");
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
//Serial.write(inByte);
Serial1.write(inByte);
}
}
ESP-CAM code
// ESP32-CAM Serial1 test
// for loopback test connect pins 14 and 15
#define RXD1 14
#define TXD1 15
void setup() {
// initialize both serial ports:
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);
Serial.println();
Serial.println("serial1 test Rx pin 14 Tx pin 15");
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
//Serial.write(inByte);
Serial1.write(inByte);
}
}
interconnected pins 14 and 15 on both board and transmitted text between them OK
But, on ESP32 I did the same loopback test shorting 16 with 17 and it didn't work.
I decided to use 16 and 17 as they are the pins I will use when expanding the code to include more function.
In this way I used the hardwareSerial mySerial(2).
Does it need to have some library to use the Serial hardware ?
I have already measured the short between 16 and 17 with a multimeter and the COM port is correct.
But what I type does not return.
// ESP32 mySerial test
// for loopback test connect pins 16 and 17
HardwareSerial mySerial(2);
void setup() {
// initialize both serial ports:
Serial.begin(115200);
mySerial.begin(9600, SERIAL_8N1, 17, 16);
Serial.println();
Serial.println("mySerial test Rx pin 16 Tx pin 17");
}
void loop() {
// read from port 1, send to port 0:
if (mySerial.available()) {
int inByte = mySerial.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (mySerial.available()) {
int inByte = Serial.read();
//Serial.write(inByte);
mySerial.write(inByte);
}
}
If the ESPCAM is far from the ESP32, up to how many meters can I get a secure communication, without corrupting the data, connecting only with 4 wires (3.3 v, GND, RX, TX) ?
depends on the cable used (use screened cable) and the electrical noise in the environment
typical several metres is OK
if you require tens of metres use RS252 shields to boost the line voltages