Hello to everyone!
I am doing a very simple code for displaying some data in my 2.4 tft lcd screen.
I am trying to plot some data, the first would be a reading from a HMC5883L
Theres something strange going on with the code. I can run my setup with no loop and the display performs as expected.
However when i am running the code with the loop, i am getting a white blank display.
Is there any problem between the display and the sensor?
I am posting my code below.
thanks
Fede
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup() {
mag.begin();
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Serial.begin(9600);
tft.reset();
tft.begin(0x9341);
tft.setRotation(0);
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.setCursor(105, 5);
tft.println("TWD");
tft.setCursor(90, 30);
tft.setTextSize(4);
tft.setTextColor(WHITE);
tft.println("000"); //REEMPLAZAR CON WIND VALUE
tft.drawLine(0,70,240,70, WHITE);
tft.drawLine(0,71,240,71, WHITE);
tft.setTextSize(2);
tft.setCursor(105, 80);
tft.println("AVG");
tft.setCursor(90, 105);
tft.setTextSize(4);
tft.setTextColor(WHITE);
tft.println("000"); //REEMPLAZAR CON WIND AVG
tft.drawLine(0,150,240,150, WHITE);
tft.drawLine(0,151,240,151, WHITE);
tft.setTextSize(2);
tft.setCursor(105, 160);
tft.println("E.T.");
}
void loop() {
sensors_event_t event;
mag.getEvent(&event);
float heading = atan2(event.magnetic.y, event.magnetic.x);
float declinationAngle = 0.017;
heading += declinationAngle;
// Correct for when signs are reversed.
if(heading < 0)
heading += 2*PI;
// Check for wrap due to addition of declination.
if(heading > 2*PI)
heading -= 2*PI;
float headingDegrees = heading * 180/M_PI;
int ete = millis()/1000;
tft.setTextSize(4);
tft.setCursor(90, 190);
tft.println(heading,0);
tft.fillRect(80,180,95,50, BLACK);
delay(1000);
}```