I want to connect this to a Mega2560 board, which handles a bunch of sensors, possibly using a serial port. I'm at the very beginning with this idea (not a project yet) and I never used the ESP32-CAM before. I tested it stand-alone with the classic WEB app and it works quite well; I can see the video and configure it on my PC through the internal WiFi network (although the image quality is not what expected).
Now, I have 3 questions:
how can I power the ESP, without the USB cable, since there is not any connector available on both boards?
can I use the U0TXD and U0RXD to communicate with the Mega? I doubt it since I presume those pins are also used by the piggyback board.
is there any other pin available on the ESP? From this picture, it seems not (if the orange ones are dedicated to the onboard hardware):
I understand (maybe) that I could use the piggyback to only program the ESP and then detach it, but...and it will not solve the above point 3, anyway, right?
Thanks
the ESP32-CAM code using hardware serial port Serial1 using GPIO14 and 15
// 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);
}
}
and the Mega code using hardware Serial1 port on pins 18 and 19
// Arduino Mega serial1 test
// mega Serial1 pin 18 is Tx
// Serial1 pin 19 is Rx
// for loopback test connect pin 18 to pin 19
// for RS232 shield connect pin 18 to Tx and pin 19 to Rx
// for loopback test connect 9 pin D connector pins 2 and 3
// connect GND pins together
void setup() {
Serial.begin(115200); // initialise serial monitor port
Serial1.begin(115200); // initialise Serial1
Serial.write("Arduino Mega Serial1 test - for loopback test connect pin 18 to pin 19\n");
}
void loop() {
if (Serial1.available()) { // read from Serial1 output to Serial
Serial.write(Serial1.read());
}
if (Serial.available()) { // read from Serial outut to Serial1
char inByte = Serial.read();
//Serial.write(inByte); // local echo if required
Serial1.write(inByte);
}
}
how many sensors do you have on the Mega and what interfaces do they use? e.g. analogue, I2C, SPI, etc
could the ESP32 interface to the sensors simplifing the whole project?
I tend to say on the ESP's RX-line, that way when the TX & RX lines are swapped (for direct communication) it is still on the correct line.
You can actually assign any of the GPIO to be used by any of the UART's on an ESP32, and you can also do away with the piggy-back all together and program the ESP32 Thru the Mega. Even using a Serial-passthrough (full-duplex) it can be done, though you would have to set the upload speed to something that is supported by the Mega (921600 isn't i think, 115200 is the safest, AVR's support up to 1Mbps, but the speed is set as part of the MCU clockspeed which is 16MHz.
Thanks for your code about a sw serial, but actually my question/s is/are different.
I bought this module right to not have to attach/detach a USB/UART module every time I must program the ESP. Unfortunately this does not leave any pin available for something else.
For the power, I have both 3.3 and 5V from the MEGA, but where could I connect this voltage? I mean, the UART auxiliary board has it own regulator which takes the 5V from the USB connector; when I do not connect any USB cable I have not other point to attach; I could solder two wire onto the ESP module, but it will still be connected to the other board and I'm not sure this is something correct.
Regarding your example to use the hardware serial port Serial1 on GPIO14 and 15, does it mean that these pins are freely available? The fact that they are marked in orange as HS2-something made me think they are reserved.
For your info I do not use/need the SD card and the Mega is required since I have to handle several peripheral (I2C, SPI, dedicate pins for servos and displays), to many for any other MCU.
the esp32-cam-ai-thinker-pinout states You can power the ESP32-CAM through the 3.3V or 5V pins. However, many people reported errors when powering the ESP32-CAM with 3.3V, so we always advise to power the ESP32-CAM through the 5V pin.
the HS2 pins are SPI and used for the SD so if you are not using them they may be used as normal IO
unless you are very good at soldering I would not recommend soldering wires on to the ESP32-CAM pins
plug the ESP32-CAM or the piggy-back module into a Solderless Prototype Breadboard, e.g.
I did several MSOP soldering, so I do not have any problems with that.
The point is that if I do not disconnect the below module, the 5V will go to its circuit; I do not know exactly where, but possibly at the voltage regulator output that will be then reverse biased. I should need 2 or 3 welds for the other signals too.
Then there is a practical and aesthetic issue; I will have a bunch of flying wires (gnd, +5, tx, rx, a possible other pin) ; at the end, quite a mess.
Sure, I could accept a flying 6 pin dupont (or similar) connector, but it is not a wonder.
That is a possible issue. But not only do some regulators allow for that, there may be some diodes in place to prevent issues. You need the schematic to know what is what. You can power an ESP32 devkit thru either the 5v or the 3.3v pin. Those boards have similar regulators on board.
I tend to build an adapter on a bit of experimentation board, and solder female header pins onto that and make connectors to connect boards.
I don't like dupont flying wires either - OK for quick prototyping but give rise to poor connections and intermittent problems
one can get Prototype screw terminal boards for the Mega etc which can give a more reliable connection
for large numbers of devices goto custom PCBs
The origin of this confusione comes directly from the ESP32-CAM module that is, it's just my poor opinion, bad engineered. It would have been quite easy to provide a connector for, at least, the 4 needful pins (+,-,tx,rx) and a jumper to short IO0 to ground. Said that, the piggy-back module is even worst. No schematics and all then pins connected between the boards (really or just to have a unique female connector?) which possibly prevent to use the pin themselves.
When I started to think about using this CAM module I saw all the example about the programming method and I thought that it is quite stupid to have an external signal converter (that I do not have, yet), attach 4 flying wires, make a shoring jumper any time a new upload is required. From this the idea to buy this combo which make it easier, at least at the very beginning; I did not think enough to the follow up.
Now, since I can not, unfortunately, change the ESP, I'm now trying to figure out a different approach which is: buy a FTDI-USB module and hack it a little (?) to take only the needed signals and make an auxiliary PCB to provide the connector (a nice JST), the programming jumper (or switch) and a switch (or just a schottky diode) to avoid the power issue...maybe it will a mess, but...I will sleep tonight and tomorrow I'll see.
'night
But there are OTA updates on an ESP !! seriously if you make OTA updates part of your sketch once(and every sketch you upload after that) you can upload Over The Air without issue straight from the IDE or use HTML uploads for updates at a distance when the IDE is not available or the ESP is being used as an Access Point.