Start a new topic

Need Help! ...simple write to a Textboxes on Page1 and 2

Hello!


Im new here and im also new  using nextion TFT.

I read a lot around the Display and the examples for arduino, but the examples are to old and not work with the new Editor. So was trying to learn by doing.

I found a lot and all examples i found is create som Buttons and Play with. But thats not helpfull for my projekt. The discription on nextion Page is to abstract for a beginner. For me the discription starts on Level 7 and not Level Zero. 

I only Need to write/print a string from arduino (later atmega128) to some textboxes in different pages. I create a TextBox "t0" on page 0 and  four TextBoxes "t0" on page 1. I refresh the box by arduino timer from page0 to page1. But i have no idea how i can print a simple  string from the arduino to a TextBox in the pages.

just a simple " Hello World" without Buttons and ohter things.


Hope sombudy can help me...

Thanks



Have you looked at CompText.ino and HMI from IteadLib Arduino Nextion Library?


In simple terms a Hello World sent to text component t0 on page 0 is sent as

  t0.txt="Hello World"ÿÿÿ  (where ÿ is the character representation of byte 255 or 0xFF)


If sending to t3 on page2 could be as simple as page2.t3.txt="Hello World"ÿÿÿ 


The IteadLib Arduino Nextion Library defines a text component in Arduino code.


NexText mytext = NexText(0,1,t0);

with this you can send your text using the function mytext.setText();


Frankly if there is a button, you can deduce button code from text code.

But in the end, the Nextion Instruction Set lays it all out.

If using Arduino, refer to the library .h and .cpp code files.

Just for clarification:


It is mostly senseless to write a variable on a page other than current

 - it won't be in memory if it is not current (globals are the exception)

So you will need to adjust your code accordingly.

Hello and thaks for answer! I have the lib ready installed, and i know now that i have to use differend command for arduino and for the netion Simulator.


I test a lot and take some code out off another sketches and try a Little bit.


my test code Show like this.:

//---------------------------------------------------------------------------- 
#include "Nextion.h"
//#include "NexButton.h"

NexPage page0  = NexPage(0, 0, "Start");
NexPage page1  = NexPage(1, 0, "Main");
NexPage page2  = NexPage(2, 0, "msgOK");
NexPage page3  = NexPage(3, 0, "msgFAIL");

/* * Declare a text object [page id:0,component id:1, component name: "t0"].  */

NexText Version  = NexText(0, 0, "t0");
NexText RXtxt =  NexText(1, 1, "t0");
NexText TXtxt =  NexText(1, 2, "t1");


void setup()

  nexInit();
  dbSerialPrintln("setup begin");

page0.show();

Version.setText("Ver. 2.03");

delay(5000);
page1.show();
 
}

void loop()
{
 
  page1.show();

  RXtxt.setText("Test 1");
  delay(2000);
  RXtxt.setText("Test 2");
  delay(2000);
  RXtxt.setText("Test 3");
  delay(2000);
  RXtxt.setText("Test 4");
  delay(2000);
  RXtxt.setText("Test 5");
  delay(2000);
 
  page2.show();
  delay(2000);
  page1.show();
  RXtxt.setText("Test 1");
  delay(2000);
  TXtxt.setText("Das ist eine Message");
  delay(2000);
  TXtxt.setText("Test 3");
  delay(2000);
  TXtxt.setText("Test 4");
  delay(2000);
  TXtxt.setText("Test 5");
  delay (2000);
 
  page3.show();
  delay (2000);
  page1.show();

}


//------------------------------------------------------------------------------


I try to put the changing string in a for Loop  with delay(2000) but it didnt work!? is text.set right?



Maybe somebody have a better idea?

Ist that the right way to Change strings in textboxes? (this wll works)


In the Projekt i take the strings from another SD Card and need to show them in the TFT.

Your Loop I see is switching between three pages.

When changing pages, things will be lost when not on current page

(unless global in HMI)


Try staying on page1 first, change "t0" to "page1.t0" and "t1" to "page1.t1"

NexText RXtxt =  NexText(1, 1, "t0");

NexText TXtxt =  NexText(1, 2, "t1");


Then when this works then, then build on it further.

sorry meant to say page1

OK Patrick!

I was writing on another app and didt read your first answer! Thanks for the easyer code.

But can this be possible, that the for Loop and other code not wll run?!  Maybe ist a mistake from me.


I try to build a pcb with a Atmega 128 and a  adjusted  code for the 128. what do you think, will it run with the Atmega128? (i cant take the 256 cause ist hard to solder in diy projekt)

Have you seen any text yet??


You may need to make a change in NexHardware.cpp .. baudrate in nexInit()

and check that you have wired nextion on serial2 - as found in NexConfig.h

Yes i set the global Switch in Editor. yes i´m a Little bit in the future, but i try to understand how i can use this TFT. The code in the example runs and switxh between the 4 pages. But i dont understand the entrys in the page line. what is what in the Editor and what i have to call. the "page1" at the end or the Name of the Funktion "Main"?!  (NexPage page1  = NexPage(1, 0, "Main");)

yes!  the code runs on the Display.....

...i also have seen the informations about the Hardware.h and i copy and wrote two files. one for uno and one for mega. but maybe i Need on for 128 if the chip will arrived.

 

#include <Arduino.h>
#include "Nextion.h"

NexPage page1  = NexPage(1, 0, "Main");
NexText RXtxt =  NexText(1, 1, "t0");
NexText TXtxt =  NexText(1, 2, "t1");

void setup()
{  
  nexInit();
  dbSerialPrintln("setup begin");
  page1.show();
 }


void loop()
{
  RXtxt.setText("Test 1");
  delay(2000);
  TXtxt.setText("Test 2");
  delay(2000);
}

 

Try something like this first, changes to page1 uses t0 comp id 1 and t1 comp id2

Then puts Test 1 in t0, and Test 2 in t1 of page1


If all is okay with serial you will see this on your screen.

Then build once serial is known good.

...now i start the board again and see, that the page not change and the Version.txt only flicker. whats wrong? before it runs..?

...the pages 2 and 3 are popups later....

Okay serial works, commands getting through to Nextion.


There is a reason why and when pages and values should change

usually in response to something happened on Arduino and status needs to be sent to user

or because the User has pressed something on Nextion and you are responding to user request


Understanding this workflow, will be able to help say when something should occur.


The earlier code says:

- show page0 with version 5 sec and change to 1 (setup)

- loop() says

   - show page 1, update 5 times RXtxt to t0 of page 1 id 1 ( NexText(1, 1, "t0");)  ~10 sec

   - show page 2, update 5 times TXtxt  to t1 of page 1 id 2 ( NexText(1, 2, "t1");) ~ 10 sec

   - show page 3, ~ 2 sec, change to page 1


I think maybe TXtxt is either the second text with id 2 on page 1 as declared

  or you meant for it to be declared for page 2 t1 with id of 2 NexText(2, 2, "t1")

But this will not show TXtxt on non current page as it is

Login or Signup to post a comment