Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: VL53L1CB
Dependents: VL53L1CB_NoShield_1sensor_polling_multizone_MB6 VL53L1CB_NoShield_3sensors_interrupt_ranging_MB6 VL53L1CB_NoShield_MB6_3sensors_interrupt_ranging VL53L1CB_shield_1sensor_interrupt_auton ... more
XNucleo53L1A2.cpp
00001 /* 00002 * *** NOTE : By default hardlinks U10, U11, U15 & U18, on the underside of 00003 * the X-NUCELO-53L1A1 expansion board are not made/OFF. 00004 * These links must be made to allow interrupts from the Satellite boards 00005 * to be received. 00006 * U11 and U18 must be made/ON to allow interrupts to be received from the 00007 * INT_L & INT_R positions; or 00008 * U10 and U15 must be made/ON to allow interrupts to be received from the 00009 * Alternate INT_L & INT_R positions. 00010 * The X_NUCLEO_53L1A2 library defaults to use the INT_L/INT_R positions. 00011 * INT_L is available on expansion board Arduino Connector CN5, pin 1 as D8. 00012 * Alternate INT_L is on CN5 Connector pin 2 as D9. 00013 * INT_R is available on expansion board Arduino Connector CN9, pin 3 as D2. 00014 * Alternate INT_R is on CN9 Connector pin 5 as D4. 00015 * The pinouts are shown here : https://developer.mbed.org/components/X-NUCLEO-53L1A2/ 00016 */ 00017 00018 #include "XNucleo53L1A2.h" 00019 00020 XNucleo53L1A2 *XNucleo53L1A2::_instance = NULL; 00021 00022 00023 XNucleo53L1A2 *XNucleo53L1A2::instance(ToF_DevI2C *ext_i2c) 00024 { 00025 if (_instance == NULL) { 00026 _instance = new XNucleo53L1A2(ext_i2c); 00027 } else { 00028 printf("Failed to create XNucleo53L1A2 instance\n\r\r\n"); 00029 } 00030 return _instance; 00031 } 00032 00033 XNucleo53L1A2 *XNucleo53L1A2::instance(ToF_DevI2C *ext_i2c, 00034 PinName gpio1_centre, 00035 PinName gpio1_left, PinName gpio1_right) 00036 { 00037 if (_instance == NULL) { 00038 _instance = new XNucleo53L1A2(ext_i2c, gpio1_centre, gpio1_left, gpio1_right); 00039 } else { 00040 printf("Failed to create XNucleo53L0A1 instance\n\r"); 00041 } 00042 return _instance; 00043 } 00044 00045 00046 int XNucleo53L1A2::init_board() 00047 { 00048 int status, n_dev = 0; 00049 00050 sensor_centre->VL53L1CB_Off(); 00051 sensor_left->VL53L1CB_Off(); 00052 sensor_right->VL53L1CB_Off(); 00053 00054 // On startup or on the shutdown pin going high the VL53l1 devices have a i2c address of 0x52. 00055 // To initialise then we have to bring up one device at a time This involves raising the shutdown pin for that device, 00056 // initialising then setting the i2c address to a unique value. Once that is done the shutdown pins don't need to be touched. 00057 00058 // set the shutdown pins to be outputs ( they are inputs on power up) 00059 stmpe1600_exp1->set_gpio_dir(GPIO_15,OUTPUT); 00060 stmpe1600_exp0->set_gpio_dir(GPIO_14,OUTPUT); 00061 stmpe1600_exp0->set_gpio_dir(GPIO_15,OUTPUT); 00062 00063 // set the shutdown pins to low, this will reset the VL53l1s 00064 stmpe1600_exp1->clear_gpio(GPIO_15); 00065 stmpe1600_exp0->clear_gpio(GPIO_14); 00066 stmpe1600_exp0->clear_gpio(GPIO_15); 00067 00068 // select the first VL53l1. It will have i2c address of 0x52. Set the i2c address to 00069 //NEW_SENSOR_CENTRE_ADDRESS 00070 stmpe1600_exp1->set_gpio(GPIO_15); 00071 status = sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS); 00072 if (status) { 00073 delete sensor_centre; 00074 delete xshutdown_centre; 00075 sensor_centre = NULL; 00076 xshutdown_centre = NULL; 00077 printf("Sensor centre not present\n\r"); 00078 } else { 00079 printf("Sensor centre present\n\r"); 00080 n_dev++; 00081 } 00082 #if (MBED_VERSION > 60300) 00083 thread_sleep_for(2); 00084 #else 00085 wait_ms(2); // NEEDS A DELAY BETWEEN SENSORS 00086 #endif 00087 00088 // select the second VL53l1. It will have i2c address of 0x52. Set the i2c address to 00089 //NEW_SENSOR_LEFT_ADDRESS 00090 00091 stmpe1600_exp0->set_gpio(GPIO_14); 00092 00093 status = sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS); 00094 if (status) { 00095 delete sensor_left; 00096 delete xshutdown_left; 00097 sensor_left = NULL; 00098 xshutdown_left = NULL; 00099 printf("Sensor left not present\n\r"); 00100 } else { 00101 printf("Sensor left present\n\r"); 00102 n_dev++; 00103 } 00104 00105 #if (MBED_VERSION > 60300) 00106 thread_sleep_for(50); 00107 #else 00108 wait_ms(50); // NEEDS A DELAY BETWEEN SENSORS 00109 #endif 00110 // select the 3rd VL53l1. It will have i2c address of 0x52. Set the i2c address to 00111 //NEW_SENSOR_RIGHT_ADDRESS 00112 stmpe1600_exp0->set_gpio(GPIO_15); 00113 status = sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS); 00114 if (status) { 00115 delete sensor_right; 00116 delete xshutdown_right; 00117 sensor_right = NULL; 00118 xshutdown_right = NULL; 00119 printf("Sensor right not present\n\r"); 00120 } else { 00121 printf("Sensor right present\n\r"); 00122 n_dev++; 00123 } 00124 #if (MBED_VERSION > 60300) 00125 thread_sleep_for(50); 00126 #else 00127 wait_ms(50); // NEEDS A DELAY BETWEEN SENSORS 00128 #endif 00129 if (n_dev == 0) { 00130 return 1; 00131 } else { 00132 return 0; 00133 } 00134 }
Generated on Mon Jul 25 2022 12:54:07 by
1.7.2