Aviso

El foro está en modo de sólo lectura.

Envio de varias variables unidas en un String hacia la pantalla Nextion

Más
6 años 5 meses antes #852 por David Flores
estoy intentando leer señales de un sensor dht22, un reloj ds3231 y otras cosas mas para un proyecto de la universidad
lo que quiero es enviar los valores del sensor a la pantalla nextion mediante la librería
t0.setText();
n0.NexNumber();

#include "Nextion.h"
#include <TimeAlarms.h> //Libreria de las Alarmas.
#include <DS3232RTC.h> //Libreria del RTC DS3231.
#include <Time.h> //libreria de complemento.
#include <Wire.h> //Libreria para comunicacion I2C.
#include "DHT.h" //cargamos la librería DHT
DHT dht2(3, DHT22);
String ho,mi,se,di,an,me;
String fe;
NexButton b0 = NexButton(0,1,"b0"); //
NexText t0 = NexText(0, 2,"t0"); //
NexNumber n0 = NexNumber(0, 2,"n0"); //

NexTouch *nex_listen_list[]=
{
&b0,
&n0,
&t0,
NULL
};

void setup() {
Serial.begin(9600);
dht2.begin(); //Se inicia el sensor
b0.attachPush(b0PushCallback, &b0);
}

void loop() {
nexLoop(nex_listen_list);
float h2 = dht2.readHumidity(); //Se lee la humedad del sensor 2
float t2 = dht2.readTemperature(); //Se lee la temperatura del sensor 2
ho=hour();
mi=minute();
se=second();
an=year();
me=month();
di=day();
fe=String("FECHA "+an+" "+me+" "+di+" --HORA-- "+ho+":"+mi+":"+se);
char str[20];
strcat (str,fe
t6.setText(fe);
n0.NexNumber(t2);

}
void Fecha() //Visualizacion de la fecha y hora el el Serial.
{
Serial.println();
Serial.print(day());
printMonth(month());
Serial.print(year());
Serial.print(" ");
Serial.print("Hora:");
Serial.print(" ");
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
}
void b0PushCallback(void *ptr)
{
digitalWrite(26,!digitalRead(26));
}
Más
6 años 5 meses antes #853 por Jose Luis
Yo aun estoy muy verde con estas librerías y encima no dispongo de ese sensor para probar de forma mas real a como has hecho tu el código.

Yo no te puedo ayudar.

Un saludo.
Más
6 años 5 meses antes - 6 años 5 meses antes #854 por Jose Luis
Intentare probar mandando un dato simulado, pero pasame tambien el codigo que usas en la nextion. A ver si veo el problema.

O mejor aun, tu puedes ver el string que tienes en fe por ejemplo anytes de mandar. Entonces haz lo siguiente, despues de esta linea
fe=String("FECHA "+an+" "+me+" "+di+" --HORA-- "+ho+":"+mi+":"+se);

suponemos que ya deberamos tener en el string cargado. Pues haz lo siguuiente fe = "string que deberia estar";
Asi lo que tendriamos en el string es el dato correcto y yo podria mirar por que no se te en la nextion.


En esta linea tiene que haber un error :

strcat (str,fe

falta cerrar parentesis al menos y no se si ibas poner algo mas.

No olvides con el codigo con estas modificaciones, enviarme el proframa para la nextion tambien. Necesito ver las dos cosas.

Un saludo.
Última Edición: 6 años 5 meses antes por Jose Luis.
Más
6 años 5 meses antes #855 por achavez
Buenas, mira yo estoy en algo similar, pero leyendo 2 DHT y un RTC, uso la libreria solo para ver el estado de un boton en la HMI. ve si te sirve.

#include "Nextion.h"
#include <Wire.h>
#include "DHT.h"
#include "RTClib.h"

#define DHTPIN1 3
#define DHTPIN2 4
#define DHTTYPE1 DHT22
#define DHTTYPE2 DHT22

NexButton bt0 = NexButton(1, 28, "boton1");

NexTouch *nex_listen_list[] =
{
&bt0,
NULL
};

float t1 = 0.0f;
float t2 = 0.0f;
float h1 = 0.0f;
float h2 = 0.0f;
int portemp1 = 0;
int portemp2 = 0;
int porhum1 = 0;
int porhum2 = 0;
int hora = 0;
int minu = 0;
int val=0;

RTC_DS1307 RTC;
DHT dht1(DHTPIN1, DHTTYPE1);
DHT dht2(DHTPIN2, DHTTYPE2);

void setup()
{

nexInit();
bt0.attachPop(cambiarLED,&bt0);
pinMode(13, OUTPUT);

Serial.begin(9600);
Wire.begin();
RTC.begin();
dht1.begin();
dht2.begin();
pinMode (13, OUTPUT);
// RTC.adjust(DateTime(2017, 11, 27, 13, 38, 0)); este es el ajuste del clock

}

void loop() {

DateTime now = RTC.now();
hora = now.hour();
minu = now.minute();
h1 = dht1.readHumidity();
h2 = dht2.readHumidity();
t1 = dht1.readTemperature();
t2 = dht2.readTemperature();
portemp1 = ((t1*100)/40);
portemp2 = ((t2*100)/40);
porhum1 = (h1);
porhum2 = (h2);

sendClockToNextion();
sendT1ToNextion();
sendT2ToNextion();
sendH1ToNextion();
sendH2ToNextion();
sendTermo1ToNextion();
sendTermo2ToNextion();
sendGot1ToNextion();
sendGot2ToNextion();

nexLoop(nex_listen_list);
Serial.println();
delay(1000);
}

void cambiarLED(void *ptr) {
digitalWrite(13, !digitalRead(13));
}

void sendClockToNextion()
{
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
String command1 = "clock.txt=\"";
String command2 = "\"";
Serial.print(command1);
if (hora < 10) {
Serial.print("0");}
Serial.print(hora);
Serial.print(":");
if (minu < 10) {
Serial.print("0");}
Serial.print(minu);
Serial.print(command2);

Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void sendT1ToNextion()
{
String command = "t1.txt=\""+String(t1,1)+"C\"";
Serial.print(command);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void sendT2ToNextion()
{
String command = "t2.txt=\""+String(t2,1)+"C\"";
Serial.print(command);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void sendH1ToNextion()
{
String command = "h1.txt=\""+String(h1,1)+"%\"";
Serial.print(command);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void sendH2ToNextion()
{
String command = "h2.txt=\""+String(h2,1)+"%\"";
Serial.print(command);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void sendTermo1ToNextion()
{
Serial.print("j1.val=");
Serial.print(portemp1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);;
}

void sendTermo2ToNextion()
{
Serial.print("j2.val=");
Serial.print(portemp2);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);;
}


void sendGot1ToNextion()
{
Serial.print("g1.val=");
Serial.print(porhum1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);;
}

void sendGot2ToNextion()
{
Serial.print("g2.val=");
Serial.print(porhum2);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);;
}
Más
6 años 5 meses antes #856 por Jose Luis
Perfecto, algo de colaboración. Se agradece y que la gente vaya tomando nota de que no solo es aparecer cuando tienes un problema. También esta bien ayudar a quien los tiene.

Gracias y un saludo.
Tiempo de carga de la página: 0.106 segundos
Gracias a Foro Kunena