Library to handle the X-NUCLEO-6180XA1 Proximity and ambient light sensor expansion board based on VL6180X.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_6180XA1 SunTracker_BLE Servo_6180XA1 BLE_HR_Light ... more

Fork of X_NUCLEO_6180XA1 by ST Expansion SW Team

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers and Board Support Package for STMicroelectronics' X-NUCLEO-6180XA1 Proximity and ambient light sensor expansion board based on VL6180X.

Firmware Library

Class X_NUCLEO_6180XA1 is intended to represent the Proximity and ambient light sensor expansion board with the same name.

The expansion board is providing the support of the following components:

  1. on-board VL6180X proximity and ambient light sensor,
  2. up to three additional VL6180X Satellites,
  3. on-board 4-digit display

It is intentionally implemented as a singleton because only one X-NUCLEO-VL6180XA1 at a time might be deployed in a HW component stack. In order to get the singleton instance you have to call class method `Instance()`, e.g.:

// Sensors expansion board singleton instance
static X_NUCLEO_6180XA1 *6180X_expansion_board = X_NUCLEO_6180XA1::Instance();

Arduino Connector Compatibility Warning

Using the X-NUCLEO-6180XA1 expansion board with the NUCLEO-F429ZI requires adopting the following patch:

  • to remove R46 resistor connected to A3 pin;
  • to solder R47 resistor connected to A5 pin.

Alternatively, you can route the Nucleo board’s A5 pin directly to the expansion board’s A3 pin with a wire. In case you patch your expansion board or route the pin, the interrupt signal for the front sensor will be driven on A5 pin rather than on A3 pin.


Example Applications

Files at this revision

API Documentation at this revision

Comitter:
mapellil
Date:
Wed Nov 30 08:25:04 2016 +0000
Parent:
53:663a22f7c44d
Child:
55:a37f407230ca
Commit message:
Aligned GetLux and GetDistance API with ST_INTERFACES, added isSensorxxPresentAPI, other minor fix.

Changed in this revision

Components/VL6180X/vl6180x_class.cpp Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_class.h Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_def.h Show annotated file Show diff for this revision Revisions of this file
ST_INTERFACES.lib Show annotated file Show diff for this revision Revisions of this file
X_NUCLEO_COMMON.lib Show annotated file Show diff for this revision Revisions of this file
x_nucleo_6180xa1.cpp Show annotated file Show diff for this revision Revisions of this file
x_nucleo_6180xa1.h Show annotated file Show diff for this revision Revisions of this file
--- a/Components/VL6180X/vl6180x_class.cpp	Tue Sep 27 12:18:09 2016 +0000
+++ b/Components/VL6180X/vl6180x_class.cpp	Wed Nov 30 08:25:04 2016 +0000
@@ -979,7 +979,7 @@
     return status;
 }
  
-int VL6180X::VL6180x_RangeGetResult(VL6180xDev_t dev, int32_t *pRange_mm) {
+int VL6180X::VL6180x_RangeGetResult(VL6180xDev_t dev, uint32_t *pRange_mm) {
     int status;
     uint8_t RawRange;
     int32_t Upscale;
@@ -2734,6 +2734,7 @@
            return (r_status|l_status);
                  
       case(range_continuous_interrupt):
+        if (gpio1Int==NULL) return 1;
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY);
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
@@ -2742,6 +2743,7 @@
            return (r_status|l_status);
                      
       case(als_continuous_interrupt):
+        if (gpio1Int==NULL) return 1;      
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY);
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
@@ -2750,6 +2752,7 @@
            return (r_status|l_status);
  
       case(interleaved_mode_interrupt):
+        if (gpio1Int==NULL) return 1;      
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY);
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);            
         if((!r_status)&&(!l_status))
@@ -2842,6 +2845,7 @@
            return (r_status|l_status);
                 
       case(range_continuous_interrupt_low_threshold):
+        if (gpio1Int==NULL) return 1;      
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW);
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
@@ -2855,7 +2859,8 @@
         else
            return (r_status|l_status);                  
             
-      case(range_continuous_interrupt_high_threshold):   
+      case(range_continuous_interrupt_high_threshold): 
+        if (gpio1Int==NULL) return 1;        
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH);
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
@@ -2870,6 +2875,7 @@
            return (r_status|l_status);
                 
        case(range_continuous_interrupt_out_of_window):
+        if (gpio1Int==NULL) return 1;       
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW);
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
@@ -2884,6 +2890,7 @@
            return (r_status|l_status);
             
       case(als_continuous_interrupt_low_threshold):
+        if (gpio1Int==NULL) return 1;      
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW);
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
@@ -2898,6 +2905,7 @@
            return (r_status|l_status);  
                 
       case(als_continuous_interrupt_high_threshold):
+        if (gpio1Int==NULL) return 1;      
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH);
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
@@ -2912,6 +2920,7 @@
            return (r_status|l_status);
                 
       case(als_continuous_interrupt_out_of_window):
+        if (gpio1Int==NULL) return 1;      
         l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW);
         r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
         if((!r_status)&&(!l_status))
--- a/Components/VL6180X/vl6180x_class.h	Tue Sep 27 12:18:09 2016 +0000
+++ b/Components/VL6180X/vl6180x_class.h	Wed Nov 30 08:25:04 2016 +0000
@@ -466,25 +466,6 @@
     }
 
 /**
- * @brief Get ranging result and only that
- *
- * @par Function Description
- * Unlike @a VL6180x_RangeGetMeasurement() this function only retrieves the range in millimeter \n
- * It does any required up-scale translation\n
- * It can be called after having started a measure and after a succes \n
- * measure is finisched either in polling mode or in interrupt mode \n
- * @warning these function is not doing wrap around filtering \n
- * This function doesn't perform any data ready check!
- *
- * @param pRange_mm  Pointer to range distance
- * @return           0 on success
- */		
-    int GetRange(int32_t *piData)
-    {
-       return VL6180x_RangeGetResult(Device, piData);
-    }
-
-/**
  * @brief Get a single distance measure result
  *
  * @par Function Description
@@ -505,7 +486,7 @@
 		  RangeWaitDeviceReady(2000);				 
           for (status=1; 
                status!=0; 
-               status=GetRange((int32_t *)piData));
+		       status=VL6180x_RangeGetResult(Device, piData));
        }
        StopMeasurement(range_single_shot_polling);
        RangeWaitDeviceReady(2000);
@@ -1102,19 +1083,6 @@
 /** @}  */
 
 /**
- * @brief Get the ALS (light in Lux) level
- *
- * @par Function Description
- * Get the ALS (light in Lux) level 
- * @param *piData The pointer to variable to write in the measure in Lux
- * @return  0       On success
- */				
-    int GetLight(uint32_t *piData)
-    {
-       return VL6180x_AlsGetLux(Device, piData);
-    }
-
-/**
  * @brief Get a single light (in Lux) measure result
  *
  * @par Function Description
@@ -1132,7 +1100,7 @@
           AlsWaitDeviceReady(2000);				 
           for (status=1; 
                status!=0; 
-               status=GetLight(piData));
+               status=VL6180x_AlsGetLux(Device, piData));
        }
        StopMeasurement(als_single_shot_polling);
 	   AlsWaitDeviceReady(2000);				 			 
@@ -1176,7 +1144,7 @@
     int VL6180x_RangePollMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
     int VL6180x_RangeGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
     int VL6180x_RangeGetMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
-    int VL6180x_RangeGetResult(VL6180xDev_t dev, int32_t *pRange_mm);
+    int VL6180x_RangeGetResult(VL6180xDev_t dev, uint32_t *pRange_mm);
     int VL6180x_RangeConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt);
     int VL6180x_RangeGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
     int VL6180x_AlsPollMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
--- a/Components/VL6180X/vl6180x_def.h	Tue Sep 27 12:18:09 2016 +0000
+++ b/Components/VL6180X/vl6180x_def.h	Wed Nov 30 08:25:04 2016 +0000
@@ -251,7 +251,7 @@
  * @brief Range and any optional measurement data.
  */
 typedef struct {
-    int32_t range_mm;          /*!< range distance in mm. */
+    uint32_t range_mm;          /*!< range distance in mm. */
     int32_t signalRate_mcps;   /*!< signal rate (MCPS)\n these is a 9.7 fix point value, which is effectively a measure of target reflectance.*/
     uint32_t errorStatus;      /*!< Error status of the current measurement. \n
                                   see @a ::RangeError_u @a VL6180x_GetRangeStatusErrString() */
--- a/ST_INTERFACES.lib	Tue Sep 27 12:18:09 2016 +0000
+++ b/ST_INTERFACES.lib	Wed Nov 30 08:25:04 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#a7810e7acf8d
+https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#e2bf4d06a8fc
--- a/X_NUCLEO_COMMON.lib	Tue Sep 27 12:18:09 2016 +0000
+++ b/X_NUCLEO_COMMON.lib	Wed Nov 30 08:25:04 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#216930edb6b7
+https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#12be3dfc15fd
--- a/x_nucleo_6180xa1.cpp	Tue Sep 27 12:18:09 2016 +0000
+++ b/x_nucleo_6180xa1.cpp	Wed Nov 30 08:25:04 2016 +0000
@@ -68,15 +68,21 @@
 {	
    int status, n_dev=0; uint8_t sensor_address;
 	
-     sensor_top->VL6180x_Off();
-     sensor_bottom->VL6180x_Off();
-     sensor_left->VL6180x_Off();
-     sensor_right->VL6180x_Off();
+     if (sensor_top)    sensor_top->VL6180x_Off();
+     if (sensor_bottom) sensor_bottom->VL6180x_Off();
+     if (sensor_left)   sensor_left->VL6180x_Off();
+     if (sensor_right)  sensor_right->VL6180x_Off();
      sensor_address = NEW_SENSOR_TOP_ADDRESS;     
      status=sensor_top->Init(&sensor_address);
      if(status)
      {
-        printf("Sensor top not present\n\r");
+        printf("Error: Mandatory top sensor fail, Init failed!\n\r");
+        if (sensor_top !=NULL)   { delete sensor_top; sensor_top=NULL; }
+        if (sensor_left !=NULL)  {delete sensor_left; sensor_left=NULL; }        
+        if (sensor_bottom !=NULL){ delete sensor_bottom; sensor_bottom=NULL; }
+        if (sensor_right !=NULL) { delete sensor_right; sensor_right=NULL; }
+        n_dev=0;
+        return 1;
      }
      else
      {
@@ -84,10 +90,12 @@
         n_dev++;
      }
      sensor_address = NEW_SENSOR_BOTTOM_ADDRESS;
-     status=sensor_bottom->Init(&sensor_address);
+     status=1;
+     if (sensor_bottom) status=sensor_bottom->Init(&sensor_address);
      if(status)
      {
         printf("Sensor bottom not present\n\r");
+        if (sensor_bottom !=NULL) { delete sensor_bottom; sensor_bottom=NULL; }
      }
      else
      {
@@ -95,10 +103,12 @@
         n_dev++;
      }
      sensor_address = NEW_SENSOR_LEFT_ADDRESS;
-     status=sensor_left->Init(&sensor_address);
+     status=1;
+     if (sensor_left) status=sensor_left->Init(&sensor_address);
      if(status)
      {
         printf("Sensor left not present\n\r");
+        if (sensor_left !=NULL) {delete sensor_left; sensor_left=NULL; }                
      }
      else
      {
@@ -106,10 +116,12 @@
         n_dev++;
      }
      sensor_address = NEW_SENSOR_RIGHT_ADDRESS;
-     status=sensor_right->Init(&sensor_address);
+     status=1;
+     if (sensor_right) status=sensor_right->Init(&sensor_address);
      if(status)
      {
         printf("Sensor right not present\n\r");
+        if (sensor_right !=NULL) { delete sensor_right; sensor_right=NULL; }        
      }
      else
      {
--- a/x_nucleo_6180xa1.h	Tue Sep 27 12:18:09 2016 +0000
+++ b/x_nucleo_6180xa1.h	Wed Nov 30 08:25:04 2016 +0000
@@ -63,6 +63,9 @@
 {
 protected:
      /** Constructor 1
+    * @brief       x_nucleo_6180xa1 board Constructor. Default the INT gpio \
+    * configuration as the electrical schematic. Self sensing for optional \
+    * expansion sensors (L/B/R). 
      * @param[in] &i2c device I2C to be used for communication
      */
     X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
@@ -83,6 +86,10 @@
        
        gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
        sensor_right=new VL6180X(*dev_i2c, *gpio0_right, D2);
+       
+       if (InitBoard()) {   // init failed
+       	   printf ("ERROR Init X-NUCLEO-6180XA1 Board\n\r");
+       	}      
     }
     
     /** Constructor 2
@@ -145,7 +152,6 @@
 	 */					         
     static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
                                              PinName gpio1_left, PinName gpio1_right);
-
     
 	/**
 	 * @brief       Initialize the board and sensors with deft values
@@ -160,6 +166,42 @@
     bool RdSwitch () {
 	     return Switch->RdSwitch();	
     }
+    
+	/**
+	 * @brief       Check the presence of sensor top. To be called after InitBoard
+	 * @return      true is present, false if absent
+	 */				
+	bool isSensorTopPresent() {
+		if (sensor_top) return true;
+		return false;
+	} 
+
+	/**
+	 * @brief       Check the presence of sensor bottom.  To be called after InitBoard
+	 * @return      true is present, false if absent
+	 */				
+	bool isSensorBottomPresent() {
+		if (sensor_bottom) return true;
+		return false;
+	} 
+	
+	/**
+	 * @brief       Check the presence of sensor left.  To be called after InitBoard
+	 * @return      true is present, false if absent
+	 */				
+	bool isSensorLeftPresent() {
+		if (sensor_left) return true;
+		return false;
+	} 
+	
+	/**
+	 * @brief       Check the presence of sensor right.  To be called after InitBoard
+	 * @return      true is present, false if absent
+	 */				
+	bool isSensorRightPresent() {
+		if (sensor_right) return true;
+		return false;
+	} 
 
     DevI2C *dev_i2c;
     VL6180X *sensor_top;