BMP280 ServiceSpecificException: I/O error (code 5)

*爱你&永不变心* 提交于 2021-01-27 14:56:28

问题


I try to use AndroidThings to measure temperature with Raspberry Pi 3 and BMP280.

3,3V i have choosed because of specification of BMP280:

To power the board, give it the same power as the logic level of your microcontroller

Then i want to initialize sensor

mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1");

And by execution i receive following exeption

Error configuring sensor
    com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error (code 5)
    at com.google.android.things.pio.I2cDeviceImpl.readRegByte(I2cDeviceImpl.java:81)
    at com.google.android.things.contrib.driver.bmx280.Bmx280.connect(Bmx280.java:215)
    at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:193)
    at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:180)
    at com.google.android.things.contrib.driver.bmx280.Bmx280SensorDriver.<init>(Bmx280SensorDriver.java:55)

Also by 5V Power i receive the same exception.

I have found this. But i have no idea how to check, if the BMP280 is realy connected to Raspberry with adb.

By own testing the connectivity i receive by device.readRegByte(0xD0) the same exeption.

Does it mean, that BMP280 is not correctly connected? If yes, how to correctly connect BMP280 with Raspberry?

Is some resistor needed by connection?

UPDATE

solved by soldering BMP280 with header strip.

Also to work with sensor is permission requiered that could be granded only in command line. ref

adb shell pm grant app.package com.google.android.things.permission.MANAGE_SENSOR_DRIVERS


回答1:


Looking at your fritzing diagram you had SDO connected to BCM3?

From the datasheet the SDO pin is what determins the address of your sensor.

Connecting SDO to GND results in slave address 1110110 (0x76); connection it to VDDIO results in slave address 1110111 (0x77)

Most importantly:

The SDO pin cannot be left floating; if left floating, the I²C address will be undefined.

com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error (code 5)

Therefore your problem is likely an undefined i2c address.

Looking at the code you are using for the Bmx280SensorDriver, it uses the address 0x77

https://github.com/androidthings/contrib-drivers/blob/master/bmx280/src/main/java/com/google/android/things/contrib/driver/bmx280/Bmx280.java#L48

Therefore you should ensure your SDO line is connected to 5V on your raspberry pi. This will ensure your sensor has the correct address.

Or alternatively connect SDO to Ground and use this constructor:

mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1", 0x76);

If you want to understand what the sensor driver is doing "under the hood" there is a great blog post and repo to see that:

http://blog.blundellapps.co.uk/tut-android-things-temperature-sensor-i2c-on-the-rainbow-hat/

https://github.com/blundell/androidthings-i2c-input/blob/master/app/src/main/java/com/blundell/tut/MainActivity.java

;-)




回答2:


Thanks for informations, for right connection

bmx280 = new Bmx280("I2C1",0x76); and SDO to gnd.

But read values is strange.

myweatherstation D/statie: temp: 186.83298 pres: -296.47287

Is possible to be sensor damaged?

TNX

Cris




回答3:


To read data from IoT Device, the contact should be fixed without any loose connection.

This could be only reached with soldering of BMP280 with header strip

Only then the connection could be etablished



来源:https://stackoverflow.com/questions/47869657/bmp280-servicespecificexception-i-o-error-code-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!