我在运行python3.5,使用的是覆盆子pi3b+。有显示器。在
我的项目是得到一个简单的加速计来打印它的值。
我遵循下面的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)
错误如下:
^{pr2}$
目前没有回答
相关问题 更多 >
编程相关推荐