0

I have written the below program in python and tried to read tthe accelerometer sensor output. When I print the output of the accelerometer I am getting 1. Please advice me how to get actual output in digits to know the exact tilt of the accelerometer.

import RPi.GPIO as io # import the GPIO library we just installed but call it "io"
import time
io.setmode(io.BCM)
io.setwarnings(False)

x_axis = 17 # this is the GPIO number our accelerometer's x axis is connected
y_axis = 27 # this is the GPIO number our accelerometer's x axis is connected
z_axis = 22 # this is the GPIO number our accelerometer's x axis is connected

io.setup(x_axis, io.IN) # initialize receiver GPIO to take input
io.setup(y_axis, io.IN) # initialize receiver GPIO to take input
io.setup(z_axis, io.IN) # initialize receiver GPIO to take input

try:
    while True:
        x = io.input(x_axis)
    if x:
        print"x-axis ="
        print(x)
        time.sleep(1)

        y = io.input(y_axis)
    if y:
        print"y-axis"
        print(y)
        time.sleep(1)

        z = io.input(y_axis)
    if z:
        print"z-axis"
        print(z)
        time.sleep(1)

except KeyboardInterrupt:
    print("Received Interrupt")


output

pi@raspberrypi /opt/embedded $ sudo python accelerometer.py
x-axis =
1
y-axis
1
z-axis
1
x-axis =
1
y-axis
1
z-axis
1
x-axis =
1
y-axis
1
z-axis
1
4

2 回答 2

0

实际上 ADXL335 是一个模拟传感器,树莓派无法读取模拟值,它会读取输出为高或低以获得传感器的准确值,您应该使用与树莓派连接的 ADC(模数转换器),或者您可以使用可以读取的 Arduino 板传感器的连续值输出

于 2019-03-18T16:51:06.033 回答
0

您可能会考虑 Joan 的简短程序,用于此处发布的略有不同的 IMU

https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=139584&p=949755#p949755

有一个美好的下午!:)

于 2016-04-14T18:25:16.937 回答