exposure wrote:Hi,
I failed for 3 days to make a I2C sensor playing ball with my ESP-201 board. I also couldn't find in the net a working example of a ESP-201 with an I2C sensor. It's always different boards (ESP-01, ESP-12) where people connect something else or use LUA but not straight Arduino code.
I'm using this:
- Arduino IDE 1.6.9
- ESP8266 (Community) library v2.2.0
- EspFan's library (https://github.com/finitespace/BME280/)
- GY-BMEP breakout board with Bosch BME280
I connected SDA > GPIO4 and SCL > GPIO5 which should also be the default pins in the wire library as far as I understand.
I'm a bit of a newbie...
So, ya - that should work - NOTE that gy bmep defaults to address 0x76. I think the libraries default to 77 and thats why you arent seeing it.
Two suggestions. I can not speak for the libaries you are using. I use both adafruit BME280 and GY bmep - and started with the adafruit so I use the adafruit library. It works for both devices but the adafruit devices (and libarary) defaults to 77 and the gy bmep defaults to 76.
So suggestion 1 - use the adafruit bme library. Make sure to use the correct address in the begin statement - this sketch is tested with the devicess and wiring you indicate you are using.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
void setup() {
Serial.begin(115200);
Serial.println(F("BME280 test"));
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
delay(2000);
}
Suggestion 2 - if you still can't see it try using the I2c scanner sketch to see if you are getting anything:
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
//
http://www.gammon.com.au/forum/?id=10896// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
I expect the 1st sample sketch will solve your problem. Good luck!