簡體   English   中英

Adafruit MMA8451 加速度計給我的 Raspberry Pi osError [Errno 121] 遠程 I/O 錯誤

[英]Adafruit MMA8451 accelerometer giving my Raspberry Pi osError [Errno 121] Remote I/O error

我在 Raspberry Pi 3 B+ 上運行 python3.5。 帶顯示器。

我的項目正在獲取一個簡單的加速度計來打印其值。 我下面下列教程:我甚至加入dtoverlay=spi1-3cs到的末尾/boot/config.txt來激活其他硬件SPI端口作為我用我裨具有顯示器。

我正在嘗試運行以下代碼,但出現以下錯誤。

我已經運行i2cdetect -y -1 它顯示了一個地址為 1d 的設備。

我檢查了我的連接和一切,不確定我做錯了什么。

    # Simple demo of reading the MMA8451 orientation every second.
# Author: Tony DiCola
import time

import board
import busio
import adafruit_mma8451
# Initialize I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Initialize MMA8451 module.
sensor = adafruit_mma8451.MMA8451(i2c)
# Optionally change the address if it's not the default:
##sensor = adafruit_mma8451.MMA8451(i2c, address=0x1d)

# Main loop to print the acceleration and orientation every second.
while True:
    x, y, z = sensor.acceleration
    print('Acceleration: x={0:0.3f}m/s^2 y={1:0.3f}m/s^2 z={2:0.3f}m/s^2'.format(x, y, z))
    orientation = sensor.orientation

    print('Orientation: ', end='')
    if orientation == adafruit_mma8451.PL_PUF:
        print('Portrait, up, front')
    elif orientation == adafruit_mma8451.PL_PUB:
        print('Portrait, up, back')
    elif orientation == adafruit_mma8451.PL_PDF:
        print('Portrait, down, front')
    elif orientation == adafruit_mma8451.PL_PDB:
        print('Portrait, down, back')
    elif orientation == adafruit_mma8451.PL_LRF:
        print('Landscape, right, front')
    elif orientation == adafruit_mma8451.PL_LRB:
        print('Landscape, right, back')
    elif orientation == adafruit_mma8451.PL_LLF:
        print('Landscape, left, front')
    elif orientation == adafruit_mma8451.PL_LLB:
        print('Landscape, left, back')
    time.sleep(1.0)

錯誤如下:

Traceback (most recent call last):
  File "simpletest.py", line 15, in <module>
    sensor = adafruit_mma8451.MMA8451(i2c)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_mma8451.py", line 103, in __init__
    while self._read_u8(_MMA8451_REG_CTRL_REG2) & 0x40 > 0:
  File "/usr/local/lib/python3.5/dist-packages/adafruit_mma8451.py", line 134, in _read_u8
    self._read_into(address, self._BUFFER, count=1)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_mma8451.py", line 130, in _read_into
    in_end=count, stop=False)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bus_device/i2c_device.py", line 149, in write_then_readinto
    in_start=in_start, in_end=in_end, stop=stop)
  File "/home/pi/.local/lib/python3.5/site-packages/busio.py", line 68, in writeto_then_readfrom
    in_start=in_start, in_end=in_end, stop=stop)
  File "/home/pi/.local/lib/python3.5/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 63, in writeto_then_readfrom
    readin = self._i2c_bus.read_i2c_block_data(address, buffer_out[out_start:out_end][0], in_end-in_start)
  File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_PureIO/smbus.py", line 215, in read_i2c_block_data
    ioctl(self._device.fileno(), I2C_RDWR, request)
OSError: [Errno 121] Remote I/O error

我的 Pi 和加速度計 - 設備在使用i2cdetect時顯示同樣的問題,但無法使用 Adafruit 的代碼或i2cget獲取數據。 i2cdump顯示垃圾/損壞的數據。 解決辦法是樹莓派和加速度計之間的地線有問題。 修復此問題后,設備會正確響應。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM