Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BME280/BMP280 sensor shows 'Wrong ID' in values section. #1672

Closed
davebuk opened this issue Apr 2, 2019 · 9 comments · Fixed by #1690
Closed

BME280/BMP280 sensor shows 'Wrong ID' in values section. #1672

davebuk opened this issue Apr 2, 2019 · 9 comments · Fixed by #1690

Comments

@davebuk
Copy link
Contributor

davebuk commented Apr 2, 2019

I have setup a Sonoff basic to use Pins 1 and 3 (Tx/Rx) for a BME280, 4 pin sensor. I have the following in custom.h

#define DEBUG_SERIAL_SUPPORT 0
#define BMX280_SUPPORT 1
#define BMX280_ADDRESS 0x00
#define I2C_SDA_PIN 1  //TX PIN
#define I2C_SCL_PIN 3  //RX PIN

Once built I get the following:

status
and at Debug I first get:

[SENSOR] Error reading data from BMP280 @ I2C (0x00) (error: 4)`
[SENSOR] Initializing BMP280 @ I2C (0x00)
[010015] [I2C] Address 0x76 locked
[010031] [SENSOR]  -> temperature:0
[010033] [SENSOR]  -> pressure:0
[010037] [SENSOR]  -> humidity:0
[030015] [SENSOR] Error reading data from BME280 @ I2C (0x76) (error: 6)

After that I then get:

[SENSOR] Error reading data from BMP280 @ I2C (0x00) (error: 4)

I have also tried setting 0x58, 0x77 and 0x76 but get the same status page as above. I guess espurna is not setting the address, or do I need to install pull up resistors on the data lines? The BME280 is connected using twisted pair twisted with positive and ground and the wires are about 1 metre long.

@davebuk
Copy link
Contributor Author

davebuk commented Apr 4, 2019

After a reboot this morning, the sensor seems to be working. The main status page is reporting correct values against BME280 @ I2C (0x00) but am still getting the following error 6 in the debug output.

[SENSOR] Initializing BMP280 @ I2C (0x00)
[SENSOR]  -> ERROR 6
[SENSOR] Initializing BMP280 @ I2C (0x00)
[SENSOR]  -> ERROR 6
[SENSOR] Initializing BMP280 @ I2C (0x00)
[SENSOR]  -> ERROR 6
[SENSOR] Error reading data from BMP280 @ I2C (0x00) (error: 4)
[SENSOR] Initializing BMP280 @ I2C (0x00)
[SENSOR]  -> ERROR 6
[SENSOR] Initializing BMP280 @ I2C (0x00)
[SENSOR]  -> ERROR 6
[SENSOR] Initializing BMP280 @ I2C (0x00)
[SENSOR]  -> ERROR 6
[SENSOR] Error reading data from BMP280 @ I2C (0x00) (error: 4)
[MQTT] Sending SonoffB005/temperature => 18.120 (PID 1)
[MQTT] Sending SonoffB005/pressure => 991.2406 (PID 1)
[MQTT] Sending SonoffB005/humidity => 51.59 (PID 1)
[SENSOR] Initializing BMP280 @ I2C (0x00)
[SENSOR]  -> ERROR 6

@mcspr
Copy link
Collaborator

mcspr commented Apr 6, 2019

My bet would be on I2C not being able to work properly over (mildly) long cable.
I've have a same sensor attached to a Basic, with ~30cm cables. No problems there.

Error code should probably be stringified... ref about 6 meaning:

#define SENSOR_ERROR_OK 0 // No error
#define SENSOR_ERROR_OUT_OF_RANGE 1 // Result out of sensor range
#define SENSOR_ERROR_WARM_UP 2 // Sensor is warming-up
#define SENSOR_ERROR_TIMEOUT 3 // Response from sensor timed out
#define SENSOR_ERROR_UNKNOWN_ID 4 // Sensor did not report a known ID
#define SENSOR_ERROR_CRC 5 // Sensor data corrupted
#define SENSOR_ERROR_I2C 6 // Wrong or locked I2C address
#define SENSOR_ERROR_GPIO_USED 7 // The GPIO is already in use
#define SENSOR_ERROR_CALIBRATION 8 // Calibration error or Not calibrated
#define SENSOR_ERROR_OTHER 99 // Any other error

@davebuk
Copy link
Contributor Author

davebuk commented Apr 7, 2019

I rewired with just a very short cable, 2-3cm and it still didn't work. After a re compile of the binary and a re flash it started working but still have the error 6 messages against BMP280 rather than the BME280 (BMP280 not fitted). I've tried again using a screened data pair approx 30cm long and the BME280 data is working, but I get a constant error 6 message every 10 seconds.

@mcspr
Copy link
Collaborator

mcspr commented Apr 8, 2019

Two POI. Inside _read, when data returns 0xffff:

if (0xFFFF == adc_T) return SENSOR_ERROR_I2C;

Inside _pre, when it tries to read chip register to determine if it is BMP or BME:
_error = SENSOR_ERROR_UNKNOWN_ID;

If we can be sure that communication is ok, maybe something there is amiss? My personal question is where does 0xffff magic come from. BME Datasheet only mentiones 0x80000 if value is "skipped"

You can also try Adafruit libraries. Note, that they have separate ones for BME and BMP:
https://github.com/adafruit/Adafruit_BME280_Library
https://github.com/adafruit/Adafruit_BMP280_Library
They expect ArduinoIDE to build things, their examples/ dir will auto populate IDE's menu. Or you can manually do a pio init -b esp01_1m and copy source there.

@davebuk
Copy link
Contributor Author

davebuk commented Apr 8, 2019

So I guess the temperature readout is giving 0xffff at some point giving the error? Maybe there is a problem with the chip I have and is outputting the incorrect values?

I'm new to all this building and compiling binaries so trying other libraries is beyond my current knowledge! 😁 I'll leave the firmware running as it is for now while it's working and have another look when I have more time to spend with the system. Thanks.

@davebuk
Copy link
Contributor Author

davebuk commented Apr 10, 2019

@mcspr @xoseperez
Think I have found the issue. After making my own error message in BaseSensor.h, the error 4 is from the 'Pre-read hook' section of BMX280Sensor.h. My guess is that espurna is looking for another sensor and is trying to get a reading and failing.

I changed the #define BMX280_NUMBER in sensor.h from 2 to 1 and compiled a new binary. There are now no more error 4 or 6 messages in the debug section of espurna web UI and the BME280 is working correctly still.

@mcspr
Copy link
Collaborator

mcspr commented Apr 10, 2019

Ok, that wasn't like this before. Updated detection & defaults based on your comment: #1690

@davebuk
Copy link
Contributor Author

davebuk commented Apr 10, 2019

When the code has been added to the dev branch I'll test and let you know. Thanks.

@davebuk
Copy link
Contributor Author

davebuk commented Apr 11, 2019

All working. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants