Thanks a lot for your reply Perry. Yes I know that you don't use the Nextion Libraries, I read your posts before start programming, but unfortunately I used the libraries I don't know why, but seems to me easy to understand at this first approuch. I notice that this libraries uses a lot of memory of the Arduino just to be added to the code. I tried at the frst post to add my code directly but it has more than 9000 characteres so I attached it. Will try again. Do you think that is to much code to be handled by the One board? Or there are bugs in my code? I added comments in Spanish into my code but if you need I can translate that. Maybe is just a problem of the libraries. (I will take a lok to the Ray Livingston libraries and learn to use your methods too)
//***Libraries Declaration***
//Nextion
#include "Nextion.h"
SoftwareSerial NextionSerial(11,12);
//BMEP280Sensor
#include "Adafruit_BME280.h"
Adafruit_BME280 bme;
#define SEALEVELPRESSURE_HPA (1013.25)
//MPU6050
//#include <Wire.h>
//#define MPU 0x68
//Ratios de conversion
//#define A_R 16384.0
//#define G_R 131.0
//
////Conversion de radianes a grados 180/PI
//#define RAD_A_DEG = 57.295779
//***Declaracion de Variables de Programa***
int Page=1;
const int Relay1 = 2;
const int Relay2 = 3;
const int Relay3 = 4;
const int Relay4 = 5;
const int Relay5 = 6;
const int Relay6 = 7;
const int Relay7 = 8;
const int Relay8 = 9;
int Altitud_Escalado;
//MPU-6050 da los valores en enteros de 16 bits
//Valores sin refinar
//int16_t AcX, AcY, AcZ, GyX, GyY, GyZ;
//
////Angulos
//float Acc[2];
//float Gy[2];
//float Angle[2];
//long tiempo_prev;
//float dt;
//float Angle0_Previous, ang_x;
//float Angle1_Previous, ang_y;
//int PitchG_Val;
//int RollG_Val;
//***Declaracion de Componentes NEXTION***
NexDSButton Boton1 = NexDSButton(1, 2, "Boton1");
NexDSButton Boton2 = NexDSButton(1, 3, "Boton2");
NexDSButton Boton3 = NexDSButton(1, 4, "Boton3");
NexDSButton Boton4 = NexDSButton(1, 5, "Boton4");
NexDSButton Boton5 = NexDSButton(1, 6, "Boton5");
NexText Pitch = NexText(2, 4, "Pitch");
NexText Roll = NexText(2, 5, "Roll");
NexGauge PitchG = NexGauge(2, 1, "PitchG");
NexGauge RollG = NexGauge(2, 2, "RollG");
NexNumber Altitud = NexNumber(3, 8, "Altitud");
NexNumber Temp = NexNumber(3, 13, "Temp");
NexNumber Humedad = NexNumber(3, 15, "Humedad");
NexWaveform WaveForm = NexWaveform(3, 4, "WaveForm");
NexButton Retorno2 = NexButton(2, 3, "Retorno2");
NexButton Retorno3 = NexButton(3, 3, "Retorno3");
NexButton GoPage2 = NexButton(1, 8, "GoPage2");
NexButton GoPage3 = NexButton(1, 9, "GoPage3");
NexPage Botonera = NexPage(1, 0, "Botonera"); // Page added as a touch event
NexPage Inclinacion = NexPage(2, 0, "Inclinacion"); // Page added as a touch event
NexPage Barometrico = NexPage(3, 0, "Barometrico"); // Page added as a touch event
//***Lista de Componentes NEXTION a Escuchar***
NexTouch *nex_listen_list[] =
{
&Boton1,
&Boton2,
&Boton3,
&Boton4,
&Boton5,
&GoPage2,
&GoPage3,
&Retorno2,
&Retorno3,
&Botonera, // Pagina 1
&Inclinacion, // Pagina 2
&Barometrico, // Pagina 3
NULL
};
//***FUNCIONES Para Cambio de Paginas***
void MoveToPage1(void *ptr)
{
Botonera.show();
Serial.println("Colocar pagina 1");
Page=1;
}
void MoveToPage2(void *ptr)
{
Inclinacion.show();
Serial.println("Colocar pagina 2");
Page=2;
}
void MoveToPage3(void *ptr)
{
Barometrico.show();
Serial.println("Colocar pagina 3");
Page=3;
}
//***SETUP de Programa***
void setup() {
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
digitalWrite(Relay4, HIGH);
digitalWrite(Relay5, HIGH);
//Wire.begin();
//Wire.beginTransmission(MPU);
//Wire.write(0x6B);
//Wire.write(0);
//Wire.endTransmission(true);
nexInit();
Serial.begin(9600);
Serial.println("Iniciando...");
Retorno2.attachPop(MoveToPage1, &Retorno2);
Retorno3.attachPop(MoveToPage1, &Retorno3);
GoPage2.attachPop(MoveToPage2, &GoPage2);
GoPage3.attachPop(MoveToPage3, &GoPage3);
Boton1.attachPop(Funcion_Boton1, &Boton1);
Boton2.attachPop(Funcion_Boton2, &Boton2);
Boton3.attachPop(Funcion_Boton3, &Boton3);
Boton4.attachPop(Funcion_Boton4, &Boton4);
Boton5.attachPop(Funcion_Boton5, &Boton5);
//***Inicializacion de Sensor BMPE280***
Serial.println(!bme.begin(0x76) ? F("Error en Sensor BME280!") : F("Sensor BME280! Iniciado Correctamente"));
}
//***LOOP de Programa***
void loop() {
nexLoop(nex_listen_list);
if (Page==1){Serial.println("pagina 1");};
if (Page==2){
Serial.println("pagina 2");
////Leer los valores del Acelerometro de la IMU
// Wire.beginTransmission(MPU);
// Wire.write(0x3B); //Pedir el registro 0x3B - corresponde al AcX
// Wire.endTransmission(false);
// Wire.requestFrom(MPU,6,true); //A partir del 0x3B, se piden 6 registros
// AcX=Wire.read()<<8|Wire.read(); //Cada valor ocupa 2 registros
// AcY=Wire.read()<<8|Wire.read();
// AcZ=Wire.read()<<8|Wire.read();
//
////A partir de los valores del acelerometro, se calculan los angulos Y, X
////respectivamente, con la formula de la tangente.
// Acc[1] = atan(-1*(AcX/A_R)/sqrt(pow((AcY/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
// Acc[0] = atan((AcY/A_R)/sqrt(pow((AcX/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
//
////Leer los valores del Giroscopio
// Wire.beginTransmission(MPU);
// Wire.write(0x43);
// Wire.endTransmission(false);
// Wire.requestFrom(MPU,4,true); //A diferencia del Acelerometro, solo se piden 4 registros
// GyX=Wire.read()<<8|Wire.read();
// GyY=Wire.read()<<8|Wire.read();
//
////Calculo del angulo del Giroscopio
// Gy[0] = GyX/G_R;
// Gy[1] = GyY/G_R;
//
// dt = (millis() - tiempo_prev) / 1000.0;
// tiempo_prev = millis();
//
// Angle[0] = 0.98 *(Angle0_Previous+Gy[0]*dt) + 0.02*Acc[0];
// Angle[1] = 0.98 *(Angle1_Previous+Gy[1]*dt) + 0.02*Acc[1];
//
//Angle0_Previous=Angle[0];
//Angle1_Previous=Angle[1];
//
////Mostrar los valores por consola
// Serial.print("Angle X: "); Serial.print(Angle[0]); //Serial.print("\n");
// Serial.print("Angle Y: "); Serial.print(Angle[1]); Serial.print("\n------------\n");
//
//ang_x=Angle[0];
//ang_y=Angle[1];
//
//static char buffer[7];
//dtostrf(ang_x, 7, 2, buffer);
//Pitch.setText(buffer);
//
//dtostrf(ang_y, 7, 2, buffer);
//Roll.setText(buffer);
//
//if (ang_x >=0) {
//PitchG.setValue(ang_x);
//}
//if (ang_x < 0) {
//PitchG_Val=map(ang_x, 0, -180, 360, 180);
//PitchG.setValue(PitchG_Val);
//}
//if (ang_y >=0) {
//RollG.setValue(ang_y);
//}
//if (ang_y < 0) {
//RollG_Val=map(ang_y, 0, -180, 360, 180);
//RollG.setValue(RollG_Val);
//}
// if (ang_y >= 30){
// Roll.Set_font_color_pco(63488);
// }
// if (ang_y < 30 && ang_y > -30){
// Roll.Set_font_color_pco(1917);
// }
// if (ang_y < -30){
// Roll.Set_font_color_pco(63488);
// }
// if (ang_x >= 30){
// Pitch.Set_font_color_pco(63488);
// }
// if (ang_x < 30 && ang_x > -30){
// Pitch.Set_font_color_pco(1917);
// }
// if (ang_x < -30){
// Pitch.Set_font_color_pco(63488);
// }
//delay(10);
}
if (Page==3){
Serial.println(F("pagina 3"));
Temp.setValue(bme.readTemperature()*100);
Altitud.setValue(bme.readAltitude(SEALEVELPRESSURE_HPA)*100);
Humedad.setValue(bme.readHumidity()*100);
Altitud_Escalado = map(bme.readAltitude(SEALEVELPRESSURE_HPA), 0, 3000, 0, 121);
WaveForm.addValue(0, Altitud_Escalado);
delay(400);
};
delay(100);
}
//***FUNCIONES DE BOTONES***
void Funcion_Boton1(void *ptr)
{
uint32_t Estado_dual;
Boton1.getValue(&Estado_dual);
if(Estado_dual)
{ digitalWrite(Relay1, LOW);}
else
{ digitalWrite(Relay1, HIGH);}
}
void Funcion_Boton2(void *ptr)
{
uint32_t Estado_dual;
Boton2.getValue(&Estado_dual);
if(Estado_dual)
{ digitalWrite(Relay2, LOW);}
else
{ digitalWrite(Relay2, HIGH);}
}
void Funcion_Boton3(void *ptr)
{
uint32_t Estado_dual;
Boton3.getValue(&Estado_dual);
if(Estado_dual)
{ digitalWrite(Relay3, LOW);}
else
{ digitalWrite(Relay3, HIGH);}
}
void Funcion_Boton4(void *ptr)
{
uint32_t Estado_dual;
Boton4.getValue(&Estado_dual);
if(Estado_dual)
{ digitalWrite(Relay4, LOW);}
else
{ digitalWrite(Relay4, HIGH);}
}
void Funcion_Boton5(void *ptr)
{
uint32_t Estado_dual;
Boton5.getValue(&Estado_dual);
if(Estado_dual)
{ digitalWrite(Relay5, LOW);}
else
{ digitalWrite(Relay5, HIGH);}
}