X893

Add accelerometer data to GPS Tracking data

I decide add 3-axis accelerometer to GM862 tracker and send data to local GpsGate server. Firstly i check this chip (LIS3LV02DL) on standalone microprocessor. I try two variant of microprocessors - ATmega168 (Arduino clone) and EmbeddedMaster (non-TFT).





Prepare accelerometer sensor to use I2C protocol

and connect to ATmega168 (Arduino) board

This code read data from sensor and work fine (now without interrupts from sensor)

#include 

#define OUTX_L 0x28
#define OUTX_H 0x29
#define OUTY_L 0x2A
#define OUTY_H 0x2B
#define OUTZ_L 0x2C
#define OUTZ_H 0x2D

#define XAXIS 0
#define YAXIS 1
#define ZAXIS 2

int ledPin = 13;                // LED connected to digital pin 13
volatile int state = LOW;

void setup()
{
        pinMode(ledPin, OUTPUT);
        digitalWrite(ledPin, state);   // sets the LED on

        attachInterrupt(0, int0_Handler, RISING);

	Serial.begin(19200);
        Serial.println("Start");

	Wire.begin();        // join i2c bus (address optional for master)
	Wire.beginTransmission( 0x1D );
	Wire.send( 0x20 );    // CTRL_REG1 ( 20h )
	Wire.send( 0x87 );    // Device on, 40hz, normal mode, all axis's enabled
	Wire.endTransmission();

	Wire.beginTransmission( 0x1D );
	Wire.send( 0x0F);
	Wire.endTransmission();

	Wire.requestFrom( 0x1D, 1 );
	while ( Wire.available() < 1 ) {
            delay(10);
        }

	byte who = Wire.receive();
        Serial.print("WHO_AM_I:");
	Serial.println( who, HEX );

        
}

void int0_Handler()
{
    state = !state;
    digitalWrite(ledPin, state);
}

void loop()
{
	int val[3];

	// transmit to device with address 0x1D
	// according to the LIS3L* datasheet, the i2c address of is fixed
	// at the factory at 0011101b (0x1D)
	Wire.beginTransmission( 0x1D );
	// send the sub address for the *first* register we want to read
	// this is for the OUTX_L register
	// set the MSB so we can do multiple reads, with the register address auto-incremented
	Wire.send( OUTX_L | 0x80);
	// stop transmitting
	Wire.endTransmission();

	// Now do a transfer reading six bytes from the LIS3L*
	// This data will be the contents of the X Y and Z registers
	Wire.requestFrom( 0x1D, 6 );
	while ( Wire.available() < 6 ) {
		// this isn't really necessary
		// a better thing to do would be to set up an onReceive handler,
		// buffer the data and go off and do something else if the data isn't ready
		delay( 5 );
	}

	// read the data
	for ( int i = 0; i < 3; i++ ) {
		// read low byte
		byte low = Wire.receive();
		// read the high byte
		val[i] = ( Wire.receive() << 8 ) + low;
	}

	// do something with the values
        Serial.println("---------------------");
	Serial.print(  " x_val = " );
	Serial.println( val[XAXIS], DEC );
	Serial.print(  " y_val = " );
	Serial.println( val[YAXIS], DEC );
	Serial.print(  " z_val = " );
	Serial.println( val[ZAXIS], DEC );

	delay( 250 );
}

On EmbeddedMaster i use C# code to check sensor and also work fine. After successfully check sensor i connect it to GM862 tracker

To be continued ...

0 comment(s) so far

Post your comment

Thanks for your comments

  • Comment

Github
Bitbucket
SF.net

Skype
Telegram

Subscribe to x893 blog Subscribe