gpt4 book ai didi

python - Adafruit MMA8451 加速计给我的 Raspberry Pi osError [Errno 121] 远程 I/O 错误

转载 作者:行者123 更新时间:2023-12-02 04:20:46 27 4
gpt4 key购买 nike

我在 Raspberry Pi 3 B+ 上运行 python3.5。带显示屏。

我的项目正在获取一个简单的加速度计来打印其值。我正在关注以下tutorial :我什至在 /boot/config.txt 的末尾添加了 dtoverlay=spi1-3cs 来激活另一个硬件 SPI 端口,因为我将 Pi 与显示器一起使用。

我正在尝试运行以下代码,但出现以下错误。

我已经运行了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 显示垃圾/损坏的数据。解决办法是Pi和加速度计之间的地线有故障。一旦修复此问题,设备就会正确响应。

关于python - Adafruit MMA8451 加速计给我的 Raspberry Pi osError [Errno 121] 远程 I/O 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53733298/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com