With all due respect, the comment / header files you’ve posted are totalling 31,474 characters in total for your explanations. I doubt someone will fully read that to try and reproduce the problem, along with the sketches which have circa 1000 lines of code. That’s the wrong approach. Let’s try and get to the bottom of the problem more easily.
Indeed PlatformIO has easy debugging capabilities – for certain platforms. PlatformIO does currently not support live-debugging of a real AVR target CPU, which your Arduino Mega 2560 has. Live-debugging is available for other core types like ARM cores (STM32, nRF51, nRF52, Atmel SAM, NXP, …), XTensa cores (ESP32) or RISC-V cores.
However, PlatformIO has recently added support for using an AVR simulator (refer Atmel AVR dev/platform v2.1.0: new boards, AVR simulator, updated Arduino cores). But again with this simulator you would have to also simulate the PSX input, which isn’t really feasable in your specific case.
The Atom PlatformIO plugin is not recommended anymore, VSCode should be used instead – refer PlatformIO IDE — PlatformIO latest documentation.
Anyway, let’s focus on the real problem here.
Instead of pushing more code in a complicated 500 line sketch, start with the absolute minimal example of what you want to achieve.
It seems to me that you’re tyring to use the EasyTransfer library in order to send and receive messages (bidirectionally) between your two Arduinos via their Serial1
interfaces.
So you should first test the library’s minimal sketch for a transmitter and receiver. These are located in Arduino-EasyTransfer/EasyTransfer/examples at master · madsci1016/Arduino-EasyTransfer · GitHub in the folders EasyTransfer_RX_Example
and EasyTransfer_TX_Example
.
These examples make the transmitter (TX) choose a new random value every 5 seconds which describes the number of times (and delay) the onboard LED (13) should be blinked. The receivers should receive that message and do the same.
You can take that code and change all Serial
occurences to Serial1
so that you have your target hardware layout. Double check that the Serial TX of one board goes to the RX of the other board and vice-versa, and that common GND is established (TX->RX, RX->TX, GND->GND). See the pinout. Then see if the sketch works or add additional debugging (Serial.println(...)
) at some interesting places or for certain variables. Work on the code or ask questions until the first minimal example works succesfully.
Also you should think about modularizing your code. Your first sketch has two functions – setup()
and loop()
, and in those you do at least 5 different tasks (reading gamepad, preparing transmission data, reading sensors, reacting on sensor data, receing data, …). That is considered bad code practice. Not only can you use different functions to split the work but also use different files or C++ classes. Both Arduino IDE and PlatformIO support splitting code over multiple files.