ESP32, BME280, TFT_eSPI - BME280 data incorrect

Looking for a second set of eyes here...

When not invoking the TFT, BME280 data in Serial Monitor is correct

14:30:26.203 -> Temperature = 69.08°F / 20.60°C
14:30:26.271 -> Pressure = 29.71 inHg
14:30:26.271 -> Approx. Altitude = 197.65 ft
14:30:26.301 -> Humidity = 51.25 %

When I invoke TFT_eSPI and try to get the same data, everything is static and grossly incorrect (as below)...
14:30:37.487 -> Temperature = 374.20°F / 190.11°C
14:30:37.487 -> Temperature = 374.20°F / 190.11°C
14:30:37.505 -> Temperature = 374.20°F / 190.11°C
14:30:37.552 -> Temperature = 374.20°F / 190.11°C

Code:

#include <SPI.h>
#include <TFT_eSPI.h>
#include <Wire.h>
#include <Adafruit_BME280.h>


#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5

#define TFT_GREY 0x5AEB
#define WHITE       0xFFFF
#define BLACK       0x0000
#define SEALEVELPRESSURE_HPA (1013.25)


TFT_eSPI tft = TFT_eSPI();
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

void setup() {
  Serial.begin(9600);
  unsigned bmeStatus;
  bmeStatus = bme.begin(); 
  if (!bmeStatus) {
      Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
      Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
      Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
      Serial.print("        ID of 0x60 represents a BME 280.\n");
      while (1) delay(10);
  }
  tft.init();
  tft.setRotation(0);
  tft.setCursor(0, 0,);
  tft.setTextColor(TFT_GREEN);
  tft.setTextFont(4);
  tft.println("TFT Ready");
}

void loop() {
  Serial.print("Temperature = ");
  Serial.print(convertBME('F'));
  printDegree();
  Serial.print("F ");
  Serial.print(" / ");
  Serial.print(convertBME('C'));
  printDegree();
  Serial.println("C ");

  tft.setTextColor(TFT_GREEN);
  tft.setTextFont(2);
  tft.println(convertBME('F'));
}

float convertBME(char type) {
  float wxValue;
  float temp      = bme.readTemperature();
  float pressure  = bme.readPressure();
  float relHum    = bme.readHumidity();
  float altitude  = bme.readAltitude(SEALEVELPRESSURE_HPA);

  if(type == 'F') {
    wxValue = temp * 9.0/5.0 +32; // Fahrenheit Conversion
  } else if(type == 'H') {
    wxValue = relHum; // Relative Humidity
  } else if(type == 'B') {
    wxValue = pressure;
  } else if(type == 'M') {
    wxValue = pressure * 0.029529983071445; // Pressure to inHg
  } else if (type == 'A') {
    wxValue = altitude * 3.280839895; // Approximate Altitude
  } else {
    wxValue = temp; // return default temp
  }
  return wxValue;
}

void printDegree() {
  Serial.print("\xC2");
  Serial.print("\xB0");
}

Any thoughts on why this is happening?

Also: If I pull the MISO from the BME280 (Pin 18 on ESP32), the same happens, but the numbers are now hundreds of "degrees" below zero (i.e., -260.xx for F).

Also: I can do a variety of things on the TFT without the BME280 being invoked. So it is working correctly.

TIA

how do you power the various system components?
upload a schematic showing the wiring and how the system is powered

Powered via 3V3 and GND

--- BME280 ---
BME_SCK 18
BME_MISO 19
BME_MOSI 23
BME_CS 5

--- TFT ---
NOT CONNECTED TFT_MISO 19 // (leave TFT SDO disconnected if other SPI devices share MISO)
TFT_MOSI 23
TFT_SCLK 18
TFT_CS 15 // Chip select control pin
TFT_DC 2 // Data Command control pin
TFT_RST 4 // Reset pin (could connect to RST pin)

Are you sharing the SPI channel for both? Put also the TFT GPIO's configuration.
You could also connect the BME280 with I2C, with just SCL, SDA pins. But would be one more pin in the MCU.

1 Like

Your BME280 is hooked up via software SPI.

And it's on the same pins as the hardware SPI that I imagine your display is using.

That's not going to work.

Use hardware SPI for both.

1 Like

That did it. I reworked the wiring, separating the TFT and BME280 onto separate systems, and now things appear to be working.

Thank you all for the fast and useful responses. Great community here.

It should work also together, but with the correct wiring. Sometimes it's difficult to clarify the names of the pins in the TFT displays, it's a mess. And don't mix any cable.

But if you separate the channels, use just SDA and SCL for the BME280.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.