The issue you're experiencing with the M5StamPLC.begin() function interfering with Serial1 is likely due to the library initializing or reconfiguring the hardware UART pins used by Serial1. Here's how you can resolve it:
Solution:
Check Pin Mapping:
Ensure that the pins you're using for Serial1 (RX_PIN and TX_PIN) are not being reconfigured by the M5StamPLC.begin() function. The M5StamPLC library might initialize its own UART or other peripherals on the same pins.
Explicitly Reinitialize Serial1 After M5StamPLC.begin():
Call Serial1.begin() again after M5StamPLC.begin() to ensure the UART settings are restored:void setup() {
M5StamPLC.begin();
Serial1.begin(38400, SERIAL_8N1, RX_PIN, TX_PIN);
}
Use Alternative UART Pins:
If the issue persists, try using a different UART (e.g., Serial2) if your hardware supports it. For example:Serial2.begin(38400, SERIAL_8N1, RX_PIN_2, TX_PIN_2);
Review M5StamPLC Library Documentation:
The M5StamPLC library might have specific requirements or conflicts with certain pins. Refer to the official documentation for details.
Debugging:
Add debug prints to verify if Serial1 is being initialized correctly:void setup() {
Serial.begin(115200); // For debugging
M5StamPLC.begin();
Serial1.begin(38400, SERIAL_8N1, RX_PIN, TX_PIN);
Serial.println("Serial1 initialized");
}
Additional Notes:
If the problem is related to the M5StamPLC library's internal UART configuration, you may need to modify the library or contact M5Stack support (support@m5stack.com) for further assistance.