ruggedBOARD
Tutorial Using Python
Tutorial Using Python
  • Overview
  • Quick Start with RB
    • Pre-Requisite
      • Required Hardware and Software Components
      • Host Setup
      • Linux Commands
    • Power Up your RB
    • Fiddle with RB Command-line
  • Lib-Mraa & UPM Sensor Libraries (Python)
    • First Python Program
    • Know Your Libraries
      • LibMRAA
        • Python Programming using MRAA (SPI)
        • Python Programming using MRAA (PWM)
        • Python Programming using MRAA (gpio_blink)
        • Python Programming using MRAA (Aio)
      • LibUPM
    • Example Programs for Sensors
      • Procedure to interface phyNODE with RB
      • Accelerometer
      • Temperature Sensor
      • Pressure Sensor
      • Humidity Sensor
      • Magnetometer
      • PIR Sensor
      • Ultrasonic Sensor
      • Gas Sensor (MQ5)
    • mikroBUS UPM Sensor
    • Example programs for Communication Protocols
      • GPIO
      • I2C
      • UART
  • Hello World in C language
    • Setting up Environment
    • Transferring Files from Host to Board
    • Write your first C program
  • IoT Implementation
    • What is IoT?
    • IoT Protocols
    • MQTT Setup
  • Peripherals Functionality Testing using C Language
    • Interfaces
      • GPIO(General purpose Input/Output):
      • UART(Universal Asynchronous Receiver-Transmitter)
      • RS232
      • RS485
      • CAN
      • MikroBUS
      • mPCIe
  • Advance RB
    • Preparing SD card in case of OS failure
Powered by GitBook
On this page

Was this helpful?

  1. Lib-Mraa & UPM Sensor Libraries (Python)
  2. Example Programs for Sensors

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

PreviousProcedure to interface phyNODE with RBNextTemperature Sensor

Last updated 6 years ago

Was this helpful?