added I2C control function (Original program cannot handle I2C constructor)
Dependencies: TextLCD X_NUCLEO_53L0A1
Fork of HelloWorld_53L0A1 by
main.cpp
00001 //------- Feburary 6th, 2018 by JH1PJL / K.Arai -------------------------------- 00002 // Tested on Nucleo-F446RE and my handmade VL53L0X board 00003 // https://os.mbed.com/users/kenjiArai/notebook/vl53l0x-tof-sensor/ 00004 #error "You will have real error when you try this sample program!!" 00005 // If you use I2C class constractor you may have an error. 00006 // You need to modify as follows. 00007 // 1) line 4 of this file -> delete or comment out 00008 // 2) /HelloWorld_53L0A1_with_I2C_device/X_NUCLEO_53L0A1/ 00009 // Components/VL53L0X/VL53L0X_i2c_platform.h 00010 // line 55 #define I2C 0x01 -> delete or comment out 00011 // line 56 #define SPI 0x00 -> delete or comment out 00012 #define ADDED 00013 //------------------------------------------------------------------------------ 00014 00015 #include "mbed.h" 00016 #ifndef ADDED 00017 #include "XNucleo53L0A1.h" 00018 #else 00019 #include "VL53L0X.h" 00020 #include "TextLCD.h" 00021 #endif 00022 #include <stdio.h> 00023 00024 /* This VL53L0X Expansion board test application performs a range measurement in polling mode 00025 on the onboard embedded top sensor. */ 00026 00027 #define VL53L0_I2C_SDA D14 00028 #define VL53L0_I2C_SCL D15 00029 00030 #ifndef ADDED 00031 static XNucleo53L0A1 *board=NULL; 00032 #else 00033 static VL53L0X *board=NULL; 00034 DigitalOut xshut(D10); // connection for XSHUT is MUST!! 00035 I2C i2c(I2C_SDA, I2C_SCL); 00036 TextLCD_I2C_N lcd(&i2c, 0x7c, TextLCD::LCD8x2); // LCD(Akizuki AQM0802A) 00037 #endif 00038 00039 /*=================================== Main ================================== 00040 =============================================================================*/ 00041 int main() 00042 { 00043 int status; 00044 uint32_t distance; 00045 00046 #ifdef ADDED 00047 lcd.locate(0, 0); 00048 // 12345678 00049 lcd.puts("12345678"); 00050 lcd.locate(0, 1); 00051 // 12345678 00052 lcd.puts(" JH1PJL "); 00053 lcd.setCursor(TextLCD_Base::CurOff_BlkOff); 00054 lcd.setContrast(0x19); 00055 wait(1.0f); 00056 #endif 00057 00058 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); 00059 00060 /* creates the 53L0A1 expansion board singleton obj */ 00061 #ifndef ADDED 00062 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2); 00063 #else 00064 //--- xshut is mandantory (if xshut=NC then not run the program) 00065 board = new VL53L0X(device_i2c, &xshut, NC); 00066 #endif 00067 #ifndef ADDED 00068 /* init the 53L0A1 expansion board with default values */ 00069 status = board->init_board(); 00070 #else 00071 status = board->init_sensor(0x33 << 1U); 00072 #endif 00073 if (status) { 00074 printf("Failed to init board!\r\n"); 00075 return 0; 00076 } 00077 while (1) { 00078 #ifndef ADDED 00079 status = board->sensor_centre->get_distance(&distance); 00080 #else 00081 status = board->get_distance(&distance); 00082 #endif 00083 if (status == VL53L0X_ERROR_NONE) { 00084 printf("Distance : %ld\r\n", distance); 00085 } 00086 #ifdef ADDED 00087 lcd.locate(0, 0); 00088 // 12345678 00089 lcd.printf("Dist.:mm"); 00090 lcd.locate(0, 1); 00091 lcd.printf(" %5d ", distance); 00092 #endif 00093 } 00094 }
Generated on Tue Jul 12 2022 21:50:43 by 1.7.2