0

I've been struggeling allday to get I²C and SPI working on the same time on my Wemos D1 Mini Pro, i want to use a BME280 + the Wemos D1 Mini 1,4' TFT Shield.

If i comment one or the other out, the sensor or the display work fine. But as soon as both buses are active the must be some kind of races condition, sometimes the display works but the Sensor one return NaN or the display freezes and the sensor returns valid data.

When the display works it seems like i2c aka Wire.h crashes and cant even i do a i2c scan, when i tried it while debugging and get errors on every address.

I'm pretty sure Wire.h and Spi.h collide some how.

#include <BME280I2C.h>
#include <Wire.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

#define TFT_CS     D4
#define TFT_RST    -1  // you can also connect this to the Arduino reset
#define TFT_DC     D3

#define I2C_SDL    D1
#define I2C_SDA    D2

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);
BME280I2C bme;

void setup(void) {

  Serial.begin(9600);  
  while(!Serial) {} // Wait

  Wire.setClock(400000L);
  Wire.begin(I2C_SDL, I2C_SDA);

  while(!bme.begin()){
    Serial.println("Could not find BME280 sensor!");
    delay(250);
  }

  switch(bme.chipModel())
  {
    case BME280::ChipModel_BME280:
      Serial.println("Found BME280 sensor! Success.");
      break;
    case BME280::ChipModel_BMP280:
      Serial.println("Found BMP280 sensor! No Humidity available.");
      break;
    default:
      Serial.println("Found UNKNOWN sensor! Error!");
  } 

  tft.initR(INITR_144GREENTAB);
  tft.setTextWrap(false); // Allow text to run off right edge
  tft.fillScreen(ST7735_BLACK);

}

void loop(void) {
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(ST7735_BLUE);
  tft.setTextSize(2);
  tft.println("Hello World");
  tft.setRotation(tft.getRotation()+1);
  delay(1000);

  printBME280Data(&Serial);
  delay(3000);
}

void printBME280Data(Stream* client) {
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);

   bme.read(pres, temp, hum, tempUnit, presUnit);

   client->print("Temp: ");
   client->print(temp);
   client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->println(" Pa");

}
  • is not a power issue? – Juraj May 26 '18 at 18:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.