[SOLVED] Is the TX pin on my Nextion broken, or what did I do wrong?

Hello!
I'm pretty much lost on this.
I have checked the send component ID box in the Nextion builder, but it seems like it isn't sending anything. The RX led should blink up on the Arduino.
I have measured conductivity pretty much from the processor of the Nextion to the processor on the Arduino UNO I'm using. All fine. When I send data on USB, the RX LED works as well.
I don't think it's a problem with my Arduino sketch, as it will not work if it doesn't receive data at all :stuck_out_tongue:
I have surely checked the ID send boxes in Nextion builder, and on the debugger, it's sending them fine; not in real life tho.
On top of all that, a few months ago I successfully tested sending button press events from the Nextion, and back then it worked.
I have no idea what the issue could be. Do you?
If I would need to give anything (nextion project, ardu sketch, or else), please tell me, I didn't do it in advance because I think this isn't an issue with my code. Is this maybe a known problem?

Here's an unhelpful video demonstration.
How could I debug this? Of course, I don't expect anybody to have a complete solution to my vague problem description...
The TX is flashing on my board because it's updating a displayed text for testing. So sending data works fine.
Edit: Now I have tested it with another Arduino board. Same issue. Has to be the Nextion...
Edit 2: I have tried it with a 3rd board of a different brand (still an arduino uno, just another chineese knockoff :D), and the RX still doesn't signal, but on this, there is an LED labelled X1, which does indeed blink for the button presses. Weird. I will try my code on this board, just a moment.
Edit 3: On this board, now sending doesn't work either, the number is not updating anymore. In the meantime I noticed there being no TX led at all, and the periodic data sends to board is doing show up on the RX pin, and as I wrote before, receiving data lights up the so labelled X1 led... While uploading, same thing, first RX lights up, than X1. I have a Mega too, I will try it with that too XD :stuck_out_tongue:

Hello Redy Gold.

Please can you post your Arduino code in code tags, attach your HMI file and maybe some photos of what you have and I'll take a look. However, be aware that if you've used Nextion libraries I won't be much help as I don't use them. You could also try using the code I put in 'Using Nextion displays with Arduino' as a test.

Well, here they are; this is the beginning of a bigger project, hence the commented out includes.

#include <Nextion.h>
//#include <DHT.h>
//#include <Ethernet.h>
//#include <Blynk.h>
//#include <SoftwareSerial.h>
#include <AltSoftSerial.h>

AltSoftSerial vizrendszer; //Initialize 2nd serial for communication with the Water System
//SoftwareSerial hifi; //Initialize 3rd serial for comm. with HiFi system.

float setTemp = 22.50; //means 22,0 C
bool isCooling = false;

//= <type of object>(<page id>, <object id>, "<object name>");

//Home page
NexButton setTempMinus = NexButton(1, 26, "setTempMinus");
NexButton setTempPlus = NexButton(1, 27, "setTempPlus");

//Quickmenu
NexButton allStopButton = NexButton(2, 4, "allStopButton");
NexButton coolingButton = NexButton(2, 1, "coolingButton");

NexTouch *nex_listen_list[] = {
  &setTempMinus,
  &setTempPlus,

  &allStopButton,
  &coolingButton,
  NULL
};

//Touch Events

void setTempMinusPush(void *ptr) {
  setTemp = setTemp - 5;
  setTempPrint();
}
void setTempPlusPush(void *ptr) {
  setTemp = setTemp + 5;
  setTempPrint();
}
void allStopButtonPush(void *ptr) {
  vizrendszer.print("allStop");
}
void coolingButtonPush(void *ptr) {
  if (isCooling) vizrendszer.print("cooling 0");
  else vizrendszer.print("cooling 1");
}



void setup() {
  Serial.begin(9600); //Initialize Nextion communication on 115200 baud.
  delay(500);
  Serial.print("baud=115200");
  nexEnd();
  Serial.end();
  Serial.begin(115200);
  
  setTempMinus.attachPush(setTempMinusPush);
  setTempPlus.attachPush(setTempPlusPush);
  allStopButton.attachPush(allStopButtonPush);
  coolingButton.attachPush(coolingButtonPush);
  
  vizrendszer.begin(9600);

  setTempPrint();
}

void loop() {
  // put your main code here, to run repeatedly:
  setTempPrint();
  delay(500);
  setTemp = setTemp + 0.1; //Test screen update
}

void nexEnd() {
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

void setTempPrint() {
  Serial.print("setTemp.txt=\"");
  Serial.print(setTemp,1);
  Serial.print("\"");
  nexEnd();
}

Couldn’t attach the .hmi here, so here’s a download link: http://minefoxcraft.dyndns.hu/Rejtett%20megosztás/FodorHOMEv0.1.HMI
Edit: Not working with my Mega either. Noticed a few things tho: It it normal for serial pins to measure as shorted (multimeter beeps) while sending data?
Also, because the Chinese board lit up the X1 LED (whatever that means) when I pressed a button, I can be sure the screen is sending something… Maybe this is a very straight forward thing and I’m just dumb. Would be nice. I’ll try this with a sample project on both my ardu and nextion, maybe it really is the code. I will try yours.

Thank you. Do you have a photo and a digram of how you have wired it up?

I see you are using the Nexion libraries, that limits how much I can help as I don't use them or know much about them, sorry.

This concerns me:

I have checked the send component ID box in the Nextion builder, but it seems like it isn't sending anything. The RX led should blink up on the Arduino.
I have measured conductivity pretty much from the processor of the Nextion to the processor on the Arduino UNO I'm using. All fine. When I send data on USB, the RX LED works as well.

As far as I know the RX and TX LEDs are only associated with the USB connection to your computer, not with any other serial port, so I would not expect to see the RX LED flashing in response to data from the Nextion.

 Serial.begin(9600); //Initialize Nextion communication on 115200 baud.

That's the serial port that communicates with you PC for uploading your program to the Arduino, and for the serial monitor, you can't use it for the Nextion, you need a spare serial port for the Nextion.

void setTempMinusPush(void *ptr)

You are defining variables to be passed to a function as void, they need to be defined as an appropriate variable type such as int or char or whatever they need to be.

You have indeed ticked 'send component ID' on, for example, the button 'setTempPlus', however, I believe you are expecting it to send ''setTempPlus 0xff 0xff 0xff'. If you look in the debug simulator you will see it actually sends 65 01 1B 01 FF FF FF, which I can't make any sense of. AFAIK 'send component ID' sends whatever is in 'id', it does not send 'objname', which is what I think you are expecting it to send. However, as it's not sending 27, I don't know what it is sending.

With respect, I think you are trying to run before you can walk as there are several basic problems here. I probably have not spotted all of them, in fact I'd be surprised if I have. I suggest you go to something simpler as a test, either my tutorial or some simple code that just sends a button press and repeats it to the serial monitor, then build from there. I also strongly suggest you abandon the Nextion libraries, in my opinion they don't work very well, and having been on this site for some time, I have yet to see anyone here who knows enough about them to be helpful.

I hope somewhere in the above is something that helps you.

Right, sorry.
65 01 1A 01 means 26
65 01 1B 01 means 27

0x1A is hex for 26
0x1B is hex for 27

That's what it sends.

Yes, I totally agree. I thought I could do this, because I could achieve both ways of communications before following tutorials.
I read your way of sending data, and I like it way more than this library they provide, I will rewrite the code with that in mind.

you need a spare serial port

As far as I know, it's enough to pull the Nextion out while uploading. At least I saw someone do it in a tutorial.

RX and TX LEDs are only associated with the USB connection to your computer

I was just experimenting with serial comms between to UNOs, and the RX and TX leds indeed light up, not only for USB.

You are defining variables to be passed to a function as void

I saw it like that in a tutorial. In theory those push callbacks should be attached to the library, but I will not mess further with that.

Thanks for your time and answer! I will experiment further and post here if I succeed or get stuck again :slight_smile:

Who would have thought? With your examples, it works fine :smiley:
Although I found a line of code that was messing it up, I commented it out. Why was that there?

void HMI_display_clock() {
  char timestring[9];
  sprintf(timestring, "%02d:%02d:%02d ", clock.hour, clock.minute, clock.second);
  //Serial.println(timestring);
  Serial.print(F("t1.txt=\""));
  Serial.print(timestring);
  Serial.print("\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

Anyway, all that's left is to implement this to my own use. Thank you again, and also for your tutorial!

P.s.
RX really does not light up for nextion, so after all it was my code (which I never thought would work as is, I just thought that at least the LED should blink.)
Also, normal serial works fine even while being plugged into USB. It even lets me peek into whats being sent to Nextion.

Code: [Select]

void setTempMinusPush(void *ptr)

You are defining variables to be passed to a function as void, they need to be defined as an appropriate variable type such as int or char or whatever they need to be.

I asked a friend who knows a lot more about programming than I do and he says I got that bit wrong; pointers can be void, so that line of code is valid. Apologies for the mistake.

However:

void setTempMinusPush(void *ptr) {
  setTemp = setTemp - 5;
  setTempPrint();
}

In that you define the pointer then never use it.

RedyAu:
Who would have thought? With your examples, it works fine :smiley:
Although I found a line of code that was messing it up, I commented it out. Why was that there?

void HMI_display_clock() {

char timestring[9];
 sprintf(timestring, "%02d:%02d:%02d ", clock.hour, clock.minute, clock.second);
 //Serial.println(timestring);
 Serial.print(F("t1.txt=""));
 Serial.print(timestring);
 Serial.print(""");
 Serial.write(0xff);
 Serial.write(0xff);
 Serial.write(0xff);
}



Anyway, all that's left is to implement this to my own use. Thank you again, and also for your tutorial!

P.s.
RX really does not light up for nextion, so after all it was my code (which I never thought would work as is, I just thought that at least the LED should blink.)
Also, normal serial works fine even while being plugged into USB. It even lets me peek into whats being sent to Nextion.

My original code from the tutorial is:

void HMI_display_clock() {
  char timestring[9];
  sprintf(timestring, "%02d:%02d:%02d ", clock.hour, clock.minute, clock.second);
  Serial.println(timestring);
  Serial1.print(F("t1.txt=\""));
  Serial1.print(timestring);
  Serial1.print("\"");
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
}

The line

Serial.println(timestring);

Prints to the serial monitor so you can see what is going on. The other prints are to Serial1.print(), which is the serial port I had the Nextion display on, which is a different port. If you are using the same port for your Nextion as you are using for the serial monitor then that line would probably cause a problem. In the tutorial I have said that the Nextion needs its own serial port. I still think you are being unwise trying to share 1 serial port with 2 devices, and I think that eventually you will have a problem of some kind as a result.

It even lets me peek into what's being sent to Nextion.

Which is what prints to Serial.print() are for in my code.

Anyway, I am glad you are making progress, I am pleased to have helped you.

I see now! I replaced all Serial1-s with Serials automagically, but that was used for debugging. All clear then!
I only have it plugged into USB and thus monitoring serial while programming, it will not operate like that in the end.
Unfortunately neither can the Nextion nor can I use Software serial for debugging, and UNO only has one port, so I can't do anything about the conflict... That said, this might only apply to the official library, your way might work with SWSerial (or with AltSoftSerial, that's what I'm going to use). I'll try it!
Edit: It works perfectly! No conflict anymore.

I asked a friend who knows a lot more about programming than I do and he says I got that bit wrong; pointers can be void, so that line of code is valid.

Well, that's good to know, although you (of course) know a lot more about programming than me too (not to mention your friend), I just copied the line from a tutorial :stuck_out_tongue: I didn't even know about pointers. I will read up on them.

Unfortunately neither can the Nextion nor can I use Software serial for debugging.

While I have not personally tried it I know other people on here who have asked me for advice have used software serial for a Nextion without any problems.

EDIT:
I just read this:

Edit: It works perfectly! No conflict any more.