FRDM-K64 I2C-Accelerometer basic example using mbed

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

FRDM-K64 I2C-Accelerometer basic example using mbed

FRDM-K64 I2C-Accelerometer basic example using mbed

Here you will find the code and project files corresponding to the I2C-Accelerometer project. The accelerometer/magnetometer is connected to the I2C port, although bot the accelerometer and magnetometer are contained within a single package, they must be initialized individually. In this example the measurements from both devices (X,Y and Z axis) is performed and displayed at the serial terminal.

In order to compile the project, the following library must be imported:

  • FXOS8700Q.h

Code:

#include "mbed.h"

#include "FXOS8700Q.h"

//I2C lines for FXOS8700Q accelerometer/magnetometer

FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);

FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);

//Temrinal enable

Serial pc(USBTX, USBRX);

MotionSensorDataUnits mag_data;

MotionSensorDataUnits acc_data;

int main()

{

    float faX, faY, faZ;

    float fmX, fmY, fmZ;

    acc.enable();

    printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());

    while (true)

    {

        acc.getAxis(acc_data);

        mag.getAxis(mag_data);

        printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f  ", acc_data.x, acc_data.y, acc_data.z);

        printf("    MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z);

        acc.getX(&faX);

        acc.getY(&faY);

        acc.getZ(&faZ);

        mag.getX(&fmX);

        mag.getY(&fmY);

        mag.getZ(&fmZ);

        printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f  ", faX, faY, faZ);

        printf("    MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ);

       

        wait(1.0);

    }

}

附件
评论

Hi Pedro,

I'm trying to edit this code so it outputs data every 0.1 seconds instead of 1 second. I changed the wait(1.0); to wait(0.1);. But I'm not sure how to build a binary file from it. Do you think you could help me out?

Thanks!!

无评分
版本历史
最后更新:
‎06-27-2014 11:22 AM
更新人: