Start a new topic

Getting data from Nextion to Arduino without library, and store in a string.

Hi,


I`m trying to get the arduino to store a text from t0 in an string, using the print function, to use another place in my code, but I have some troubles doing so.


Using the serial monitor, I can get the value from t0.txt writing "print t0.txtÿÿÿ", but getting that value stored in a string is becoming an headache for me. 


I tried using Serial.readString like this in the loop, but only the H is printed out:


  mitNummer = Serial3.readString();

  Serial3.println("print t0.txtÿÿÿ");

  Serial.println(mitNummer); //send besked til monitor

  Serial.println("H");


Any suggestions on how to do this? The thing is that the print function print the value in ASCII, and that is just what I want, The number varies in output, so making an HEX translator is Waaay too hard for me... (educated Toolmaker)


Cheers, Daniel


Whoops, The solution is:-)


mitNummer = Serial3.readString();

  Serial3.print("print t0.txt");

  Serial3.write(0xff);

  Serial3.write(0xff);

  Serial3.write(0xff);

  Serial.println(mitNummer); //send besked til monitor

  Serial.println("H");

Hey Daniel,


So what was the difference from the first to second example.  As a char "ÿ" = a byte 0xFF. 

So the solution as to why the second worked over the first lays in something else that was changed.

Hi,


This time I can post a code that looks about right:-) Well, this is running in the setup of the arduino code, to get the variables I need, as I need the loop to run without any delay, to get serial data when arriving, When running the two print txt commands together, I only get an output from t0.txt, but running the last part of the code in the loop, I get the value I want. is there anything I`m missing? Tried printing /r, but without any luck...


 delay(100);

 

  { 

  Serial3.read();

  inData = Serial3.readString();

  Serial3.print("print t0.txt");

  Serial3.write(0xff);

  Serial3.write(0xff);

  Serial3.write(0xff);

  mitNummer = inData;

  Serial.println(mitNummer); //send besked til monitor

  inData = ""; //Tøm string for ny data

   }

  delay(100);

  {

 Serial3.read();

  inData = Serial3.readString();

  Serial3.print("print t2.txt");

  Serial3.write(0xff);

  Serial3.write(0xff);

  Serial3.write(0xff);

  minFin = inData;

  minFin.remove(0, 1);

  delay(30);

  Serial.println(minFin); //send besked til monitor

}

}

void loop(){

}


Suggestions are welcome, wife is more angry at the code than I am:-)


Cheers, Daniel

You should look at some examples from the Nextion Library


If you are not using a library, you should consider doing so as it makes things easier.  You may also want to read through some of the tutorials on programming from the Arduino site.


Checking through the threads on here generally helps provide some snippets of code, but few full files.  Pay attention if there is any .ino files in a thread and have a look at them to see how they are accomplishing what they are discussing in the thread.


Well, I have been looking around- a lot! My problem isn't that I need an LED to blink when I touch the display, that's not the hardest thing to do... I need the values of 4 text boxes in ASCII for further programming, with the arduino, and 2 other serial connected devices. I haven't seen one thread or project where one is getting 15digit numbers that never are the same out of the display in ASCII. I know I'm not the best programmer in the world, but I have been working with this in the past, and it is beginning to come back to me:-) but making some kind of translator for hex and trimming the hex string, that's never the same length, is way over my head... Just wanted an input if anyone has one. Do I need an carriage return somewhere, or is there some neat and easy way to get it to work? If not, I have to wait two weeks to get some help from a family member with a master of science in Electronic, that I'm visiting:-) Cheers, Daniel
But if there are an myNextion print function that works in the library, and spits out ASCII, I would be really glad if someone would show how it works:-) Cheers, Daniel

In order for Ascii to be output the display has to be set to do so.

If I were to use the following statement in a button on the Nextion

  printh 41 42 43 44

It is going to output ABCD.  Likewise

  printh 44 61 6E 69 65 6C 20 57 69 6E 74 68 65 72

is going to output Daniel Winther


The difficulty is that with the printh command is that you cannot use printh t0.txt


I have to apologize that I do not use Arduino, so if my answers are not lining up with what you are looking for - it probably has more to so with that fact I don't use Arduino.


Finding a code snippet

 

 

void loop(void)
{
   // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);
 
  // print the results to the serial monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);
 
  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(2);
    /*
     * When a pop or push event occured every time, 
     * the corresponding component[right page id and component id] in touch event list will be asked.
     */
     uint32_t number;
     number = outputValue;
     n0.setValue(number);//Delete this line if it dosent work
     nexLoop(nex_listen_list);
}

 

 

Perhaps you can see how serial.print works for your Arduino MCU - if this isn't it, then you need to be more clear so I can attempt to assist


Hi Daniel


Serial.print("t2.txt=");

   Serial.write(0x22);

   Serial.print("PUT YOUR TEXT OR VARIABLE HERE"); //Remove inverts for Variable

   Serial.write(0x22);

   Serial.write(0xff);

   Serial.write(0xff);

   Serial.write(0xff);

Login or Signup to post a comment