Hello
I have been trying to report the position of the touched point on a Nextion screen.
Got buttons, text, sliders, variables, images etc all working fine, but the reporting part I can't seem to crack, and I think it maybe because I am not formatting the command correctly.
I am not using the clumsy Nextion library (have not needed to), and Perry has given some excellent pointers in his stickied thread (wasn't sure whether to post in there... thought better here).
The Nextion command guide states: ( Instruction Set - Nextion )
Command:
*tch0,tch1,tch2,tch3 *
Touch
Coordinates x.val=tch0, y.val=tch1
Readonly. When Pressed tch0 is x coordinate, tch1 is y coordinate.
When released (not currently pressed), tch0 and tch1 will be 0.
tch2 holds the last x coordinate, tch3 holds the last y coordinate.
Returned (Length=9)
0x67 Touch Coordinate (awake) 0x67 0x00 0x7A 0x00 0x1E 0x01 0xFF 0xFF 0xFF
Returned when sendxy=1 and not in sleep mode
0x00 0x7A is x coordinate in big endian order,
0x00 0x1E is y coordinate in big endian order,
0x01 is event (0x01 Press and 0x00 Release)
(0x00256+0x71,0x00256+0x1E)
data: (122,30) Pressed
My short 'test' routine (and its incorrect I know)... is here. It throws back very random numbers and not what I was expecting.
Page 7 by the way is the page within my Nextion programming that gives me a blank page to use.
#include <Nextion.h> // Library for the Nextion screen
#define NEXTION_PORT Serial1
Nextion nex(NEXTION_PORT);
Long SwipeX;
//---------------------------------------
void setup() {
Serial.begin(9600); // For serial debug
Serial1.begin(9600); // Serial to Nextion
Serial1.print("rest");Serial1.print("\xFF\xFF\xFF"); // Reset the Nextion screen
delay(100);
Serial1.print("dim=100");Serial1.print("\xFF\xFF\xFF"); // Set brightness to 100%
Serial1.print("page ");Serial1.print(7);Serial1.print("\xFF\xFF\xFF");; // Change to swipe page
Serial1.print("sendxy=1");Serial1.print("\xFF\xFF\xFF"); // Turn on co-ord reporting
//---------------------------------------
}
void loop() {
Serial1.print("tch0");Serial1.print("\xFF\xFF\xFF"); // Request touched X co-ord
if (Serial1.available()) {
SwipeX= Serial1.read();if (SwipeX!=255){Serial.println(SwipeX);}
}
}
I have literally thrown all kinds of variations of that command at it. Tried reading the result as 9 individual Serial.reads etc (It reports 255 all the time if nothing comes back - hence the !=255).
It's odd that I get random numbers when I touch the screen, but there seems to be no pattern and certainly not 9 variables in a row as I am expecting (am I even correct there?).
It says the result is in big endian order, which I don't understand. but, I still would expect a result I could deduce something from. This is totally random and returns 2 or 3 odd variables at best.
I never see 103 (0x67), which I thought would be the starting value.
I worked out the "sendxy=1" to start the XY reporting. Nothing came back at all until I sent that.
Ideas?