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