Buenos días.
Primero saludar a todos los del foro.
Estoy usando una pantalla 2.4" TFT LCD SHIELD ILI9325, tambien el arduino UNO y un sensor GY - BM 280(conectado a los pines D19/SCL y D18/SDA). Adjunto foto de los componenes.
Tengo el siguiente problema:
Cuando quiero imprimir en la pantalla TFT las lecturas bme.readTemperature(), bme.readHumidity y bme.readPressure. Dejo el código abreviado del problema.
//LIBRERIAS SENSOR
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
//LIBRERIAS TFT
#include <Adafruit_GFX.h> // Core graphics library
#include <MCUFRIEND_kbv.h> // Hardware-specific library
#include <Fonts/FreeSans12pt7b.h>
#include <FreeDefaultFonts.h>
#include <TouchScreen.h>
//MACRO TFT
#define BLACK 0x0000 // Color negro
#define WHITE 0xFFFF // Color blanco
#define GREY 0x8410 // Color griz
#define NUEVO 0xEEEE // Color dorado
#define VERDEOSCURO 0x03E0 // Color verde oscuro
#define MINPRESSURE 200 // Presiòn mìnima del touch
#define MAXPRESSURE 1000 // Presiòn màxima del touch
//OBJETOS
Adafruit_BME280 bme;
MCUFRIEND_kbv tft;
Adafruit_GFX_Button on_btn, off_btn;
//VARIABLE SENSOR
float temperature;
float pressure;
float humidity;
// Todos las pantalla tàctiles y cableados son diferentes
// Abrir el ejemplo TouchScreen_Calibr_native.ino de MCUFRIEND_kbv
// Recordar que debes mantener apretado en cuadrado con cruz en el interior de color blanco para una buena calibraciòn
// Copia y pega los resultados obtenidos, recordar si usas la pantalla en modo retrato(VERTICAL) o paisaje(HORIZONTAL)
const int XP = 8, XM = A2, YP = A3, YM = 9; //240x320 ID=0x9328
const int TS_LEFT = 158, TS_RT = 893, TS_TOP = 116, TS_BOT = 909;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
//LECTURA DE COORDENADAS TACTILES
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY() {
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); // Restaura pines compartidos
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); // Activa la interfaz de la pantalla tàctil
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE); // Verifica si el toque es valido en funciòn de la presiòn
if (pressed) {
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); // Mapea las coordenas en el eje X
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height()); // Mapea las coordenas en el eje Y
}
return pressed;
}
//ACTUALIZA LA PANTALLA POR SI HAY CAMBIO
bool actualizacion = true;
void setup() {
Serial.begin(9600);
//INICIAR EL SENSOR BME 280
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
//INICIAR LA PANTALLA TFT
uint16_t ID = tft.readID(); // Lee el ID de la pantalla gràfica
Serial.println("found ID = 0x");
Serial.print(ID, HEX);
if (ID == 0xD3D3) ID = 0x9325; // Verifica el ID y lo cambia a 0x9325
tft.begin(ID); //Se configura e inicia la pantalla TFT
//ROTACION DE LA PANTALLA TFT Y COLOR DE FONDO
tft.setRotation(0); // Con el botòn RESET en la parte superior
tft.fillScreen(BLACK); // Fondo de pantalla color negro
//BOTÒN DE MÌNIMOS Y MÀXIMOS
on_btn.initButton(&tft, 120, 290, 120, 40, RED, RED, WHITE, "MIN/MAX", 2);
on_btn.drawButton(false);
}
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg) {
int16_t x1, y1;
uint16_t wid, ht;
//tft.drawFastHLine(0, y, tft.width(), WHITE);
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(WHITE);
tft.setTextSize(sz);
tft.print(msg);
}
void loop(){
unsigned long currentMillis = millis();
unsigned long startTime = millis();
bool down = Touch_getXY();
//temperature = bme.readTemperature();
//pressure = bme.readPressure() / 100.0F;
//humidity = bme.readHumidity();
on_btn.press(down && on_btn.contains(pixel_x, pixel_y));
if (on_btn.justReleased())
on_btn.drawButton();
if (on_btn.justPressed()) {
on_btn.drawButton(true);
}
tft.fillRect(0, 0, 240, 19, GREY);
showmsgXY(55, 1, 2.2, NULL, "TEMPERATURA");
tft.fillRect(0, 87, 240, 19, GREY);
showmsgXY(80, 88, 2.2, NULL, "PRESION");
tft.fillRect(0, 174, 240, 19, GREY);
showmsgXY(80, 175, 2.2, NULL, "HUMEDAD");
tft.setCursor(70, 35);
tft.setTextSize(5);
tft.print(temperature);
tft.setCursor(70, 124);
tft.setTextSize(5);
tft.print(pressure);
tft.setCursor(70, 204);
tft.setTextSize(5);
tft.print(humidity);
Serial.println(temperature);
Serial.println(pressure);
Serial.println(humidity);
Serial.println("______________");
delay(2000);
}
Adjunto foto del buen funcionamiento de la pantalla y touch.
Cuando descomente esta parte del código la pantalla se pondrá en color blanco la pantalla TFT, el Monitor Serial registra con normalidad los valores de Temperatura, Presión y Humedad.
temperature = bme.readTemperature();
pressure = bme.readPressure() / 100.0F;
humidity = bme.readHumidity();
Agradezco la ayuda que me puedan brindar, gracias de antemano.




