带有Android Things I / O错误的BME280传感器(代码5)

时间:2018-11-21 22:58:04

标签: android android-studio kotlin raspberry-pi3

目前,我正在使用Raspberry Pie 3b和BME280传感器测试Android Things平台 BME to Raspberry Pie connection

使用Bmx280驱动程序并应返回温度值的简单代码:

class DataReader: Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    try {
        Log.d("Sensor", "All ok")
        val sensor = Bmx280("I2C1", 0x77)
        sensor.temperatureOversampling = Bmx280.OVERSAMPLING_1X
        val temperature_value = sensor.readTemperature()
        Log.d("S*ensor", "Current temperature: " + temperature_value)

        sensor.pressureOversampling = Bmx280.OVERSAMPLING_1X
        val pressure_value = sensor.readPressure()
        Log.d("Sensor", "Current temperature: " + pressure_value)
    } catch (error: Exception) {
        Log.d("Sensor", "Error: " + error)
    }
}

这是我一直收到的错误消息:

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

尝试了多种方法(将BME280连接到3.3V和5V),多次检查了我的连接电路。

还尝试使用其他地址,例如:

val sensor = Bmx280("I2C1", 0x77)
val sensor = Bmx280("I2C1", 0x76)

当我尝试读取数据时,这是PIO CLI工具的输出:

rpi3:/ $ pio list i2c
I2C1
rpi3:/ $ pio i2c I2C1 0x12 read-reg-byte 0x24
[WARNING:client_errors.cc(35)] error 5: I/O error
5|rpi3:/ $ pio i2c I2C1 0x12 read-raw size
[ERROR:cli_command.cc(74)] Invalid size.

已解决:问题出在传感器的电线和插头之间。焊接在一起后,传感器按预期工作

0 个答案:

没有答案