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.
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.
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();
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.
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.
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
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.