AnsweredAssumed Answered

Reading acceleration from ADXL345 with PIC32

Question asked by Valdo on May 29, 2013
Latest reply on May 31, 2013 by DragosB

Hello,

 

I am working on something for my own purposes. I would just like to have acceleration data displayed on my computer using the ADXL345. I am not trying to do anything but be able to physically move my breadboard and be able to see the graph change. It does not have to be very accurate at all. I have browsed the forums and found much help on this matter. http://ez.analog.com/message/48998#48998.

 

 

The processor I am using is PIC32MX250F. I am still having trouble converting the acceleration reading that I am receiving from my ADXL345. I have put the accelerometer in 16g mode, with full-range accuracy. This means my conversion factor is 3.9mg/LSB. The following function is how I read in acceleration values:

 

 

void ADXL345_GetXyz(unsigned short* x,

                    unsigned short* y,

                    unsigned short* z)

{

    *x = ADXL345_GetRegisterValue(ADXL345_DATAX1) << 8; // move left by a byte

    *x += ADXL345_GetRegisterValue(ADXL345_DATAX0); // additive

 

 

    *y = ADXL345_GetRegisterValue(ADXL345_DATAY1) << 8;/* move left by a byte */

    *y += ADXL345_GetRegisterValue(ADXL345_DATAY0); // additive

   

    *z = ADXL345_GetRegisterValue(ADXL345_DATAZ1) << 8; /* move left by a byte*/

    *z += ADXL345_GetRegisterValue(ADXL345_DATAZ0); // additive

}

 

In my main code, I convert my reading in to decimal and write the value over UART to my computer:

                //CONSOLE_WriteString("x axis: ");

                itoa(tempString, x, 10);/* convert to base 10*/

                CONSOLE_WriteString(tempString);

                UART_Write(0xD);

               

                //CONSOLE_WriteString("y axis: ");

                itoa(tempString, y, 10); /* convert to base 10*/

                CONSOLE_WriteString(tempString);

                UART_Write(0xD);

 

 

                //CONSOLE_WriteString("z axis: ");

                itoa(tempString, z, 10); /* convert to base 10*/

                CONSOLE_WriteString(tempString);

                UART_Write(0xD);

 

I still have to implement the conversion factor. I would like to do this in C (MPLAB). But I am having a difficult doing this because my data types do not match up. I could use some help.

 

My end goal is to receive acceleration data and display it real-time in LabView. I am using an RS232 to USB converter to send data to my computer.

Outcomes