LCD and I2c Problems

Hi all

I hope someone can help as I have been trying to fathom this out all weekend.

So originally I had a little setup of a Oled display and a BME280 Humidity/Temperature sensor, both running on I2c, on my Arduino Uno, which worked great.

However the display was a bit too small to be honest, so I found a nice 2.4" TFT LCD and thought that would look great, I looked around the web a came upon a project using the TFT and a standard DHT sensor

Link is here to see it plus code after

Start of code

#include <SPFD5408_Adafruit_GFX.h>    // Core graphics Adafruit library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>     // Touchscreen library

#include "DHT.h"
#define DHTPIN A7
#define DH);
// *** Define Touchscreen Pin
#define YP A3 
#define XM A2 
#define YM 9   
#define XP 8   
// *** Define Value of Touchscreen input
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

// *** Define Pin of LCD used
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET PC6

// *** Define Name of Color
#define BLACK   0x0000
#define WHITE   0xFFFF
#define RED     0xF800
#define GREEN   0x07E0
#define BLUE    0x001F
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define GREY    0x2108
#define MINPRESSURE 10
#define MAXPRESSURE 1000

// Meter colour schemes
#define RED2RED 0
#define GREEN2GREEN 1
#define BLUE2BLUE 2
#define BLUE2RED 3
#define GREEN2RED 4
#define RED2GREEN 5

uint32_t runTime = -99999;       // time for next update
int reading = 0; // Value to be displayed
int d = 0; // Variable used for the sinewave test waveform
boolean alert = 0;
int8_t ramp = 1;
int tesmod =0;
void setup() {

First thing I discovered was the LCD was using pin A4 to do a reset, but this is used by I2c, so that wont work, done some Googling and found a solution where you hardwire the reset the LCD reset pin to the main reset pin on the Arduino, see picture.

That seemed to work great, then into the code I just added the 2 lines for the BME280 sensor

#include “Seeed_BME280.h”
BME280 bme280;

When I now upload the LCD displays everything correctly as before, however the back light is flashing crazily on and off, if I remove the two lines of code, everything is grand again.

Any ideas greatfully appreciated.

Cheers Alan

Try this Libray for your BME280 alone.Execute an example program from the IDE. And then, slowly add codes with your display program. This approach may help you to isolate the problem.

Hi Golam

Just tried that.

Just added the #include <BlueDot_BME280.h>

Uploaded again and the backlight flickering like crazy.

Remove that line and everything works as normal.

I really have no idea what is going on!

Just to isolate the problem, can you try placing an I2CLCD (normal 16x2 Text LCD) instead of your graphics LCD. I2CLCD also has a back-light. Use this library for the I2CLCD.

Hi Golam

I knew that a normal i2c lcd will work, but I want to use this TFT screen as I can make some fancy graphics etc.

But that's not the point, I can't see why the back light flickers like crazy, just because I added a new library, if I remo8it the backlight goes back to normal.

I even looked through the BME280 code to see if there were a y conflicts, but can't see any.

As I said it seems to make no sense