3.5 TFT OLED Display goes white when reading data from sensors

Hey there, I’m currently making an autonomous temperature checking machine for my school using Arduino Uno and a couple of sensors like APDS-9960 (proximity) and MLX90614 (temperature). The wiring is fine and the machine works well in terms of outputting correct information. However, I haven’t been able to output data from the sensors to the 3.5 TFT OLED display I bought; as simple as even initializing a variable in the void loop section to retrieve the value from the APDS-9960 or MLX90614 would make the display go white. When I remove any related code to the sensor, excluding the initialization, the screen is able to show texts and shapes, however when I add code related to the sensors, the screen just goes white as I’ve said before.

#include <Wire.h>
#include <SparkFun_APDS9960.h>
#include <Adafruit_MLX90614.h>
#include "U8glib.h"
#include "Adafruit_GFX.h"
#include "MCUFRIEND_kbv.h"
#include "Fonts/FreeSans9pt7b.h"
#include "Fonts/FreeSerif12pt7b.h"
#include "FreeDefaultFonts.h"
#include "Adafruit_ILI9341.h" 

//OLED Display
MCUFRIEND_kbv tft;
//Proximity Sensor
SparkFun_APDS9960 apds = SparkFun_APDS9960();
//Temperature Sensor
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

uint8_t proximity_data = 0;
double temp = 0.0;

void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg, int color)
{
  int16_t x1, y1;
  uint16_t wid, ht;
  //tft.setFont(f);
  tft.setCursor(x, y);
  tft.setTextColor(color);
  tft.setTextSize(sz);
  tft.print(msg);
}

void outputMessage(uint8_t mode) 
{
  switch (mode) {
    case 1:
      showmsgXY(150, 80, 3, &FreeSans9pt7b, "TEMPERATURE", 0x7E0);
      showmsgXY(195, 120, 3, &FreeSans9pt7b, "36.50", 0xFFFF);
      showmsgXY(282, 110, 2, &FreeSans9pt7b, "o", 0xFFFF);
      showmsgXY(292, 120, 3, &FreeSans9pt7b, "C", 0xFFFF);
      break;
    case 2:
      showmsgXY(110, 100, 4, &FreeSans9pt7b, "Move Closer!", ILI9341_RED);
      break;
   case 3:
      showmsgXY(110, 100, 4, &FreeSans9pt7b, "Move Further!", ILI9341_RED);
      break;
      
  }
}

void setup() {
  
  Serial.begin(9600);
  delay(100);
  Serial.println();
  Serial.println(F("--------------------------------------------"));
  Serial.println(F("APDS-9960 - Proximity Sensor: Initialization"));
  Serial.println(F("--------------------------------------------"));
  
  // Initialize APDS-9960 (configure I2C and initial values)
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9960 init!"));
  }
  
  // Adjust the Proximity sensor gain
  if ( !apds.setProximityGain(PGAIN_2X) ) {
    Serial.println(F("Something went wrong trying to set PGAIN on APDS-9960"));
  }
  
  // Start running the APDS-9960 proximity sensor (no interrupts)
  if ( apds.enableProximitySensor(false) ) {
    Serial.println(F("APDS-9960 initialization complete!"));
  } else {
    Serial.println(F("Something went wrong during sensor init!"));
  }
  
  tft.reset();
  uint16_t ID = tft.readID();
  tft.begin(ID);
  tft.setRotation(1);
  tft.fillScreen(0x000);

  //outputMessage(2);

  Serial.println();
  Serial.println(F("--------------------------------------"));
  Serial.println(F("MLX90614 - Temp Sensor: Initialization"));
  Serial.println(F("--------------------------------------"));

  if ( mlx.begin() ) {
     Serial.println(F("MLX90614 initialization complete!"));
  } else {
    Serial.println(F("Something went wrong during MLX90614 init!"));
  }
}

void loop() {
   // Commented out so that the display is able to output information.
  //temp = mlx.readObjectTempC();
      
  if (temp < 37.50 ) {
    outputMessage(1);
    Serial.print("Body Temperature = "); Serial.print(averageTemp); Serial.println("*C");
    Serial.println();
    averageTemp = 0.0;
    delay(1500);
    
  } else if ( temp >= 37.50 ) {
    outputMessage(4);
    Serial.print("Fever Temperature: "); Serial.print(averageTemp); Serial.println("*C");
    Serial.println();
    averageTemp = 0.0;
    delay(1500);
  }

}

Help is appreciated! :slight_smile:

It is always wise to post a link(s) to your hardware e.g. Ebay sale page.
Your screen is a TFT not an OLED.

I am guessing that you have an Mcufriend Uno Shield like this Blue TFT
And a APDS-9960
And a Overview | Using Melexis MLX90614 Non-Contact Sensors | Adafruit Learning System

Your problem is down to your sensors using I2C.
The TFT screen uses A4 pin for LCD_RST.
I2C on a Uno uses A4 for SDA

Either move to a different Arduino or make a hardware mod to the TFT shield.
It is a sad fact that the parallel TFT uses too many pins.

Thanks for posting your sketch nicely formatted.
You only need to include header files that you are actually using e.g.

#include <Wire.h>                       //using I2C devices
#include <SparkFun_APDS9960.h> //yes
#include <Adafruit_MLX90614.h>  //yes
#include "U8glib.h"        //NOT USED
#include "Adafruit_GFX.h" //yes
#include "MCUFRIEND_kbv.h"   //yes
#include "Fonts/FreeSans9pt7b.h" //
#include "Fonts/FreeSerif12pt7b.h" //
#include "FreeDefaultFonts.h"  //
#include "Adafruit_ILI9341.h"  //NOT USED

MCUFRIEND_kbv uses GFX graphics. And defines colours like TFT_RED, TFT_BLACK, …
which is safer than ILI9341_RED, …

There is no harm in including unused Font files. If you might change to Adafruit_ILI9341 one day, just comment the include statement e.g. with //

David.

david_prentice:
It is always wise to post a link(s) to your hardware e.g. Ebay sale page.
Your screen is a TFT not an OLED.

I am guessing that you have an Mcufriend Uno Shield like this Blue TFT
And a APDS-9960
And a Overview | Using Melexis MLX90614 Non-Contact Sensors | Adafruit Learning System

Your problem is down to your sensors using I2C.
The TFT screen uses A4 pin for LCD_RST.
I2C on a Uno uses A4 for SDA

Either move to a different Arduino or make a hardware mod to the TFT shield.
It is a sad fact that the parallel TFT uses too many pins.

Thanks for posting your sketch nicely formatted.
You only need to include header files that you are actually using e.g.

#include <Wire.h>                       //using I2C devices

#include <SparkFun_APDS9960.h> //yes
#include <Adafruit_MLX90614.h> //yes
#include “U8glib.h” //NOT USED
#include “Adafruit_GFX.h” //yes
#include “MCUFRIEND_kbv.h” //yes
#include “Fonts/FreeSans9pt7b.h” //
#include “Fonts/FreeSerif12pt7b.h” //
#include “FreeDefaultFonts.h” //
#include “Adafruit_ILI9341.h” //NOT USED



MCUFRIEND_kbv uses GFX graphics. And defines colours like TFT_RED, TFT_BLACK, ...
which is safer than ILI9341_RED, ...

There is no harm in including unused Font files. If you might change to Adafruit_ILI9341 one day, just comment the include statement e.g. with `//`

David.

Hi David, thanks for replying! Also, sorry about the wrongly said device name!

Yes, the TFT LCD display and the sensor is exactly what I’m using right now, but for the temperature sensor, I’m using a GY-906 integrated with MLX90614 (I’m a bit new to Arduino, so forgive me for my lack of knowledge on proper technical terms :slight_smile: ). The MLX90614 and APDS-9960 sensor is connected to the SDL and SCA pins (not A4 and A5!) in the Arduino Uno, and if the TFT screen uses the A4 pin instead of the SDA pin, the screen should’ve worked properly, right?

Oh and thanks for the tips on redundant file includes, I was using an OLED display before so I needed to use the u8glib library.

Edit: pic of SDA and SCL pins

SCL and SDA share the same port pins (PC5, PC4) with Analog A5, A4 on a Uno. That is the problem.

You can snip the LCD_RST pin on the TFT shield but need to solder a 10k resistor between LCD_RST and 5V.
Fairly easy on a 2.4 inch because the top of the shield header pins is visible. On your 3.5 inch shield you can't see the top of the header pins.

David.