Start a new topic

setText() works weird

 Hi, I'm basicly trying to send a float value to nextion. I'm using t0.setText() command for this. As you can see in the photo it works really weird. I also tried to have another font.


image



 

#include "Nextion.h"
#include <NexText.h>
#include <NexButton.h>
#include <NexPage.h>

NexPage page0 = NexPage(0,0,"page0");
NexPage page1 = NexPage(1,0,"page1");

NexText t0 = NexText(1, 5, "t0");       //Temp
NexText t1 = NexText(1, 6, "t1");       //Humid
NexText t2 = NexText(1, 7, "t2");       //Oxygen

char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
  &bt0,
  &bt1,
  &bt2,
  &bt3,
  NULL
};
void setup(void)
{
  /* Set the baudrate which is for debug and communicate with Nextion screen. */
  nexInit();
  dht.begin();
  Serial.begin(9600);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(ledPin,     OUTPUT);
  pinMode(uvPin,      OUTPUT);

  /* Register the pop event callback function of the dual state button component. */
  bt0.attachPop(bt0PopCallback, &bt0);
  bt1.attachPop(bt1PopCallback, &bt1);
  bt2.attachPop(bt2PopCallback, &bt2);
  bt3.attachPop(bt3PopCallback, &bt3);
  dbSerialPrintln("setup done");
}

void loop(void)
{

  //==============================
  //  Display the Temperature in °F
  //==============================


    unsigned long currentMillis = millis(); 
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;       
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Serial.print(" ");
  Serial.print(h);
  Serial.print(" ");
  Serial.println(t);
  delay(50);

  
      uint32_t tempValue;                                                   //TEMP
      memset(buffer, 0, sizeof(buffer));
      tempValue = t;
      itoa(tempValue, buffer, 10);
      t0.setText(tempValue);

      uint32_t humidValue;                                                 //HUMID
      memset(buffer, 0, sizeof(buffer));
      humidValue = h;
      itoa(humidValue, buffer, 10);
      t1.setText(humidValue);

  }
  nexLoop(nex_listen_list);  
}

 

ino
HMI

 I didn't copy all of the code in the first message but I added the file you can have a look. I have two setText() line (67 and 73) but only one of them is working besides it is working really weird. There is almost no charecter in the screen(I added the photo). Does anyone know why that might happen?

My font is 8x16,encode: iso-8859-9

Please refer to CompText example in the examples folder of Iteadlib Library

Inside loop() is in the wrong manner

@Erdem


Casting your floats 't' and 'h' to uint32_t is not the way to go, you lose your decimal place data!

Unless of course that was your intention.

And in that case you should send 'buffer'

t1.setText(buffer);

Try dtostrf()  

  char buffer [10];  
  dtostrf(t, 2, 2, buffer);
  t1.setText(buffer); 

  



Login or Signup to post a comment