About setComponentText

Hey guys I got problem about my project I upload all I need in this project but it show
'class Nextion' has no member named 'setComponentText' and
'class Nextion' has no member named 'init' how can I fix it?

#include <ArduinoComponents.h>

#include <Nextion.h>

#include <Arduino_JSON.h>

#include <ArduinoJson.h>
DynamicJsonDocument doc(1024);

#include <EEPROM.h>

#include <SoftwareSerial.h>
#include <Nextion.h>
String message;
int k=0;
SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino
Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

int ReadEPROM;
int ReadEPROM2;
void setup() {
Serial.begin(115200);
myNextion.init();

  for(int i=0;i<18;i++){
  int Add=doc["add"][i];
  int Pos=(i+1)*10;
  ReadEPROM=EEPROM.read(Pos);
  myNextion.setComponentText("np"+String(i), String(ReadEPROM));
  Serial.println(ReadEPROM);
  }

}

void loop() {
message = myNextion.listen(); //check for message
if(message != ""){ // if a message is received...
Serial.println(message);
String inputString = message;
int startIndex = inputString.indexOf("{"); // Find the index of the opening brace
int endIndex = inputString.indexOf("}"); // Find the index of the closing brace
String orderString = inputString.substring(startIndex, endIndex + 1); // Extract the substring, including the braces
deserializeJson(doc,orderString);
Serial.println(orderString);
k=1;
}
if(k==1){
int Pre_Order = doc["o"][0];
Serial.print("Pre_Order :");
Serial.println(Pre_Order);
int Pre_Order1 = doc["r"][0];
Serial.print("Pre_Order :");
Serial.println(Pre_Order);
int Pre_Add = doc["a"][0];
Serial.print("Pre_Add :");
Serial.println(Pre_Add);
int Pre_Add1 = doc["b"][0];
Serial.print("Pre_Add1 :");
Serial.println(Pre_Add1);
int Pre_Reset = doc["r"][0];
Serial.print("Pre_Reset :");
Serial.println(Pre_Reset);
if(Pre_Order==1){
for(int i=1;i<=18;i++){
int order=doc["o"][i];
int Pos=(i)*10;
ReadEPROM=EEPROM.read(Pos);
int Add = ReadEPROM-order;
EEPROM.write(Pos,Add);
ReadEPROM=EEPROM.read(Pos);
myNextion.setComponentText("ontime", "1");
Serial.print("ReadEPROM :");
Serial.println(ReadEPROM);
Serial.print("Order :");
Serial.println(order);
delay(100);
if(order==0){
myNextion.setComponentText("t"+String(i-1), "-");
}
else{
myNextion.setComponentText("t"+String(i-1), "P");
}
// Serial.println(Name);
}
}
else if(Pre_Add==1){
for(int i=1;i<=9;i++){
int Add=doc["a"][i];
int Pos=(i+9)*10;
EEPROM.write(Pos,Add);
ReadEPROM=EEPROM.read(Pos);
// myNextion.setComponentText("np"+String(i-1), String(ReadEPROM));
Serial.print("ReadEPROM :");
Serial.println(ReadEPROM);
}
}
else if(Pre_Add1==1){
for(int i=1;i<=9;i++){
int Add=doc["b"][i];
int Pos=(i)*10;
EEPROM.write(Pos,Add);
ReadEPROM=EEPROM.read(Pos);
// myNextion.setComponentText("np"+String(i-1), String(ReadEPROM));
Serial.print("ReadEPROM :");
Serial.println(ReadEPROM);
}
}

else if(Pre_Reset==1){
  for(int i=0;i<18;i++){
  int Pos=(i+1)*10;
  ReadEPROM=EEPROM.read(Pos);
  myNextion.setComponentText("np"+String(i), String(ReadEPROM));
  Serial.println(ReadEPROM);
  }
}
myNextion.setComponentText("status", "Empty");    
message="";
k=0;
}

}

Here is my code

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Which library are you using? This one doesn't have setComponentText.
Where did you get the code that uses setComponentText?

Tbh, I have no idea cuz I got this code from my senior😥
How about class Nextion init? Did you know how can I fix it? I download itead Nextion from GitHub already but it show up that not found and don’t have class Nextion no member init.

Sorry, I don't. It won't help me, but it may encourage others to help you, if you do what you were asked to do in post #2

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.