debug

Dependencies:   mbed mbed-rtos PinDetect X_NUCLEO_53L0A1

Committer:
astovall21
Date:
Wed Apr 28 17:44:45 2021 +0000
Revision:
0:ea1c50666fc2
debug;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
astovall21 0:ea1c50666fc2 1 #include "mbed.h"
astovall21 0:ea1c50666fc2 2 #include "XNucleo53L0A1.h"
astovall21 0:ea1c50666fc2 3 #include <stdio.h>
astovall21 0:ea1c50666fc2 4 #include "rtos.h"
astovall21 0:ea1c50666fc2 5 #include "LSM9DS1.h"
astovall21 0:ea1c50666fc2 6
astovall21 0:ea1c50666fc2 7 #define VL53L0_I2C_SDA p28
astovall21 0:ea1c50666fc2 8 #define VL53L0_I2C_SCL p27
astovall21 0:ea1c50666fc2 9
astovall21 0:ea1c50666fc2 10
astovall21 0:ea1c50666fc2 11 DigitalOut myled(LED1);
astovall21 0:ea1c50666fc2 12
astovall21 0:ea1c50666fc2 13 Serial pc(USBTX,USBRX);
astovall21 0:ea1c50666fc2 14 DigitalOut shdn(p26);
astovall21 0:ea1c50666fc2 15
astovall21 0:ea1c50666fc2 16 static XNucleo53L0A1 *board=NULL;
astovall21 0:ea1c50666fc2 17
astovall21 0:ea1c50666fc2 18
astovall21 0:ea1c50666fc2 19 int main()
astovall21 0:ea1c50666fc2 20 {
astovall21 0:ea1c50666fc2 21 float tempC;
astovall21 0:ea1c50666fc2 22 int status;
astovall21 0:ea1c50666fc2 23 uint32_t distance;
astovall21 0:ea1c50666fc2 24 uint32_t last_distance;
astovall21 0:ea1c50666fc2 25 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
astovall21 0:ea1c50666fc2 26 /* creates the 53L0A1 expansion board singleton obj */
astovall21 0:ea1c50666fc2 27 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
astovall21 0:ea1c50666fc2 28 shdn = 0; //must reset sensor for an mbed reset to work
astovall21 0:ea1c50666fc2 29 wait(0.1);
astovall21 0:ea1c50666fc2 30 shdn = 1;
astovall21 0:ea1c50666fc2 31 wait(0.1);
astovall21 0:ea1c50666fc2 32 LSM9DS1 lol(p9, p10, 0xD6, 0x3C);
astovall21 0:ea1c50666fc2 33 lol.begin();
astovall21 0:ea1c50666fc2 34 if (!lol.begin()) {
astovall21 0:ea1c50666fc2 35 pc.printf("Failed to communicate with LSM9DS1.\n");
astovall21 0:ea1c50666fc2 36 }
astovall21 0:ea1c50666fc2 37 lol.calibrate();
astovall21 0:ea1c50666fc2 38 /* init the 53L0A1 board with default values */
astovall21 0:ea1c50666fc2 39 status = board->init_board();
astovall21 0:ea1c50666fc2 40
astovall21 0:ea1c50666fc2 41 while (status)
astovall21 0:ea1c50666fc2 42 {
astovall21 0:ea1c50666fc2 43 pc.printf("Failed to init board! \r\n");
astovall21 0:ea1c50666fc2 44 status = board->init_board();
astovall21 0:ea1c50666fc2 45 }
astovall21 0:ea1c50666fc2 46 //loop taking and printing distance
astovall21 0:ea1c50666fc2 47 while (1)
astovall21 0:ea1c50666fc2 48 {
astovall21 0:ea1c50666fc2 49
astovall21 0:ea1c50666fc2 50 if (board->sensor_centre->get_distance(&distance) == VL53L0X_ERROR_NONE)
astovall21 0:ea1c50666fc2 51 {
astovall21 0:ea1c50666fc2 52 if(distance != last_distance)
astovall21 0:ea1c50666fc2 53 {
astovall21 0:ea1c50666fc2 54 pc.printf("D=%ld mm\r\n", distance);
astovall21 0:ea1c50666fc2 55 }
astovall21 0:ea1c50666fc2 56 board->sensor_centre->get_distance(&last_distance);
astovall21 0:ea1c50666fc2 57 }
astovall21 0:ea1c50666fc2 58 lol.readTemp();
astovall21 0:ea1c50666fc2 59 lol.readMag();
astovall21 0:ea1c50666fc2 60 lol.readGyro();
astovall21 0:ea1c50666fc2 61
astovall21 0:ea1c50666fc2 62 //pc.printf("%d %d %d %d %d %d %d %d %d\n\r", lol.calcGyro(lol.gx), lol.calcGyro(lol.gy), lol.calcGyro(lol.gz), lol.ax, lol.ay, lol.az, lol.mx, lol.my, lol.mz);
astovall21 0:ea1c50666fc2 63 //pc.printf("%d %d %d\n\r", lol.calcGyro(lol.gx), lol.calcGyro(lol.gy), lol.calcGyro(lol.gz));
astovall21 0:ea1c50666fc2 64 pc.printf("gyro: %d %d %d\n\r", lol.gx, lol.gy, lol.gz);
astovall21 0:ea1c50666fc2 65 pc.printf("accel: %d %d %d\n\r", lol.ax, lol.ay, lol.az);
astovall21 0:ea1c50666fc2 66 pc.printf("mag: %d %d %d\n\n\r", lol.mx, lol.my, lol.mz);
astovall21 0:ea1c50666fc2 67 myled = 1;
astovall21 0:ea1c50666fc2 68 wait(2);
astovall21 0:ea1c50666fc2 69 myled = 0;
astovall21 0:ea1c50666fc2 70 wait(2);
astovall21 0:ea1c50666fc2 71 // tempC = myTMP36;
astovall21 0:ea1c50666fc2 72 // pc.printf("Float operator overloading avoids .read(): T=%5.2F C \n\r", tempC);
astovall21 0:ea1c50666fc2 73 // pc.printf("A Printf arg needs a float type convert: T=%5.2F C \n\r", float(myTMP36));
astovall21 0:ea1c50666fc2 74 // pc.printf("Or Use .read() instead: T=%5.2F C \n\r\n\r", myTMP36.read());
astovall21 0:ea1c50666fc2 75 // wait(.5);
astovall21 0:ea1c50666fc2 76
astovall21 0:ea1c50666fc2 77 }
astovall21 0:ea1c50666fc2 78
astovall21 0:ea1c50666fc2 79 }