Perry, I am having a similar problem. I just bought this NX8048P050 to use with my ESP32. When I have the Arduino IDE try to get data from the Nextion, I get nothing but garbage. And when I try to have it change the page on the Nextion, nothing happens, the same when I try to have it write text to t0. My serials are called SerialNex5 and SerialNex10 because I plan to have 2 displays, 1 to display data and the other to control relays for lights. That being said, I have tied:
if (SerialNex5.available())
and it runs the if statement, so I know that it is connecting to the serial port. Do you have a test sketch and HMI that I could test to make sure this display isn't bad before I try to return it?
Topic split from another topic. Please do not add your own questions to the end of other people's topics.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Thank you.
Hello @crwhite57 ,
I don't have anything specific for testing a Nextion but if you try the code in my tutorial Using Nextion displays with Arduino it should act as a test.
If you post your code and upload your HMI file (in a zip file as the forum software won't allow a HMI file) then I'll look at it for you.
Thank Perry. Let me give you some information about the project. This is for an electric car I am building. I am using 2 Nextion displays. The first one is an NX804P050-011 5-inch and the second one is the 10-inch NX1060P101=011R. The 10-inch will be the dash just to display information, but the 5-inch is supposed to show bootup information, then go to a passcode screen, then to the 3rd page that controls 8 relays. The problem is that the ESP is not receiving the passcode, changing the pages, and not printing the text to the display. This is a lengthy code, so I hope someone can help. I am only uploading the HMI that has the buttons as the 2 of them make it too large to upload. If we can figure out the Nex5 then I will know what to do for the Nex10.
#include <TinyGPSPlus.h>
#include "SoftwareSerial.h"
#include "Nextion.h"
/*#include "NexDualStateButton.h"*/
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
static const int gpsRXPin = 18, gpsTXPin = 19;
static const uint32_t GPSBaud = 9600;
SoftwareSerial SerialNex5(16, 17);
SoftwareSerial SerialNex10(0, 4);
SoftwareSerial Serialgps(gpsRXPin, gpsTXPin);
Adafruit_MPU6050 mpu;
int R1 = 32;
int R2 = 33;
int R3 = 25;
int R4 = 26;
int R5 = 27;
int R6 = 14;
int R7 = 12;
int R8 = 13;
int R9 = 5;
int counter = 0;
int startCount = 0;
unsigned long last = 0UL;
TinyGPSPlus gps;
const int voltageSensorPin = 39;
float vIn;
float vOut;
float voltageSensorVal;
const float factor = 5.1;
const float vCC = 5;
//convert C to F
const float farin = 1.52;
String dfd = "";
String sendD = "";
// Nextion Objects, ada 5 tombol
// (page id, component id, component name)
NexDSButton bt0 = NexDSButton(2, 1, "bt0");
NexDSButton bt1 = NexDSButton(2, 2, "bt1");
NexDSButton bt2 = NexDSButton(2, 3, "bt2");
NexDSButton bt3 = NexDSButton(2, 4, "bt3");
NexDSButton bt4 = NexDSButton(2, 5, "bt4");
NexDSButton bt5 = NexDSButton(2, 6, "bt5");
NexDSButton bt6 = NexDSButton(2, 7, "bt6");
NexDSButton bt7 = NexDSButton(2, 8, "bt7");
NexButton b0 = NexButton(2, 1, "b0");
NexText t0 = NexText(2, 9, "t0");
NexText t1 = NexText(2, 10, "t1");
NexText t2 = NexText(2, 11, "t2");
NexText t3 = NexText(2, 12, "t3");
NexText t4 = NexText(2, 13, "t4");
NexText t5 = NexText(2, 14, "t5");
NexText t6 = NexText(2, 15, "t6");
NexText t7 = NexText(2, 16, "t7");
NexPage page0 = NexPage(0, 0, "page0");
NexPage page1 = NexPage(1, 0, "page1");
NexPage page2 = NexPage(2, 0, "page2");
char buffer[100] = {0};
// Register objects to the touch event list
NexTouch *nex_listen_list[] = {
&page0,
&page1,
&page2,
&bt0,
&bt1,
&bt2,
&bt3,
&bt4,
&bt5,
&bt6,
&bt7,
&b0,
NULL
};
void page0PopCallback(void *ptr)
{
Serial.println("page0PopCallback");
page0.show();
}
void page1PopCallback(void *ptr)
{
Serial.println("page1PopCallback");
page1.show();
}
void page2PopCallback(void *ptr)
{
dbSerialPrintln("page2PopCallback");
page2.show();
}
void bt0PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("bt0PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt0.getValue(&dual_state);
if (dual_state)
{
t0.setText("ON");
digitalWrite(R1, LOW);
}
else
{
t0.setText("OFF");
digitalWrite(R1, HIGH);
}
}
void bt1PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("bt1PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt1.getValue(&dual_state);
if (dual_state)
{
t1.setText("ON");
digitalWrite(R2, LOW);
}
else
{
t1.setText("OFF");
digitalWrite(R2, HIGH);
}
}
void bt2PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("bt2PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt2.getValue(&dual_state);
if (dual_state)
{
t2.setText("ON");
digitalWrite(R3, LOW);
}
else
{
t2.setText("OFF");
digitalWrite(R3, HIGH);
}
}
void bt3PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("b3PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt3.getValue(&dual_state);
if (dual_state)
{
t3.setText("ON");
digitalWrite(R4, LOW);
}
else
{
t3.setText("OFF");
digitalWrite(R4, HIGH);
}
}
void bt4PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("bt4PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt4.getValue(&dual_state);
if (dual_state)
{
t4.setText("ON");
digitalWrite(R5, LOW);
}
else
{
t4.setText("OFF");
digitalWrite(R5, HIGH);
}
}
void bt5PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("bt5PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt5.getValue(&dual_state);
if (dual_state)
{
t5.setText("ON");
digitalWrite(R6, LOW);
}
else
{
t5.setText("OFF");
digitalWrite(R6, HIGH);
}
}
void bt6PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("bt6PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt6.getValue(&dual_state);
if (dual_state)
{
t6.setText("ON");
digitalWrite(R7, LOW);
}
else
{
t6.setText("OFF");
digitalWrite(R7, HIGH);
}
}
void bt7PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
Serial.println("bt7PopCallback");
Serial.print("ptr=");
Serial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt7.getValue(&dual_state);
if (dual_state)
{
t7.setText("ON");
digitalWrite(R8, LOW);
}
else
{
t7.setText("OFF");
digitalWrite(R8, HIGH);
}
}
void b0PopCallback(void *ptr)
{
uint16_t len;
uint16_t number;
NexButton *btn = (NexButton *)ptr;
dbSerial.println("b0PopCallback");
dbSerial.print("ptr=");
dbSerial.println((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the text value of button component [the value is string type]. */
btn->getText(buffer, sizeof(buffer));
number = atoi(buffer);
number += 1;
memset(buffer, 0, sizeof(buffer));
itoa(number, buffer, 10);
/* Set the text value of button component [the value is string type]. */
btn->setText(buffer);
stopCar();
}
void startCar()
{
// Turn motor power on
digitalWrite(R9, HIGH);
}
void stopCar()
{
// Turn motor power off
digitalWrite(R9, LOW);
ESP.restart();
}
void setup() {
//Start Serial Ports
Serial.begin(115200);
SerialNex5.begin(115200);
SerialNex10.begin(19200);
Serialgps.begin(9600);
Wire.begin();
/******************************************************************/
page0.attachPop(page0PopCallback);
page1.attachPop(page1PopCallback);
page2.attachPop(page2PopCallback);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(R3, OUTPUT);
pinMode(R4, OUTPUT);
pinMode(R5, OUTPUT);
pinMode(R6, OUTPUT);
pinMode(R7, OUTPUT);
pinMode(R8, OUTPUT);
pinMode(R9, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(R9, LOW);
SerialNex5.print("page1");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
}
void loop(void) {
nexLoop(nex_listen_list);
while (counter != 1) {
while (!SerialNex5.available()) {
Serial.println("Nextion 5 Off line");
}
if (SerialNex5.available()) {
Serial.println("Nextion 5 inch On Line");
SerialNex5.print("page0");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.print("t0.txt=\"Nextion is On Line\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
delay(30);
/*****************************MPU6050 Setup***************************/
Serial.println("Adafruit MPU6050 test!");
SerialNex5.print("t0.txt=\"Testing MPU6050\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
delay(2000);
// Try to initialize!
while (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
Serial.println("Change Nex5 to Page 2 and Nex10 to page 2");
Serial.print(F("MPU6050 status: "));
Serial.println("Not Connected");
SerialNex5.print("t0.txt=\"MPU6050 status:\"");
// SerialNex5.print(“\xFF\xFF\xFF”);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.print("t1.txt=\"Not Connected\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("page1");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("t0.txt=\"MPU6050 status:\"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("t1.txt=\"Not Connected\"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
delay(3000);
while (1) {
delay(10);
}
}
if (mpu.begin()) {
Serial.println("MPU6050 Found!");
SerialNex5.print("t0.txt=\"MPU6050 Connected\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.print("t1.txt=\" \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("page1");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("t0.txt=\"MPU6050 Connected\"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("t1.txt=\" \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
delay(2000);
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
SerialNex5.print("t0.txt=\"Accelerometer range\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t0.txt=\"Accelerometer range\"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
SerialNex5.print("t1.txt=\"set to +-2G \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"set to +-2G \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
SerialNex5.print("t1.txt=\"set to +-4G \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"set to +-4G \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
SerialNex5.print("t1.txt=\"set to +-8G \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"set to +-8G \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
SerialNex5.print("t1.txt=\"set to +-16G \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"set to +-16G \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
}
delay(2000);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
SerialNex5.print("t0.txt=\"Gyro range set to\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t0.txt=\"Gyro range set to\"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
SerialNex5.print("t1.txt=\"+- 250 deg/s \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"+- 250 deg/s \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
SerialNex5.print("t1.txt=\"+- 500 deg/s \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"+- 500 deg/s \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
SerialNex5.print("t1.txt=\"+- 1000 deg/s \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"+- 1000 deg/s \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
SerialNex5.print("t1.txt=\"+- 2000 deg/s \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"+- 2000 deg/s \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
}
delay(2000);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
SerialNex5.print("t0.txt=\"Filter bandwidth set to\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t0.txt=\"Filter bandwidth set to\"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
SerialNex5.print("t1.txt=\"260 H \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"260 H \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
SerialNex5.print("t1.txt=\"184 Hz \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"184 Hz \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
SerialNex5.print("t1.txt=\"94 Hz \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"94 Hz \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
SerialNex5.print("t1.txt=\"44 Hz \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"44 Hz \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
SerialNex5.print("t1.txt=\"21 Hz \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"21 Hz \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
SerialNex5.print("t1.txt=\"10 Hz \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"10 Hz \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
SerialNex5.print("t1.txt=\"5 Hz \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t1.txt=\"5 Hz \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
break;
}
Serial.println("");
delay(100);
Serial.println("Done!\n");
SerialNex5.print("t0.txt=\"Done!\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.print("t1.txt=\" \"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("t0.txt=\"Done!\"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("t1.txt=\" \"");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
delay(3000);
SerialNex5.print("page1");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex10.print("page 2");
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
counter = 1;
Serial.println(counter);
startup();
}
/*****************************************************************************************************/
//*********************** Get data from MPU-6050*****************/
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("Temperature: ");
Serial.print(temp.temperature * farin + 32);
Serial.println(" degF");
SerialNex5.print("t8.txt=" + String(temp.temperature * farin + 32));
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
//*********************Get system voltage****************/
SerialNex10.listen();
// if (SerialNex10.available()){
voltageSensorVal = analogRead(voltageSensorPin);
vOut = (voltageSensorVal / 1024) * vCC;
vIn = vOut * factor;
//********************************Print to dashboard****************************/
Serial.print("Pitch: ");
Serial.println(String(a.acceleration.x));
SerialNex10.print("j0.val=" + String(a.acceleration.x));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("z2.val=" + String(a.acceleration.y));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
Serial.print("Roll: ");
Serial.println(String(a.acceleration.y));
SerialNex10.print("n5.val=" + String(vIn));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
Serial.print("Voltage: ");
Serial.println(String(vIn));
while (Serialgps.available() > 0)
gps.encode(Serialgps.read());
if (gps.location.isUpdated())
{
Serial.print("Latitude: ");
Serial.print(gps.location.rawLat().negative ? "-" : "+");
Serial.println(gps.location.rawLat().deg);
SerialNex10.print("t1.txt=" + String(gps.location.rawLat().negative ? "-" : "+"));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("n3.val=" + String(gps.location.rawLat().deg));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
Serial.print("Longitude: ");
Serial.print(gps.location.rawLng().deg);
SerialNex10.print("t1.txt=" + String(gps.location.rawLng().negative ? "-" : "+"));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.print("n2.val=" + String(gps.location.rawLng().deg));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
else if (gps.satellites.isUpdated())
{
Serial.print("Number Sats: ");
Serial.println(String(gps.satellites.value()));
SerialNex10.print("n1.val=" + String(gps.satellites.value()));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
else if (gps.altitude.isUpdated())
{
Serial.print("Altitude: "); // Select as required
Serial.print(String(gps.altitude.feet())); // Select as required
Serial.println("ft"); // Select as required
SerialNex10.print("n4.val=" + String(gps.altitude.feet())); // Select as required
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
else if (gps.course.isUpdated())
{
Serial.print("Bearing: ");
Serial.println(String(gps.course.deg()));
SerialNex10.print("z1.val=" + String(gps.course.deg()));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
else if (gps.speed.isUpdated())
{
SerialNex10.print("z0.val=" + String(gps.speed.mph() * 1.27) + "\t"); // Select as required
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
Serial.print("Speed: "); // Select as required
Serial.print(String(gps.speed.mph())); // Select as required
Serial.println("MPH"); // Select as required
SerialNex10.print("n0.val=" + String(gps.speed.mph())); // Select as required
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
else if (gps.time.isUpdated())
{
Serial.print("Time: ");
Serial.print(gps.time.hour());
SerialNex10.print("n6.val=" + String(gps.time.hour()));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
Serial.print(":" + String(gps.time.minute()));
SerialNex10.print("n7.val=" + String(gps.time.minute()));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
Serial.println(":" + String(gps.time.second()));
SerialNex10.print("n8.val=" + String(gps.time.second()));
SerialNex10.write(0xff);
SerialNex10.write(0xff);
SerialNex10.write(0xff);
}
delay(500);
//}
}
void startup()
{
if (startCount == 0) {
while (!dfd == "1957") {
String dfd = "";
delay(300);
while (SerialNex5.available()) {
dfd += char (SerialNex5.read());
Serial.print("Waiting for passcode");
Serial.println(dfd);
Serial.println(dfd.substring(0, 4));
}
}
startCount = 1;
Serial.println("Passcode ACCEPTED");
SerialNex5.print("t0.txt = \"Passcode ACCEPTED\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.print("t1.txt=\"You are Authorized\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
delay(2000);
Serial.println("MotorOn");
SerialNex5.print("t0.txt=\"Power to the motors\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.print("t1.txt=\"is now activated\"");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
startCar();
SerialNex5.print("page2");
SerialNex5.write(0xff);
SerialNex5.write(0xff);
SerialNex5.write(0xff);
startCar();
}
}
Power Switchs.zip (4.2 MB)
Thank you for your code.
At what point in writing all that did it stop working?
OK, let me guess, the answer is it never worked, yes?
Assuming I'm right then you have to stop and back up and go back to basics. You should never write that much code without doing it in small steps and testing as you go, so start with something simple, such as displaying 'Hello World' in a text box on the Nextion, or using my demonstration code. Get that working then keep adding in small steps making sure each new step works and does not break what you did before.
If you read my tutorial you will discover there are 4 ways to drive a Nextion:
- Using the official Nextion libraries: No one here has to my knowledge ever had much success with them, those that have tried report only problems. No one here to my knowledge supports them, I certainly don't.
- Use my methods, which you need to understand to use. If you use my methods I will help you.
- Use @Seithan's library, which I have heard is very good, but I cannot help with much.
- Invent your own way of driving a Nextion, well, I managed it so I don't see why someone else can't do it.
I consider myself to be a good hobby programmer in C, not a professional and not much good at C++, so if you want my help then please stick to C at the same level of complexity as in my example code. Your code is full of stuff I don't understand, there are people who will understand it easily, but I doubt they know much about Nextion displays.
So here's what I don't understand about you, you have not told me your skill level in programming. That I need to say write a little bit at a time and test as you go, and used lots of delay() suggests you are a beginner. That you wrote code with lots of pointers and callback functions suggests expert far beyond my level. What is your skill level?
I have been doing programming for the ESP32 for about 2 years now and have been pretty good at it using GPS, Temp sensors, Proximity sensors, TFT displays, and much more. This is my first time using the Nextion display and how to send and receive data to and from it.
Could you post a link to your tutorial so I can check it out?
It's a sticky at the top of this (display) section of the forum.
Your startup function has a couple of odd features. Try != in your test for 1957.
Also, you have redeclared your dfd String there which I expect has broken things too.
Echoing @PerryBebbington, you have a huge amount of code there for something that doesn't work.
I had to declare it 2 times.
The first was because if I didn't do the first one, I would get an error the dfd was not declared, and the second one was so that each time it looped and dfd didn't equal 1957, it would clear out what it did get. The problem is that dfd keeps getting garbage I never had sent to it.
You don't need to declare it twice. It makes sense to set it to an empty string though so just remove the word String from that line.
Thanks, It did that.
Perry, I just downloaded your Nextion_demonstration43.ino and got this error when I tried to compile it.
'index' redeclared as different kind of symbol
it is referring to this line.
enum HMIData {spare, page, type, index, data0, data1};
Is there a way to fix this so I can see if it works with my Nextion?
Thank you for pointing that out.
The sketch compiles OK for a Mega but not a ESP8266. I don't have an ESP32 to test with so have not tried to compile for that board, but I suspect I'd get similar problems.
There appear to be conflicts between some of the variable names I chose and some of the variables defined for the ESP boards, I have re-named the variables and I believe removed the conflicts. I have uploaded the new files to the tutorial for you to try, please let me know of any problems.
I don't see the upload. And you are right. Here is the full error
Nextion_demonstration43:14:34: error: 'index' redeclared as different kind of symbol
enum HMIData {spare, page, type, index, data0, data1};
It's in the tutorial at the end of part 3 exactly where the version with the error was. The code pasted into the reply is also the modified version.
That fixed the error. I will let you know if it works when I get back up. I have not been to bed yet.
Unfortunately, it does not work. I have a feeling the display is defective.
It might be, but I'd try a bunch more tests before concluding that. Can you try with a different type of Arduino for example?
All I have are 2 ESP32dev,2 ESP8266 d1mini, and 2 ESP8266 WeMos D1.
Get yourself a Nano Every and try that.
Can you post some photos and describe the problem in more detail?