How can I create a Labview program to read the acceleration

How can I create a Labview program to read the acceleration of an accelerometer (adxl321) using arduino uno
How can I create a Labview program to read the acceleration of an accelerometer (adxl321) using arduino uno

Solution

>>Include and use appropriate library code.

#include <Wire.h>
#include \"ADXL321.h\"
/*Function: Write a byte to the register of the ADXL321*/
void ADXL321::write(uint8_t _register, uint8_t _data)
{
Wire.begin();
Wire.beginTransmission(ADXL321_ADDR);
Wire.write(_register);
Wire.write(_data);
Wire.endTransmission();
}
/*Function: Read a byte from the regitster of the ADXL321*/
uint8_t ADXL321::read(uint8_t _register)
{
uint8_t data_read;
Wire.begin();
Wire.beginTransmission(ADXL321_ADDR);
Wire.write(_register);
Wire.endTransmission();
Wire.beginTransmission(ADXL321_ADDR);
Wire.requestFrom(ADXL321_ADDR,1);
while(Wire.available())
{
data_read = Wire.read();
}
Wire.endTransmission();
return data_read;
}
void ADXL321::init()
{
setMode(ADXL321_STAND_BY);
setSampleRate(AUTO_SLEEP_32);
setMode(ADXL321_ACTIVE);
}
void ADXL321::setMode(uint8_t mode)
{
write(ADXL321_MODE,mode);
}
void ADXL321::setSampleRate(uint8_t rate)
{
write(ADXL321_SR,rate);
}
/*Function: Get the contents of the registers in the ADXL321*/
/* so as to calculate the acceleration. */
void ADXL321::getXYZ(int8_t *x,int8_t *y,int8_t *z)
{
unsigned char val[3];
int count = 0;
val[0] = val[1] = val[2] = 64;
while(Wire.available() > 0)
Wire.read();
Wire.requestFrom(ADXL321_ADDR,3);
while(Wire.available())
{
if(count < 3)
{
while ( val[count] > 63 ) // reload the accelerometer//
{
val[count] = Wire.read();
}
}
count++;
}
*x = ((char)(val[0]<<2))/4;
*y = ((char)(val[1]<<2))/4;
*z = ((char)(val[2]<<2))/4;
}
void ADXL321::getAcceleration(float *ax,float *ay,float *az)
{
int8_t x,y,z;
getXYZ(&x,&y,&z);
*ax = x/21.00;
*ay = y/21.00;
*az = z/21.00;
}

How can I create a Labview program to read the acceleration of an accelerometer (adxl321) using arduino uno How can I create a Labview program to read the accel
How can I create a Labview program to read the acceleration of an accelerometer (adxl321) using arduino uno How can I create a Labview program to read the accel

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site