Hello,
I am doing a project to control the Arduino robot from Matlab through esp32 cam. But now I am having a problem in communication from ESP32 cam to Arduino mega.
This code of ESP32 cam is used to connect to wifi, receive a signal from Matlab, and output signal to serial (On ESP32 cam, the communication port is pin 3 (RX) and pin 1 (TX))
This code of Arduino Mega 2560 is used to receive signals from the ESP32 cam and control the motors (There is a rather long paragraph below but it is not important).
I tried connecting, and it connected to wifi, received a signal from Matlab, and wrote out serial, but Arduino seems to have not received a signal from esp32 cam to control the motors.
Hope everyone can help me.
PS: For some reason, I have to use ESP32 CAM instead of ESP32 or ESP8266
Awww dude! ESP32 CAM is a 3.3V device and is 5V intolerant. A Mega is a 5V device. Did you use logic level shifters?
And dude software serial on an ESP32, it just does not work very well when, the ESP32 has 3 different Serial Ports (UART). You can just use one of them. Also, software serial does not work very well at 115200.
Serial0: RX0 on GPIO3, TX0 on GPIO1
Serial1: RX1 on GPIO9, TX1 on GPIO10 (+CTS1 and RTS1)
Serial2: RX2 on GPIO16, TX2 on GPIO17 (+CTS2 and RTS2)
Here OP wants the 3 blinks in case a client connects - so part of the loop.
The while(1) is meant to handle the case where you've exhausted the client.available() data because you read the buffer faster than the data was incoming, yet you don't want to go blink again. Once the client is done and has closed the connection, the Myserver.hasClient() test will allow to return to the main loop and wait for a new client.
The while could be while(Myserver.hasClient()) though and I would had a yield() somewhere in there just to pat the dog.
My question is that the while loop will not exit the way it is wrote. loop() is already in a while loop, so why nest a while in a while when it's not necessary and causes the rest of the code in loop() to not ever run again.
not sure what you mean. and if you don't loop, you'll get the blinking again because the client is still connected.
the code of the loop in plain English is:
LOOP
if there is an incoming client
blink 3 times
as long as the client is connected, send the incoming data to the Serial line
the while(1) is there to represent this as long as the client is connected
The LOOP is there to handle the next client.
sure you could use the loop to feed the serial line, but you would need an extra test to not blink again
The ESP32 has 4 hardware serial ports. Hardware serial is faster.
And I say poo! that your ESP32 code is working. SoftwareSerial mySerial(3,1); on an ESP32 GPIO_NUM_1 and GPIO_NUM3 are the serial programming port pins. Using the programing port pins of the ESP32 as serial pins will create issues. Of course the simulator does not know about the programming port and that the ESP32 does not work well with softwareserial.