Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: APDS_9960 LPS22HB LSM9DS1 HTS221
Diff: 2_check_LSM9DS1/main2.cpp
- Revision:
- 0:f1a10797d9f6
- Child:
- 1:cce280da16d4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2_check_LSM9DS1/main2.cpp Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,84 @@ +/* + * Mbed Application program + * Nano 33 BLE Sense board runs on mbed-OS5 + * LSM9DS1 -> iNEMO inertial module: + * 3D accelerometer, 3D gyroscope, 3D magnetometer + * by STMicroelectronics + * + * Copyright (c) 2020 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Started: January 22nd, 2020 + * Revised: Feburary 5th, 2020 + */ + +// Pre-selection -------------------------------------------------------------- +#include "select_example.h" +//#define EXAMPLE_2_CHECK_LSM9DS1 +#ifdef EXAMPLE_2_CHECK_LSM9DS1 + +// Include -------------------------------------------------------------------- +#include "mbed.h" +#include "nano33blesense_iodef.h" +#include "LSM9DS1.h" + +// Definition ----------------------------------------------------------------- + +// Constructor ---------------------------------------------------------------- +RawSerial pc(STDIO_UART_TX, STDIO_UART_RX, 115200); +DigitalOut sen_pwr(PIN_VDD_ENV, 1); +DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1); +I2C i2c(PIN_SDA1, PIN_SCL1); +LSM9DS1 *imu = NULL; +Timer t; + +// RAM ------------------------------------------------------------------------ + +// ROM / Constant data -------------------------------------------------------- + +// Function prototypes -------------------------------------------------------- +extern void check_i2c_connected_devices(void); + +//------------------------------------------------------------------------------ +// Control Program +//------------------------------------------------------------------------------ +int main() +{ + i2c_pullup = 1; + sen_pwr = 1; + pc.printf("\r\nCheck LSM9DS1\r\n"); + thread_sleep_for(200); + check_i2c_connected_devices(); + imu = new LSM9DS1(PIN_SDA1, PIN_SCL1); + uint16_t reg = imu->begin(); + pc.printf("IMU(LSM9DS1) 0x%x\r\n", reg); + imu->calibration(); + // check I2C line + check_i2c_connected_devices(); + if (reg == 0x683d){ + pc.printf("ACC+GYR+MAG are ready!\r\n"); + } else { + pc.printf("ACC+GYR+MAG are NOT ready!\r\n"); + } + uint32_t n = 0; + while(true) { + t.reset(); + t.start(); + imu->readAccel(); + imu->readGyro(); + imu->readMag(); + imu->readTemp(); + pc.printf("acc = %+5.3f, %+5.3f, %+5.3f, ", imu->ax, imu->ay, imu->az); + pc.printf("gyr = %+8.3f, %+8.3f, %+8.3f, ", imu->gx, imu->gy, imu->gz); + pc.printf("mag = %+5.3f, %+5.3f, %+5.3f, ", imu->mx, imu->my, imu->mz); + pc.printf("temperature = %+5.1f, ", imu->temperature_c); + ++n; + uint32_t passed_time = t.read_ms(); + pc.printf("processing time: %d [ms], count: %4d\r\n", passed_time, n); + if (passed_time < 199){ + thread_sleep_for(200 - t.read_ms()); + } + } +} + +#endif // EXAMPLE_2_CHECK_LSM9DS1 \ No newline at end of file