Sign In

Published by on

After installing the maa7455 library and also getting familiar with the functions available, let us move on to writing our first demo that will show raw 8 bit measurement values read from the X,Y and Z axis.

mma7455 readings on LCD

In this demo the sensitivity is set to 2G. So if an acceleration of 2G is sensed along any axis, the readings for that axis would be close to 128. But since acceleration due to gravity is only 1G the maximum value shown along any axis would not exceed ± 64.

Bring each axis perpendicular to the earths surface such that it is parallel to the earths gravitational field. The value should come close to 64 along that axis.

The Source Code

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>

#include "lib/lcd/lcd_hd44780_avr.h"
#include "lib/mma7455/acc_mma7455_avr.h"

int main(void)
   //Initialize LCD

   //Show intro screen
   LCDWriteFStringXY(0,0,PSTR("MMA7455 Demo !"));
   LCDWriteFStringXY(0,1,PSTR("By Avinash Gupta"));



   LCDWriteFStringXY(0,0,PSTR("DEMO #1"));
   LCDWriteFStringXY(0,1,PSTR("Raw 8 bit data"));



   //Initialize the MMA7455 accelerometer
   uint8_t res;   //result of operation


      LCDWriteFStringXY(0,0,PSTR("MMA7455 Chip "));
      LCDWriteFStringXY(0,1,PSTR("NOT Found ! "));


      //wait until data is ready

      //Now take measurements    
        int8_t x,y,z;



      LCDWriteFStringXY(0,0,PSTR(" X:   Y:   Z:"));

      //Print the measured values


NOTE: To compile this program you need to install the MMA7455 library as described here. Also I2C library and LCD library must also be installed in the same manner.

NOTE: The hardware must be setup as described here.

load on as6 editor

When the MMA7455Demo1.c is loaded in the editor, copy and paste the above source code and save the file.

Now build the project using any of the following method.

  • Using the menu bar. Goto Build > Build Solution.
  • Hit F7 key on the keyboard.

If you have done everything as described, the code should compile without any problems. And finally you would get a hex file which you can burn to your xBoard MINI as described here.

NOTE: After compilation of the project, HEX file is created inside the folder Debug inside your project folder. The name of the HEX file is same as the project's name. In our case it is MMA7455Demo1.hex

We cordially thanks the following peoples who shared this page on various social networks and insprided us to develop more quality contents!