Accelerometer
MMA8X5X
Code to interface Accelerometer(MMA8X5X) using python
#!/usr/bin/env python
from __future__ import print_function
import time, sys,atexit
from upm import pyupm_mma8x5x as MMA8X5X
def main():
# Instantiate the Three-Axis Accelerometer Sensor on I2C on bus 1
mySensor = MMA8X5X.MMA8X5X(2)
data = MMA8X5X.mma8x5x_data_t()
# activate periodic measurements
mySensor.setActive();
# Print out the x, y, z value every 0.5 seconds
while(1):
mySensor.getData(data, True)
print("X-Axis : "+str(data.x),"Y-Axis : "+str(data.y),"Z-Axis : "+str(data.z))
time.sleep(.5)
if __name__ == '__main__':
main()
To run the program,
Step 1: save the file as mma8x5x.py
Step 2: Run the Program in the board's terminal using python3 mma8x5x.py
Last updated
Was this helpful?