Start a new topic

Getting data from arduino mega into nextion txt box

Hi I have the following code which works well by displaying the results I require, however I would like to display the results in a text box t0 on my Nextion display. Does anyone have any pointers please.


void loop() { 

 

  Serial.println();

 

  int x = analogRead(xpin); //read from xpin

  delay(1); //

  int y = analogRead(ypin); //read from ypin

  delay(1);

  int z = analogRead(zpin); //read from zpin

 

  float zero_G = 512.0; //ADC is 0~1023 the zero g output equal to Vs/2

  float scale = 102.3; //ADXL335330 Sensitivity is 330mv/g

  //330 * 1024/3.3/1000

  Serial.print round(((float)x - 331.5) / 65 * 9.8); //print x value on serial monitor

  Serial.print("%");

  Serial.print("\n");

  Serial.print round(((float)y - 329.5) / 68.5 * 9.8); //print y value on serial monitor

  Serial.print("%");

  Serial.print("\n");

  delay(1000);

  Serial.print("\n");

  delay(3000); //wait for 1 second

 

  while (Serial.available()) {

    char inChar = Serial.read();

 


    Serial.print(variable);

    Serial.write(0x22);

    Serial.write(0xFF);

    Serial.write(0xFF);

    Serial.write(0xFF);


Many Thanks

Andy


1 person likes this idea

Sorry should have said I have already added the following code.


 

NexButton b0 = NexButton(1, 1, "b0"); // Button added

NexButton b1 = NexButton(1, 2, "b1"); // Button added

NexButton b2 = NexButton(1, 3, "b2"); // Button added

NexButton b3 = NexButton(1, 4, "b3"); // Button added

NexButton b4 = NexButton(1, 5, "b4"); // Button added

NexButton b5 = NexButton(1, 6, "b5"); // Button added

NexButton b6 = NexButton(2, 1, "b0"); // Button added

NexButton b7 = NexButton(2, 1, "b1"); // Button added

NexText t0 = NexText(2, 5, "t0"); //

void updateTextBox () {

}

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 


 

NexTouch *nex_listen_list[] =

{

  &b0, // Button added

  &b1, // Button added

  &b2, // Button added

  &b3, // Button added

  &b4, // Button added

  &b5, // Button added

  &b6, // Button added

  &b7, // Button added

  &t0, // Text Box added

  NULL

}; // End of touch event list

This forum was closed Nov 15, 2017

New forum at nextion.itead.cc opened Sep 2017.