check program for VL53L0X_simple library
Dependencies: VL53L0X_simple TextLCD
Please refer below page.
/users/kenjiArai/notebook/vl53l0x-tof-sensor/
Diff: main.cpp
- Revision:
- 1:45891160ccab
- Parent:
- 0:da0fdf120892
- Child:
- 2:f675507dcad3
--- a/main.cpp Sun Feb 04 02:45:35 2018 +0000 +++ b/main.cpp Mon Feb 05 22:38:59 2018 +0000 @@ -25,7 +25,7 @@ * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ * Created: January 21st, 2018 - * Revised: Feburary 4th, 2018 + * Revised: Feburary 6th, 2018 (with updated VL53L0X_simple library) */ // Include -------------------------------------------------------------------- @@ -42,9 +42,9 @@ #if 1 //I2C i2c(P0_30, P0_7); // only for TY51822r3 I2C i2c(I2C_SDA, I2C_SCL); -VL53L0X sensor(i2c, D9); // XSHUT = NC +VL53L0X sensor(i2c, D8); // XSHUT = D8 #else -//VL53L0X sensor(I2C_SDA, I2C_SCL, D9); // use XShut pin +//VL53L0X sensor(I2C_SDA, I2C_SCL, D8); // use XShut pin VL53L0X sensor(I2C_SDA, I2C_SCL, NC); // XSHUT = NC #endif #if USE_LCD @@ -55,8 +55,8 @@ // RAM ------------------------------------------------------------------------ // ROM / Constant data -------------------------------------------------------- -char *const msg0 = "\r\nVL53L0X is running correctly!!\r\n"; -char *const msg1 = "\r\nVL53L0X -> something is wrong!!\r\n"; +char *const msg0 = "VL53L0X is running correctly!!\r\n"; +char *const msg1 = "VL53L0X -> something is wrong!!\r\n"; char *const msg2 = "#,"; char *const msg3 = "d[mm]=,"; char *const msg4 = "d[mm]=,error,"; @@ -87,6 +87,12 @@ lcd.setContrast(0x19); wait(2.0f); #endif + status = sensor.init_sensor(0x33); // set new I2C address + if (status == VL53L0X_ERROR_NONE) { + pc.printf(msg0); + } else { + pc.printf(msg1); + } status = sensor.set_mode(range_long_distance_33ms_200cm); //status = sensor.set_mode(range_hi_accurate_200ms_120cm); //status = sensor.set_mode(range_hi_speed_20ms_120cm);