static void app_task(void *param)
{
    int16_t a[3], m[3], t;

    printf("# Testing LSM303DLHC\n");

    printf("# Initializing LSM303DLHC...\n");
    lsm303dlhc_powerdown();

    printf("# Setting LSM303DLHC accelerometer\n");
    lsm303dlhc_acc_config(LSM303DLHC_ACC_RATE_400HZ, LSM303DLHC_ACC_SCALE_16G, LSM303DLHC_ACC_UPDATE_ON_READ);

    printf("# Setting LSM303DLHC magnetometer\n");
    lsm303dlhc_mag_config(LSM303DLHC_MAG_RATE_220HZ,
                          LSM303DLHC_MAG_SCALE_2_5GAUSS, LSM303DLHC_MAG_MODE_CONTINUOUS,
                          LSM303DLHC_TEMP_MODE_ON);

    while (1)
    {
        lsm303dlhc_read_acc(a);
        lsm303dlhc_read_mag(m);
        lsm303dlhc_read_temp(&t);

        printf("A = (%f\t%f\t%f)\n", a[0] * ACC_RES, a[1] * ACC_RES, a[2] * ACC_RES);
        printf("M = (%f\t%f\t%f)\n", m[0] * MAG_RES, m[1] * MAG_RES, m[2] * MAG_RES);
        printf("T = %f\n", t / 256.);

        vTaskDelay(configTICK_RATE_HZ / 10);
    }
}
Exemplo n.º 2
0
int main(void)
{
    lsm303dlhc_t dev;
    int16_t temp_value;
    lsm303dlhc_3d_data_t mag_value;
    lsm303dlhc_3d_data_t acc_value;

    puts("LSM303DLHC temperature test application\n");
    printf("Initializing LSM303DLHC sensor at I2C_%i... ", TEST_LSM303DLHC_I2C);

    if (lsm303dlhc_init(&dev, TEST_LSM303DLHC_I2C, TEST_LSM303DLHC_ACC_PIN, TEST_LSM303DLHC_MAG_PIN,
                        TEST_LSM303DLHC_ACC_ADDR, ACC_S_RATE, ACC_SCALE,
                        TEST_LSM303DLHC_MAG_ADDR, MAG_S_RATE, MAG_GAIN) == 0) {
        puts("[OK]\n");
    }
    else {
        puts("[Failed]");
        return 1;
    }

    while (1) {
        if (lsm303dlhc_read_acc(&dev, &acc_value) == 0) {
            printf("Accelerometer x: %i y: %i z: %i\n", acc_value.x_axis,
                                                        acc_value.y_axis,
                                                        acc_value.z_axis);
        }
        else {
            puts("\nFailed reading accelerometer values\n");
        }
        if (lsm303dlhc_read_temp(&dev, &temp_value) == 0) {
            printf("Temperature value: %i degrees\n", temp_value);
        }
        else {
            puts("\nFailed reading value\n");
        }

        if (lsm303dlhc_read_mag(&dev, &mag_value) == 0) {
            printf("Magnetometer x: %i y: %i z: %i\n", mag_value.x_axis,
                                                       mag_value.y_axis,
                                                       mag_value.z_axis);
        }
        else {
            puts("\nFailed reading magnetometer values\n");
        }

        vtimer_usleep(SLEEP);
    }

    return 0;
}
Exemplo n.º 3
0
void _get_lsm303dlhc_read_handler(int argc, char **argv)
{
    (void)argc;
    (void)argv;

    uint8_t error;
    lsm303dlhc_3d_data_t data;

    if (!lsm303_dev.acc_address || !lsm303_dev.mag_address) {
        puts("Error: please call `lsm303dlhc_init` first!");
        return;
    }

    error = lsm303dlhc_read_acc(&lsm303_dev, &data);
    if (error) {
        puts("Error reading accelerometer data from lsm303dlhc.");
        return;
    }
    else {
        printf("lsm303dlhc: Accelerometer {%i, %i, %i} mg\n", data.x_axis, data.y_axis, data.z_axis);
    }

    error = lsm303dlhc_read_mag(&lsm303_dev, &data);
    if (error) {
        puts("Error reading magnetometer data from lsm303dlhc.");
        return;
    }
    else {
        printf("lsm303dlhc: Magnetometer {%i, %i, %i}/1100 gauss\n", data.x_axis, data.y_axis, data.z_axis);
    }

    error = lsm303dlhc_read_temp(&lsm303_dev, &(data.x_axis));
    if (error) {
        puts("Error reading temperature data from lsm303dlhc.");
        return;
    }
    else {
        printf("lsm303dlhc: Temperature %i\n", data.x_axis);
    }
}