Programma di lettura sensori compreso laser
Dependencies: HTS221 LIS3MDL LPS22HB LSM303AGR LSM6DSL VL53L0X
Fork of HelloWorld_ST_Sensors by
Revision 5:2fdca1624a33, committed 2017-10-03
- Comitter:
- mapellil
- Date:
- Tue Oct 03 14:05:43 2017 +0200
- Parent:
- 4:a876fbe13688
- Child:
- 6:6156615b89fd
- Commit message:
- Added support for targets SensorTile (through define; set target NUCLEO_L476RG), DISCO_L475VG_IOT01A, Nucleoxx+IKS01A2
Changed in this revision
--- a/LSM303AGR.lib Mon Oct 02 09:30:24 2017 +0200 +++ b/LSM303AGR.lib Tue Oct 03 14:05:43 2017 +0200 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/LSM303AGR/#e37be5550633 +https://developer.mbed.org/teams/ST/code/LSM303AGR/#652f8f67d991
--- a/LSM6DSL.lib Mon Oct 02 09:30:24 2017 +0200 +++ b/LSM6DSL.lib Tue Oct 03 14:05:43 2017 +0200 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/LSM6DSL/#578a45c4dad5 +https://developer.mbed.org/teams/ST/code/LSM6DSL/#20ccff7dd652
--- a/main.cpp Mon Oct 02 09:30:24 2017 +0200 +++ b/main.cpp Tue Oct 03 14:05:43 2017 +0200 @@ -47,6 +47,7 @@ #include "lis3mdl_class.h" #else // X-Nucleo-IKS01A2 #include "LSM303AGRMagSensor.h" +#include "LSM303AGRAccSensor.h" #endif @@ -54,95 +55,78 @@ #ifdef TARGET_DISCO_L475VG_IOT01A static DevI2C devI2c(PB_11,PB_10); -#else // X-Nucleo-IKS01A2 -//#define SPI3W_TEST // or SPI4W_TEST -#ifdef SPI3W_TEST -SPI devSPI(PB_15, NC, PB_13); // 3W -#else -#ifdef SPI4W_TEST +#else // X-Nucleo-IKS01A2 or SensorTile +#define TARGET_SENSOR_TILE // to be compiled as NUCLEO_L476RG until the target sensor tile will be created +#ifdef TARGET_SENSOR_TILE +SPI devSPI(PB_15, NC, PB_13); // 3W on SensorTile + Arduino Cradle + Nucleo (compiled as Nucleo_L476RG) +static Serial ser(PC_12,PD_2); +#define printf(...) ser.printf(__VA_ARGS__) +#else +#ifdef SPI4W_TEST SPI devSPI(PB_15, PB_14, PB_13); // 4W -#else +#else // IKS01A2 + Nucleo static DevI2C devI2c(D14,D15); +//static HTS221Sensor hum_temp(&devI2c); #endif #endif #endif -//static DevI2C devI2c(D14,D15); /** FIXME temporary **/ -static HTS221Sensor hum_temp(&devI2c); -#if defined (SPI3W_TEST) || defined (SPI4W_TEST) -#ifdef SPI3W_TEST -#define SPI_TYPE LPS22HBSensor::SPI3W +#if defined (TARGET_SENSOR_TILE) || defined (SPI4W_TEST) +#ifdef TARGET_SENSOR_TILE +#define SPI_TYPE_LPS22HB LPS22HBSensor::SPI3W +#define SPI_TYPE_LSM6DSL LSM6DSLSensor::SPI3W #else #define SPI_TYPE LPS22HBSensor::SPI4W #endif -static LPS22HBSensor press_temp(&devSPI, PA_10, NC, SPI_TYPE); +//static LPS22HBSensor press_temp(&devSPI, PA_10, NC, SPI_TYPE); +static LPS22HBSensor press_temp(&devSPI, PA_3, NC, SPI_TYPE_LPS22HB); #else // target Nucleoxxx + IKS01A2 static LPS22HBSensor press_temp(&devI2c); +static HTS221Sensor hum_temp(&devI2c); #endif #ifdef TARGET_DISCO_L475VG_IOT01A static LSM6DSLSensor acc_gyro(&devI2c,LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW,PD_11); // low address static LIS3MDL magnetometer(&devI2c); -#else // X-NUCLEO_IKS01A2 +#else // X-NUCLEO_IKS01A2 or SensTile +#if defined (TARGET_SENSOR_TILE) +static LSM6DSLSensor acc_gyro(&devSPI,PB_12, NC, PA_2, SPI_TYPE_LSM6DSL); +static LSM303AGRMagSensor magnetometer(&devSPI, PB_1); +static LSM303AGRAccSensor accelerometer(&devSPI, PC_4); +#else static LSM6DSLSensor acc_gyro(&devI2c,LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH,D4,D5); // high address static LSM303AGRMagSensor magnetometer(&devI2c); +static LSM303AGRAccSensor accelerometer(&devI2c); #endif - -/* Helper function for printing floats & doubles */ -static char *print_double(char* str, double v, int decimalDigits=2) -{ - int i = 1; - int intPart, fractPart; - int len; - char *ptr; - - /* prepare decimal digits multiplicator */ - for (;decimalDigits!=0; i*=10, decimalDigits--); - - /* calculate integer & fractinal parts */ - intPart = (int)v; - fractPart = (int)((v-(double)(int)v)*i); - - /* fill in integer part */ - sprintf(str, "%i.", intPart); - - /* prepare fill in of fractional part */ - len = strlen(str); - ptr = &str[len]; - - /* fill in leading fractional zeros */ - for (i/=10;i>1; i/=10, ptr++) { - if (fractPart >= i) { - break; - } - *ptr = '0'; - } - - /* fill in (rest of) fractional part */ - sprintf(ptr, "%i", fractPart); - - return str; -} +#endif /* Simple main function */ int main() { uint8_t id; float value1, value2; - char buffer1[32], buffer2[32]; +// char buffer1[32], buffer2[32]; int32_t axes[3]; /* Init all sensors with default params */ +#ifndef TARGET_SENSOR_TILE hum_temp.init(NULL); +#endif press_temp.init(NULL); +#ifndef TARGET_DISCO_L475VG_IOT01A magnetometer.init(NULL); + accelerometer.init(NULL); +#endif acc_gyro.init(NULL); /* Enable all sensors */ +#ifndef TARGET_SENSOR_TILE hum_temp.enable(); +#endif press_temp.enable(); #ifndef TARGET_DISCO_L475VG_IOT01A // X-NUCLEO-IKS01A2 magnetometer.enable(); + accelerometer.enable(); #endif acc_gyro.enable_x(); acc_gyro.enable_g(); @@ -150,15 +134,19 @@ printf("\033[2J\033[20A"); printf ("\r\n--- Starting new run ---\r\n\r\n"); +#ifndef TARGET_SENSOR_TILE hum_temp.read_id(&id); printf("HTS221 humidity & temperature = 0x%X\r\n", id); +#endif press_temp.read_id(&id); - printf("LPS22HB pressure & temperature = 0x%X\r\n", id); + printf("LPS22HB pressure & temperature = 0x%X\r\n", id); magnetometer.read_id(&id); #ifdef TARGET_DISCO_L475VG_IOT01A printf("LIS3MDL magnetometer = 0x%X\r\n", id); #else // X-NUCLEO-IKS01A2 printf("LSM303AGR magnetometer = 0x%X\r\n", id); + accelerometer.read_id(&id); + printf("LSM303AGR accelerometer = 0x%X\r\n", id); #endif acc_gyro.read_id(&id); printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id); @@ -168,9 +156,11 @@ while(1) { printf("\r\n"); +#ifndef TARGET_SENSOR_TILE hum_temp.get_temperature(&value1); hum_temp.get_humidity(&value2); printf("HTS221: [temp] %7f C, [hum] %f%%\r\n", value1, value2); +#endif value1=value2=0; press_temp.get_temperature(&value1); press_temp.get_pressure(&value2); @@ -183,6 +173,8 @@ printf("LIS3MDL [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); #else // X-NUCLEO-IKS01A2 printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + accelerometer.get_x_axes(axes); + printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); #endif acc_gyro.get_x_axes(axes); @@ -191,7 +183,11 @@ acc_gyro.get_g_axes(axes); printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); +#if defined (TARGET_SENSOR_TILE) || defined (TARGET_DISCO_L475VG_IOT01A) printf("\033[7A"); +#else + printf("\033[8A"); +#endif wait(1); } }