I am automating an industrial process, it's very specific and relatively simple (some relays, some actuators... basically ON/OFF signals) so I am using a microcontroller instead of a PLC. At the moment I am using an ESP32, which has the added benefit of submitting sensor data to a cloud server. For added safety, I also use a industrial PID controller so that the ON/OFF signals need both the ESP and the PID to agree. It works fine but I'd like to add more outputs and possibly inputs.
This was the first time I built anything related to ESPs and IoT, and the ESP32 has truly been a great platform to work with. However, compared to say an Arduino Mega it has it's limitations. Initially I didn't care, because there were not many things to control, however the project was not as successful as I wanted and I will need to add more output signals. This upgrade will require more I/O pins, and the Arduino Mega feels like the logical choice.
What would you recommend so that I can control the system with the MEGA but still output sensor data to my cloud server?
I initially thought of coupling the Arduino with the ESP through serial communication. However in the small number of tests I've done the communication is not reliable. For example I did the typical 5V voltmeter using the Mega and a potentiometer, sending data through serial to the ESP. This was just to test the idea and the ESP received a lot of crazy values and was not very responsive.
I was also considering one of those Arduinos that have an ESP8266 module in the board, like this one: https://robotdyn.com/mega-wifi-r3-atmega2560-esp8266-flash-32mb-usb-ttl-ch340g-micro-usb.html
I also thought about using other communication methods, like I2C or SPI. I even thought of sending the data as bit code through digital pins haha (Ben Eater has a great video on that). But I would like to hear recommendations, because I feel I am overthinking this and there are some simple solutions out there.