Start a new topic
Solved

0x67 return errors

My nextion 3.2 seem returning error with xy coordinates:

somes part of the screen are ok, but some others return negative coordinates. Thats the matter?




place here your HDMI and your sketch file then I can see if I have it also.

I use Arduino and a 3.2 nextion display


Vic


using  this librairy: https://github.com/bborncr/nextion

#include <Nextion.h>
Nextion Ecran(Serial3, 9600);
void setup() {
  Serial.begin(9600);
  Ecran.init();
  Serial.println("Start");
}
void loop() {
   Ecran.sendCommand("sendxy=1");
  delay(100);
  String message = Ecran.listen();
  if ( message != "") Serial.println(message);
}

Its returning like the screen could splited in 6 parts with negatives coordinates.

According to the Nextion return codes 0x67 is not an error


The touch event return data format that is

returned when sendme=1 is 9 bytes long:


0x67   0x00 0x7A   0x00 0x1E   0x01   0xFF 0xFF 0xFF


If the first byte is:  

  • 0x67 touch is in awake state follows 
  • 0x68 touch is in sleep state follows
The second and third bytes are the x coordinate
  • 0x00 followed by 0x7A  is calculated as 0x00 * 256 + 0x76 = x = 122.
The fourth and fifth bytes are the y coordinate
  • 0x00 followed by 0x1E is calculated as 0x00 * 256 + 0x1E = y = 30.
If the sixth byte is:
  • 0x00 this is a release event
  • 0x01 this is a touch event
Bytes seven, eight and nine
  • 0xFF 0xFF 0xFF - signifies end of data.

The possible x and y coordinates are two-byte word values with the range 0 to 655, There are no negative values possible.  You could use the Nextion editor, and use "display MCU input" and see the values the display is returning.  If the data being returned is not in the above format, something is going on, but if the data matches, there is an error in the way the code is trying to interpret the data.


Patrick

Thanks a lot.

 I finally rewrite a method in librairy



 

String Nextion::listenxy(int *XTH, int *XT , int *YTH , int *YT){
  char _bite;
  char _end = 0xff;//end of file x3
  String cmd;
  int countEnd = 0;

  while(nextion->available()>0){
	delay(10);
	if(nextion->available()>0){
	  _bite = nextion->read();
	  cmd += _bite;
	  if(_bite == _end) countEnd++;
	  if(countEnd == 3) break;
	}
  }

*XTH = cmd[1];
*XT  = cmd[2];
*YTH = cmd[3];
*YT  = cmd[4];
 
return cmd; 	
	
 }

 and manage the program

#include <Nextion.h>

Nextion Screen(Serial3, 9600);

void setup() {
  Serial.begin(9600);
  Screen.init();
  Serial.println("Start");
}

void loop() {

  String message;
  int XtouchH, Xtouch, YtouchH, Ytouch;

  Screen.sendCommand("sendxy=1");
  delay(50);
  message = Screen.listenxy(&XtouchH, &Xtouch, &YtouchH, &Ytouch);

  if (message != "") {

    if (Xtouch < 0) Xtouch =  Xtouch + 255;
    if (YtouchH == 0 && Ytouch < 0)  Ytouch = Ytouch + 255;
    if (YtouchH == 1 && Ytouch > 0)  Ytouch = Ytouch + 255;
    if (YtouchH == 1 && Ytouch < 0)  Ytouch = Ytouch + 512;

    // swap axis and calibration
    int X = Ytouch * 400.0 / 382.0;
    int Y = Xtouch;

    Serial.print ("X="); Serial.println(X);
    Serial.print ("Y="); Serial.println(Y);
    Serial.println ("");

  }
}