ESP8266 i2c problems.

Hello i have one of these eps8266-12 boards with a oled on it here. The problem I have is that I’m trying to use the bme280 temperature sensor on it. And the problem is that the i2c pins are only going to the oled GPIO04 and GPIO05. there is no broken out pins for i2c . Crazy thing is that there are 2 pins on there the board say scl and sda but they are not i2c pins they come up as GPIO02 and GPIO14. SO what i did was i did a Wire.begin(2,14); in the bme280 sketch and ran that sketch. that works fine no problem. But if i try the oled sketch with that Wire.begin(2,14); in it Oled doesn’t work. if i comment out the wire.begin and re-upload the sketch the oled works but the bme280 doesn’t Here is the sketch below.

#include <stdint.h>
#include "SparkFunBME280.h"
//Library allows either I2C or SPI, so include both.
#include "Wire.h"
#include "SPI.h"
#include <Arduino.h>
#include <U8g2lib.h>
//Global sensor object
BME280 mySensor;
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);  // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED
void setup()
{
  Wire.begin(02,14);
    u8g2.begin();
 mySensor.settings.commInterface = I2C_MODE;
  mySensor.settings.I2CAddress = 0x76;
mySensor.settings.runMode = 3; //Normal mode
mySensor.settings.tStandby = 0;
mySensor.settings.filter = 0;
  mySensor.settings.tempOverSample = 1;
 mySensor.settings.pressOverSample = 1;
 mySensor.settings.humidOverSample = 1;
  Serial.begin(115200);

  uint8_t memCounter = 0x80;
  uint8_t tempReadData;
  for(int rowi = 8; rowi < 16; rowi++ )
  {
    Serial.print("0x");
    Serial.print(rowi, HEX);
    Serial.print("0:");
    for(int coli = 0; coli < 16; coli++ )
    {
      tempReadData = mySensor.readRegister(memCounter);
      Serial.print((tempReadData >> 4) & 0x0F, HEX);//Print first hex nibble
      Serial.print(tempReadData & 0x0F, HEX);//Print second hex nibble
      Serial.print(" ");
      memCounter++;
    }
    Serial.print("\n");
  }
}
void loop(){
  u8g2.clearBuffer();          // clear the internal memory
  u8g2.setFont(u8g2_font_logisoso32_tr);  // choose a suitable font
  //u8g2.drawStr(0,32, mySensor.readTempC(), 2);  // write something to the internal memory
  u8g2.setCursor (0, 32);
 // u8g2.print(mySensor.readTempC(), 2);
  u8g2.sendBuffer();          // transfer internal memory to the display
delay(1000);
}

Not sure what to do can someone please help me? I don’t know what to do I’m beyond lost.

Joseph

I once made a sketch with a ESP12, BME280 and ILI9341 2.4" TFT. The BME and TFT use Adafruit librarys. The BME is connected to pins 2 and 4. The TFT uses SPI, and for CS and DC also pins 2 and 4. There is not much i/o on an ESP board...

So I am mixing I2C and SPI on the same pins, and that gave some weird problem similar like yours. Altough not exactly the same setup, perhaps this may help.

//put this before accesssing the BME
...
digitalWrite(2, LOW); // this is not the same as pinmode!
digitalWrite(4, LOW);
pinMode(4, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);

temp = bme.readTemperature(); 
...

I suppose you could solve some things digging into the librarys, but that gives problems if there is an update. I have forgotten why i put the remark in the first line but that was the only way I could get it working. Don't know if it will work on pins 2 and 14. But for the ESP, I2C is not hardware.

I put this in the setup

void setup()
{
digitalWrite(2, LOW); // this is not the same as pinmode!
digitalWrite(4, LOW);
pinMode(4, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);

temp = bme.readTemperature(); 
  Wire.begin(02,14);
    u8g2.begin();
 mySensor.settings.commInterface = I2C_MODE;
  mySensor.settings.I2CAddress = 0x76;
mySensor.settings.runMode = 3; //Normal mode
mySensor.settings.tStandby = 0;
mySensor.settings.filter = 0;
  mySensor.settings.tempOverSample = 1;
 mySensor.settings.pressOverSample = 1;
 mySensor.settings.humidOverSample = 1;
  Serial.begin(115200);

  uint8_t memCounter = 0x80;
  uint8_t tempReadData;
  for(int rowi = 8; rowi < 16; rowi++ )
  {
    Serial.print("0x");
    Serial.print(rowi, HEX);
    Serial.print("0:");
    for(int coli = 0; coli < 16; coli++ )
    {
      tempReadData = mySensor.readRegister(memCounter);
      Serial.print((tempReadData >> 4) & 0x0F, HEX);//Print first hex nibble
      Serial.print(tempReadData & 0x0F, HEX);//Print second hex nibble
      Serial.print(" ");
      memCounter++;
    }
    Serial.print("\n");
  }
}

and i get this error

WARNING: Category ‘Language’ in library ArduinoStreaming is not valid. Setting to ‘Uncategorized’
C:\Users\mypc\AppData\Local\Temp\arduino_modified_sketch_283843\sketch_feb17b.ino: In function ‘void setup()’:

sketch_feb17b:20: error: ‘temp’ was not declared in this scope

temp = bme.readTemperature();

^

sketch_feb17b:20: error: ‘bme’ was not declared in this scope

temp = bme.readTemperature();

^

Multiple libraries were found for “Wire.h”
Used: C:\Users\mypc\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\Wire
Not used: C:\Users\mypc\Documents\Arduino\libraries\Wire
exit status 1
‘temp’ was not declared in this scope

I think the issue may be that the sensor and the display are using the same i2c address. You can change the i2c address of the screen by running this command.

void U8G2::setI2CAddress(uint8_t adr)

Eg..

u8g2.setI2CAddress(0x3C * 2);

Using your original code, but it before u8g2.begin();

Your BMP280 should run on the SPI bus HSPI or the I2C bus.

Have you tried running the BMP on the SPI buss?

My problem, with combined pins for SPI an d I2C was that after the display was updated, I2C communication stopped working. SPI left the pins for CS and DC in an undefined state if they afterwards was used for I2C.

Therefore, I had sort of to reset these pins (for I2C).

The piece of code has to be placed before every acces to the BME. Not in setup.

boys, read the post before answering

OP has I2C OLED display on board wired to esp8266 default I2C pins io 4, io 5. and the pins are not accessible on board

he has an I2C device he wants to attach to the board. he used pins io 2 and io 14.

now if the library is initialized with default pins, the display works. if it is initialized with io 2 and 14 the attached device works. of course.

Hello this is the temperature sensor i have Here.

Pertinax: My problem, with combined pins for SPI an d I2C was that after the display was updated, I2C communication stopped working. SPI left the pins for CS and DC in an undefined state if they afterwards was used for I2C.

Therefore, I had sort of to reset these pins (for I2C).

The piece of code has to be placed before every acces to the BME. Not in setup.

I use a BMP280 on an ESP32 with SPI, works great.

HSPI connection: bmp = ESP cs = gpio15 sda = mosi = gpio13 sdo = miso = gpio12 sck = sck = gpio14 I, also, use an OLED device and a 2nd SPI device on the VSPI bus.

Hello idahowaler the bme280 i do have is Here.

There is something weird in the description of this seller.
The picture shown is normally used for the BMP280 chip, so no humidity.
The price is also very low for a BME280.

If you read the description, at the end it says
"Package Include:1*BMP280 Atmospheric Pressure Sensor Temperature Humidity Sensor Breakout

But that is not why you have problems.

Hello that is not the same seller i bought mine from. Mine does have temperature humidity and pressure all in one sensor.

Just a update i got everything to work now. The silkscreen on the PCB board is misleading I had to go by what the eBay image they said for the pinout And it says oled is on these pins. and also the same pins are broken out near the power pins they are the i2c D4 and D5 pins.

|500x423