4180Lab2Part16

Dependencies:   mbed 4DGL-uLCD-SE X_NUCLEO_53L0A1

Committer:
khuifang2202
Date:
Wed Feb 06 04:40:52 2019 +0000
Revision:
13:4500aa092029
Parent:
11:5186cc367be0
huifang

Who changed what in which revision?

UserRevisionLine numberNew contents of line
khuifang2202 13:4500aa092029 1 // Wiring Diagram:
khuifang2202 13:4500aa092029 2
khuifang2202 13:4500aa092029 3 // uLCD:
khuifang2202 13:4500aa092029 4 // Mbed uLCD
khuifang2202 13:4500aa092029 5 // Vu +5V (Vu is the 5v output pin on mbed)
khuifang2202 13:4500aa092029 6 // p13 TX (RX on ribbon cable)
khuifang2202 13:4500aa092029 7 // p14 RX (TX on ribbon cable)
khuifang2202 13:4500aa092029 8 // GND GND
khuifang2202 13:4500aa092029 9 // p30 RES
khuifang2202 13:4500aa092029 10
johnAlexander 0:ce8359133ae6 11 #include "mbed.h"
khuifang2202 13:4500aa092029 12 #include "XNucleo53L0A1.h" //ToF
khuifang2202 13:4500aa092029 13 #include "uLCD_4DGL.h" //lcd
johnAlexander 0:ce8359133ae6 14 #include <stdio.h>
4180_1 11:5186cc367be0 15 Serial pc(USBTX,USBRX);
4180_1 11:5186cc367be0 16 DigitalOut shdn(p26);
4180_1 11:5186cc367be0 17 // This VL53L0X board test application performs a range measurement in polling mode
4180_1 11:5186cc367be0 18 // Use 3.3(Vout) for Vin, p28 for SDA, p27 for SCL, P26 for shdn on mbed LPC1768
johnAlexander 0:ce8359133ae6 19
4180_1 11:5186cc367be0 20 //I2C sensor pins
4180_1 11:5186cc367be0 21 #define VL53L0_I2C_SDA p28
4180_1 11:5186cc367be0 22 #define VL53L0_I2C_SCL p27
johnAlexander 0:ce8359133ae6 23
khuifang2202 13:4500aa092029 24 //lcd
khuifang2202 13:4500aa092029 25 uLCD_4DGL uLCD(p13,p14,p30); // serial tx, serial rx, reset pin;
khuifang2202 13:4500aa092029 26
Davidroid 10:891e10d3b4a6 27 static XNucleo53L0A1 *board=NULL;
johnAlexander 1:3483e701ec59 28
johnAlexander 0:ce8359133ae6 29 int main()
4180_1 11:5186cc367be0 30 {
4180_1 11:5186cc367be0 31 int status;
4180_1 11:5186cc367be0 32 uint32_t distance;
johnAlexander 7:c8087e7333b8 33 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
johnAlexander 7:c8087e7333b8 34 /* creates the 53L0A1 expansion board singleton obj */
Davidroid 10:891e10d3b4a6 35 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
4180_1 11:5186cc367be0 36 shdn = 0; //must reset sensor for an mbed reset to work
4180_1 11:5186cc367be0 37 wait(0.1);
4180_1 11:5186cc367be0 38 shdn = 1;
4180_1 11:5186cc367be0 39 wait(0.1);
4180_1 11:5186cc367be0 40 /* init the 53L0A1 board with default values */
johnAlexander 7:c8087e7333b8 41 status = board->init_board();
4180_1 11:5186cc367be0 42 while (status) {
khuifang2202 13:4500aa092029 43 //pc.printf("Failed to init board! \r\n");
khuifang2202 13:4500aa092029 44 uLCD.printf("Failed to init board! \r\n");
4180_1 11:5186cc367be0 45 status = board->init_board();
johnAlexander 7:c8087e7333b8 46 }
4180_1 11:5186cc367be0 47 //loop taking and printing distance
4180_1 11:5186cc367be0 48 while (1) {
johnAlexander 7:c8087e7333b8 49 status = board->sensor_centre->get_distance(&distance);
johnAlexander 9:9733cfdb0a18 50 if (status == VL53L0X_ERROR_NONE) {
khuifang2202 13:4500aa092029 51 //pc.printf("D=%ld mm\r\n", distance);
khuifang2202 13:4500aa092029 52 uLCD.printf("D=%ld mm\r\n", distance);
johnAlexander 7:c8087e7333b8 53 }
4180_1 11:5186cc367be0 54 }
johnAlexander 0:ce8359133ae6 55 }