I have an Arduino MEGA with one of these Nextion displays. I created a nice display and my aim is to show analog inputs. However I have noticed that this display cannot show decimals (using the number "widget"). So I am using "text" widget to do that, unfortunately it doesn't work, anybody knows why?
#include "Nextion.h"
#define RES 1023
#define AREF 5
int voltage_pin=A0;
int raw_voltage;
double voltage;
String voltage2;
void setup() {
Serial.begin(9600);
}
void loop() {
raw_voltage=analogRead(voltage_pin);
voltage=raw_voltage*AREF/RES;
Serial.print("n3.val=");
Serial.print(raw_voltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
String voltage2=String(voltage);
Serial.print("t10.txt=");
Serial.print(voltage2);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(100);
}
Thanks in advance! :)