My apologies if this is a non-problem and I'm just being totally thick... saying that, I'm stuck and need some assistance.
I have a two Mega2560's, an original Arduino and the other is an Elegoo. Both exhibit the same issue when sending commands to my Nextion 3.5" Enhanced screen.
If connected to Serial everything works great, I receive events from the screen and can send to the screen. However, if I simply change the port used to Serial1, Serial2 or Serial3, and switching the cables to the respective connections, data sent to the screen does not work. Interesting note is that receiving from the screen continues to work, only the sending to the screen doesn't.
As a very simple test setup until I resolve this, I've got the Mega2560, the screen and a button on a breadboard. The button when pressed sends text to "t0".
I can't see any way of adding an image to this post! In the help, there is clearly an image icon in the toolbar, but that is not on the toolbar now. If someone can tell me how, I'll edit the post and add it.
And the code is:
#define NEXTION Serial1
#define NEXTION_SPEED 9600
const int buttonPin = 2;
int buttonState = 0;
int oldButtonState = 0;
int counter = 0;
void sendText(String text) {
NEXTION.print(text);
NEXTION.write(0xff);
NEXTION.write(0xff);
NEXTION.write(0xff);
}
void setup() {
//Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
NEXTION.begin(NEXTION_SPEED);
sendText("");
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != oldButtonState) {
oldButtonState = buttonState;
if (buttonState == HIGH) {
counter += 1;
sendText("t0.txt=\"hello" + String(counter) + "\"");
}
}
}
The NEXTION definition makes it easier to switch between serial ports, but I have actually placed Serial1,2,3 in the code where I'm sending/receiving to/from the screen so it's not that.
I make no other change other than switching to a different serial port. On Serial it works, and on any of the other ports it does not.
I'm literally pulling my hair out here as I cannot for the life of me get a handle on why ports 1, 2 or 3 do not work. I must be missing something really obvious.
Thank you in advance for any help you can provide.