Go Down

Topic: Nextion screen problem with DUE (Read 2724 times) previous topic - next topic

flopes

Hi everyone,

I am changing from Mega to Due and I am having some problems with my nextion touch screens. Apparently the due does not like this line of code:
Code: [Select]
Nextion myNextion(Serial3, 9600); //TOUCH A ---> TX to pin 18 and RX to pin 19

here is the code I am testing:

Code: [Select]

#include <Nextion.h>

Nextion myNextion(Serial3, 9600); //TOUCH A ---> TX to pin 18 and RX to pin 19

char rx_message_A[25];

void setup() {

   Serial.begin(9600);
   delay(100);
   pinMode(22, OUTPUT);         
   pinMode(24, OUTPUT);         
   delay(1000);
   Serial3.begin(9600);   //TOUCH A
   delay(100);
   myNextion.init();
   delay(2000);
}

void loop() {

   myNextion.listen().toCharArray(rx_message_A, 25);
   Serial.print(rx_message_A);
   
   
   digitalWrite(22, LOW);
   delay(1000);              // wait for a second
   digitalWrite(24, LOW);
   delay(1000);              // wait for a second
   digitalWrite(22, HIGH);
   delay(1000);              // wait for a second
   digitalWrite(24, HIGH);
   delay(1000);
 
}


The result of this code is that nothing works. The relays do not work and the same with the touch screen, I dont even see anything on the monitor.

I am using external 5V power supply to feed the Nextion display and I use common ground with the arduino due.

This code works fine on the Arduino Mega, the relays blink and I see the messages when I press the buttons on the touch screen.

Any ideas please?

dlloyd

Here's the link to the Nextion library. It uses software serial, so you'll need make some modifications to use hardware serial (refer to the link). Not sure if there would be other software compatibility issues.

Your touchscreen is 5V so you'll need to level shift or voltage divide to 3.3V for the Due's RX input. I think the Due's TX could be directly connected to the touchscreen. Check the touchscreen datasheet to see if 3.3V is high enough for the touchscreen to recognize this as high.


flopes

Hi

thanks for the reply.

The code I sent you above is working pretty well on arduino Mega using HARDWARE SERIAL.


The MCU on the back of the Nextion is a 3.3V chip (STM32F030C8T6 powered after the 3.3V regulator) so this is why I dont understand why it does not work.

The only difference between the MEGA and the DUE I can see on the serial pins is that on the MEGA all serial pins are 5V TTL and on the DUE pins 0 and 1 are 5V and the other 3 are 3V TTL.

dlloyd

#3
Sep 26, 2016, 02:40 pm Last Edit: Sep 26, 2016, 09:27 pm by dlloyd
Just noticed you should be using Serial2 for pins 18 and 19...
Code: [Select]
Nextion myNextion(Serial2, 9600); //TOUCH A ---> TX to pin 18 and RX to pin 19

Note that on the Due, pins 0 and 1 are 3.3V ... pin0 (RX0) has already been level shifted to 3.3V using a single bus buffer.

EDIT: Oops ... should be
Code: [Select]
Nextion myNextion(Serial1, 9600); //TOUCH A ---> TX to pin 18 and RX to pin 19

flopes

Just noticed you should be using Serial2 for pins 18 and 19...
Code: [Select]
Nextion myNextion(Serial2, 9600); //TOUCH A ---> TX to pin 18 and RX to pin 19

Actually that is only comment because I am using 2 touch screens one on SERIAL1 and the other on SERIAL2

Note that on the Due, pins 0 and 1 are 3.3V ... pin0 (RX0) has already been level shifted to 3.3V using a single bus buffer.
This is why I dont understand why it does not work. I only get  "e ÿÿÿ" instead of for exemple 65 0 4 1 ffff ffff ffff

On pins 0 and 1 I get this rubbish e ÿÿÿ and on the other serials nothing at all, the TX/RX LEDs on the DUE dont even blink when I press a button on the touchscreen.

Any other ideas?

dlloyd

OK, I wouldn't use pins 0 and 1 with a touchscreen as that's used for programming. Here's the hardware serial port pinouts:

Name      RX  SAM3X Pin    TX  SAM3X Pin   Description
Serial    RX0  URXD   0    TX0  UTXD   1   Connected to ATmega16U2, serial programming, serial monitor
Serial1   RX1  RXD0   19   TX1  TXD0  18   USART0, Touchscreen A?
Serial2   RX2  RXD1   17   TX2  TXD1  16   USART1, Touchscreen B?
-------   ---  RXD2   52   ---  TXD2  65   USART2, UNSUPPORTED
Serial3   RX3  RXD3   15   TX3  TXD3  14   USART3, ?
SerialUSB ---  ----   --   ---  ----  --   Native USB Port

Its a bit convoluted ... please re-check your connections?

flopes

Connections are exactly the same as in Arduino MEGA. I ordered another DUE because I do not find anything that could not make it work...

I am still thinking about the touchscreen properties, check the attachment pse.

flopes

Ok, so some eveolution here.

I have another device which comunicates in RS232 and so I used a MAX232 to interface between my device and the DUE and it works, I get the respective data in the monitor using the DUE.

So why the hell the nextion touch would not work???

flopes

I am still struggling with arduino due serial coms... I sent an email to ITEAD the fabricant of NEXTION displays, and basically they said we tried with UNO and MEGA and we dont care about DUE.

If anyone has any thoughts about this would great.... how to use SERIAL comm with nextion touch display.

Thanks

barth_bh

Hi, any solution? I have same problem - programing Nextion with hardware serial trough Mega works fine, but with Due after 4 sek connection is lost

lspaula

Guys, just trying to figure out this problem, I've got the messages from the Nextion to reach the arduino through Hardware serial 2 by doing the following:

Check the file NexConfig.h for the configuration:
Code: [Select]
#define nexSerial Serial2
Removing the mention to SoftwareSerial from the NexUpload.c file;
Adding
Code: [Select]
#include"SD.h"
Including to the Setup:
Code: [Select]
nexSerial.begin(9600);

Yeah, it seems that the messages to and from the Nextion are at 9600 bps

Still will try to update the Nextion variables, but the buttons are being captured successfully.

Regards,

Luciano.

lspaula

Variables getting updated, but still no callbacks being triggered (only the debug message returns were shown, such as [537332668:0,1,b_sistemp])  and error messages both ways:

Code: [Select]
recvRetCommandFinished err


Will keep working.

Regards,

Luciano

lspaula

#12
Jan 07, 2017, 07:36 pm Last Edit: Jan 07, 2017, 07:43 pm by lspaula
The devil is on the details. It turns out that I was missing the nexInit() on the Setup. No need to add nexSerial.begin(9600);. It is all made by the nexInit(). Moreover, the Serial for debugging is initialized as 9600bps. No need also for Serial.begin(9600).

Now everything is working apart from the button instances. Even the dual state buttons are triggering the callbacks, but I am missing some detail for the button instances.

If anyone can help, I have done the following:

1) Created the button instance:
Code: [Select]
NexButton       b_sistemp       = NexButton(0, 1, "b_sistemp");

2) Added it to the listen list:
Code: [Select]
NexTouch *nex_listen_list[] =
{
    &b_sistemp,
    NULL
};

3) Registered the callback on the Setup():
Code: [Select]
b_sistemp.attachPop(b_sistempPopCallback, &b_sistemp);

4) Created a callback for the button:
Code: [Select]
void b_sistempPopCallback(void *ptr)
{
    NexButton *btn = (NexButton *)ptr;
    dbSerialPrintln("b_sistempPopCallback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr);

    page_number = 2; //Sistemp Page
    Serial.println(F("Sistemp button was pressed"));
}


Edited: The debug serial gives me the button details, but the callback is not triggered:

[537332668:0,1,b_sistemp]


Regards,

Luciano

lspaula

Changed the Nextion event to be triggered on the button release and now everything works fine! No problems so far. Hopefully I can finish this project with no extra issues.

stulish

Hi Do you have a copy of the sketch/project that is working with just one botton on it, so i can see what is going on.

thanks

Go Up