Start a new topic

getText Send Text in Text object to Arduino Mega2560 does not work

I tried to get the text from a text object defined by
NexText chn = NexText(2, 36, "chn");//HMI Text object chn Channel setting
setchannel is called if button b0 is released
void setchannel(void *ptr) //set channel
{     setpointer = 1; // pointer for Set channel     dbSerialPrintln("b0PopCallback"); //debug serial monitor info     //memset(buffer, 0, sizeof(buffer)); // erase buffer and set to 0     //chn.getText(buffer, sizeof(buffer)); // write text into buffer     chn.getText(channel,10);     //channel = buffer;     Serial.println(channel);    // message = "AT+C"+channel+'\n'; //HC12 message towards receiver }

The Serial monitor responds with the following
recvRetCommandFinished ok
recvRetCommandFinished ok
Pause in hours=0
Pause in minutes=0
Pause in seconds=0
Delay in seconds=0
Blaster quantity=0
setup done
recvRetString should have a content different from 0 or "" because the Textobject on the Nextion displays 001 as channel number. However, nothing is returned.
Communication seems to work with MEGA2560. I am trying to find the reason since one day now and still have no positive result. What could be the reason?

What is the reason you deviated from CompText.ino method?

Because this method did not work out as well

Did not work out as well ... as well as what?

Seems what you are using now doesn't work

but I can confirm that the CompText.ino method does work.

Hello Patrick. I have used the method of CompText.ino now. I have programmed a new HMI with three pages. The textobjects are defined as global and the keys are numeric pads. Two Buttons are used to get the text. So far this works out. However, if I use the original HMI file it does not work. The textobjects are defined in the same way as in the new HMI file. So there is an issue with the HMI file and not the INO file.

I appended the not working HMI file. On page 2 are parameters which should be set. This does not work. I

can not find the reason.  


Please elaborate to define your problem

 - does not work ... is too vague

In defining your step by step 

    what is working up until

    point where it doesn't work

will help define your logic and narrow down you issue.

Use standard debugging principles,

-  embedded print commands to monitor progress

-  timer code to measure against expectations.

As per the HMI demo for examples

 - HMI loaded into Nextion Editor

   - have to first select device it will go on

   - have to save your HMI after selecting

Then build and upload as normal.

By does not work I mean the following: By releasing a button on the HMI Panel I want to activate getText for a Textbox via Arduino MEGA2560. Therefore I have used exactly the same method as in the Comptext.ino example. The Arduino reacts properly on the release button but as on request by the command lines

memset(buffer, 0, sizeof(buffer)); // 

 chn.getText(buffer, sizeof(buffer)); //

getText returns recvRetString[0,]

which can not be the case as the textbox with object name chn is not empty. So the text is not

returned properly to the Arduino. This is what is wrong.

So prove

   the Mega has moved into this function of button release

then prove

   the Mega executes each line in the function

Make a stub program

   that only deals with setting and retrieval

   prove the stub works, then apply what is learned

Maybe this is a new topic? If I look at the pageIDs in the actual version of the Nextion editor I find always

0 as value. Why is that? If I want to read a release button from page 1 and define the button in the arduino IDE the Mega will not response because page ID is wrong. This will happen as well with the text I want to get with the Mega?!

I attached an HMI and INO file as an example how to change Text with Numeric keyboard and SET buttons, store it in the EEPROM if it deviates from the prior Text and transfer it to the Arduino MCU. Now, one issue is still there. Everything works fine if I change the Text and release the SET button. However, if I do not change the Text and press the SET button the Arduino MCU returns recvRetString[0,] . How can I change that as to obtain a correct response via MCU? 


MCU does as told to.

If you have condition "if deviate from prior"

   to prevent EEPROM write

then condition should also include and provide for

   when to get the string return

I have not yet dug into your code, may or may not.

But several logic things don't sit right

Why use EEPROM Nextion side and not MCU side?

  - eeprom is limited write cycles - how often is this occurring?

If edit Text with Numberic Keyboard,

   - why wasn't Number component used?

Why use Set if Text hasn't been changed?


Correct response was recvRetString[0,]

   as the MCU is reporting on what occurred to debug port so you can see what has been happening

Your how to change to obtain correct response

   suggests fudging the actual events that occur

Seems like you have design issues of which is in control

  Nextion vs MCU .... MCU should always be in control

HMI Human Machine Interface

   - Human Interfacing

        - input, selections, choices, request actions

   - Machine Interfacing

       - get input and process input

       - decide if action needs to be taken

       - act only if it is safe to do so

       - report status of request to display

You have to align your logic to actual steps needing to be done.

   recvRetString should occur purposefully

      only used when required

      used not when required reports empty as it should as it is empty

Why use EEPROM Nextion side and not MCU side?

  - eeprom is limited write cycles - how often is this occurring?

Write cycles are much less than 100 times. Guaranteed EEPROM writing cycles about 100000.

So I don´t need to worry about that. I also want to use MCU EEPROM for saving parameters. 

If edit Text with Numeric Keyboard,

   - why wasn't Number component used?

I want to transfer parameter settings from HMI Panel to MCU then via HC12 module remotely to other MCU which responds if data is sent properly(half duplex mode). HC12 module has text based transfer protocol, i.e. for changing channel AT+Cxxx is used. I want to transfer xxx from HMI Panel to MCU. MCU appends xxx to AT+C as to get AT+Cxxx. So that is why I want to transfer text and not a number. 

Why use Set if Text hasn't been changed?

If I have to change the MCU connected with the HMI panel I want to be able to transfer the stored  parameter settings from the panel again. Automatic synchronizing would be the final aim

Number Component can also be converted to text

 - either Nextion side (Nextion Instruction Set)
 - MCU side (Arduino reference)
So it is the MCU side that sends to HC12
 - easily converted before send to HC12
Numbers consume much less space than text,

 - it would be programmers style I guess, 

   logic ... less easy to follow reasons.

If automatic sync is the final aim

 - then sync is done automatically with MCU shadowing values

 - no user intervention needed

But back to recvRetString being empty
  would be because of
  - either called unconditionally when a condition should be applied
  -  or not waiting for time eeprom needs for access before reading

 Splitting control logic between MCU and Nextion
  - challenges are to be expected
  - one has to clearly define and follow their own rules for.

Lets focus on recvRetString

As I wrote the following happens:

If I touch the textbox the numeric pad opens->I enter a new value-> press ok->press SET button->recvRetString is not empty

If I press SET button again recvRetString is empty.

I want to send Text to MCU whether it has changed or not. So I guess its not a timer issue but more a conditional one. Thank you Rick for your comments. I think we are getting closer in solving the problem.

So MCUs only do exactly as told to do.

Button Release for Set (b1)

repo va0.txt,4
  wepo t1.txt,4
  t2.txt="Already set in EEPROM"


 Arduino code for MCU when Button Released

void b1_1PopCallback(void *ptr)
    memset(buffer, 0, sizeof(buffer));
    t1_1.getText(buffer, sizeof(buffer));


 what code lines give an empty string and why do you think so

Login or Signup to post a comment