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
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:
- on-board VL6180X proximity and ambient light sensor,
- up to three additional VL6180X Satellites,
- 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
A3pin; - to solder R47 resistor connected to
A5pin.
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
Revision 15:454710d17358, committed 2015-10-20
- Comitter:
- gallonm
- Date:
- Tue Oct 20 16:44:28 2015 +0200
- Parent:
- 14:0effa0bbf192
- Child:
- 16:0d4776564733
- Commit message:
- Fixed the function StartMeasurement
Added the other sensors (bottom, left and right)
Introduced the function InitSensor for each sensors
At the start we turn off all sensors
Fixed the function InitBoard
Added the other STMPE1600DigiOut for bottom, left and right sensor
Update the destructor
Changed in this revision
--- a/Components/STMPE1600/stmpe1600_class.h Mon Oct 19 13:54:17 2015 +0200
+++ b/Components/STMPE1600/stmpe1600_class.h Tue Oct 20 16:44:28 2015 +0200
@@ -60,7 +60,7 @@
typedef enum {
// GPIO Expander pin names
- GPIO_0,
+ GPIO_0=0,
GPIO_1,
GPIO_2,
GPIO_3,
@@ -107,7 +107,8 @@
dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 1);
dev_i2c.i2c_read(&data[1], expdevaddr, GPSR_8_15, 1);
*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set pin mask
- if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname);
+ if(lvl)
+ *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname);
dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 1);
dev_i2c.i2c_write(&data[1], expdevaddr, GPSR_8_15, 1);
}
--- a/Components/VL6180X/vl6180x_class.cpp Mon Oct 19 13:54:17 2015 +0200
+++ b/Components/VL6180X/vl6180x_class.cpp Tue Oct 20 16:44:28 2015 +0200
@@ -2657,9 +2657,9 @@
int VL6180X::ReadID()
{
int status;
- uint8_t rl_id;
+ uint8_t rl_id=0;
- status=VL6180x_RdByte( Device, IDENTIFICATION_MODEL_ID, &rl_id);
+ status=VL6180x_RdByte(Device, IDENTIFICATION_MODEL_ID, &rl_id);
if((status==0)&&(rl_id==0xB4))
return status;
else
@@ -2670,11 +2670,12 @@
int VL6180X::InitSensor(uint8_t NewAddr) //FIXME printf da sostituire con VL6180x_ErrLog e poi specificare il contenuto di questa funzione
{
int status;
- uint16_t buf;
- uint8_t buffer;
VL6180x_Off();
VL6180x_On();
+ /*status=VL6180x_WaitDeviceBooted(Device);
+ if(status)
+ printf("WaitDeviceBooted fail\n\r");*/
status=IsPresent();
if(!status)
{
@@ -2682,32 +2683,32 @@
status=Init();
if(status)
{
- printf("Failed to init VL6180X sensor!\n");
+ printf("Failed to init VL6180X sensor!\n\r");
return status;
}
status=Prepare();
if(status)
{
- printf("Failed to prepare VL6180X!\n");
+ printf("Failed to prepare VL6180X!\n\r");
return status;
}
if(NewAddr!=DEFAULT_DEVICE_ADDRESS)
{
- //status=SetI2CAddress(NewAddr); //if new_addr!=addr_default else errore
+ status=SetI2CAddress(NewAddr);
if(status)
{
- printf("Failed to change I2C address!\n");
+ printf("Failed to change I2C address!\n\r");
return status;
}
}
else
{
- printf("Invalid new address!");
+ printf("Invalid new address!\n\r");
return INVALID_PARAMS;
}
Device->Ready=1;
}
- return status;
+ return status;
}
@@ -2758,8 +2759,8 @@
return (r_status|l_status);
case(als_continuous_interrupt):
- status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY);
- status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
+ 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))
return AlsMeasIntContinuousMode(fptr);
else
@@ -3069,7 +3070,7 @@
status=NOT_READY;
}
else
- VL6180x_ErrLog("Fail to get interrupt status");
+ VL6180x_ErrLog("Failed to get interrupt status");
return status;
}
@@ -3292,7 +3293,7 @@
}
else
{
- VL6180x_ErrLog("Fail to read RESULT_INTERRUPT_STATUS_GPIO");
+ VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO");
return status;
}
if((operating_mode==range_continuous_polling)||(operating_mode==range_continuous_interrupt))
@@ -3356,7 +3357,7 @@
status=VL6180x_AlsGetInterruptStatus(Device, &IntStatus);
if(status)
{
- VL6180x_ErrLog("Fail to read RESULT_INTERRUPT_STATUS_GPIO");
+ VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO");
return status;
}
if((operating_mode==als_continuous_polling)||(operating_mode==als_continuous_interrupt))
@@ -3424,7 +3425,7 @@
}
else
{
- VL6180x_ErrLog("Fail to read RESULT_INTERRUPT_STATUS_GPIO");
+ VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO");
return status;
}
--- a/Components/VL6180X/vl6180x_class.h Mon Oct 19 13:54:17 2015 +0200
+++ b/Components/VL6180X/vl6180x_class.h Tue Oct 20 16:44:28 2015 +0200
@@ -128,15 +128,19 @@
/* turns on the sensor */
void VL6180x_On(void)
{
- if (gpio0) *gpio0=1;
- else if (expgpio0) *expgpio0=1;
+ if(gpio0)
+ *gpio0=1;
+ else if(expgpio0)
+ *expgpio0=1;
}
/* turns off the sensor */
void VL6180x_Off(void)
{
- if (gpio0) *gpio0=0;
- else if (expgpio0) *expgpio0=0;
+ if(gpio0)
+ *gpio0=0;
+ else if(expgpio0)
+ *expgpio0=0;
}
int InitSensor(uint8_t NewAddr);
@@ -171,6 +175,11 @@
int HandleIRQ(OperatingMode operating_mode, MeasureData_t *Data);
+ unsigned Present()
+ {
+ return Device->Present;
+ }
+
/* Wrapper functions */
int WaitDeviceBooted()
{
@@ -525,7 +534,7 @@
status=ReadID();
if(status)
- printf("Failed to read ID device! Device not present!\n"); //FIXME da sistemare la funzione di stampa errore ErrLog da platform.h
+ printf("Failed to read ID device! Device not present!\n\r"); //FIXME da sistemare la funzione di stampa errore ErrLog da platform.h
return status;
}
int StopRangeMeasurement(OperatingMode operating_mode);
--- a/x_nucleo_6180xa1.cpp Mon Oct 19 13:54:17 2015 +0200
+++ b/x_nucleo_6180xa1.cpp Tue Oct 20 16:44:28 2015 +0200
@@ -48,16 +48,19 @@
if(_instance==NULL)
_instance=new X_NUCLEO_6180XA1(ext_i2c);
else
- error("Failed to init X_NUCLEO_6180XA1 board!\n");
+ VL6180x_ErrLog("Failed to init X_NUCLEO_6180XA1 board!\n");
return _instance;
}
-int X_NUCLEO_6180XA1::InitBoard()
+int X_NUCLEO_6180XA1::InitBoard() //FIXME sistemare le stampe degli errori
{
- int status;
- //flag per verificare sensori presenti
- //sensor_top->VL6180x_Off() x4
+ int status, n_dev=0;
+
+ sensor_top->VL6180x_Off();
+ sensor_bottom->VL6180x_Off();
+ sensor_left->VL6180x_Off();
+ sensor_right->VL6180x_Off();
status=sensor_top->InitSensor(NEW_SENSOR_TOP_ADDRESS);
if(status)
{
@@ -65,9 +68,59 @@
delete gpio0_top;
sensor_top=NULL;
gpio0_top=NULL;
+ //VL6180x_ErrLog("Fail to init sensor_top\n\r");
+ printf("Failure to init sensor_top\n\r");
}
-
- //stessa cosa per left, bottom e right
+ else
+ {
+ n_dev++;
+ }
+ status=sensor_bottom->InitSensor(NEW_SENSOR_BOTTOM_ADDRESS);
+ if(status)
+ {
+ delete sensor_bottom;
+ delete gpio0_bottom;
+ sensor_bottom=NULL;
+ gpio0_bottom=NULL;
+ //VL6180x_ErrLog("Fail to init sensor_bottom\n\r");
+ printf("Failed to init sensor_bottom\n\r");
+ }
+ else
+ {
+ n_dev++;
+ }
+ status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS);
+ if(status)
+ {
+ delete sensor_left;
+ delete gpio0_left;
+ sensor_left=NULL;
+ gpio0_left=NULL;
+ //VL6180x_ErrLog("Fail to init sensor_left\n\r");
+ printf("Failed to init sensor_left\n\r");
+ }
+ else
+ {
+ n_dev++;
+ }
+ status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS);
+ if(status)
+ {
+ delete sensor_right;
+ delete gpio0_right;
+ sensor_right=NULL;
+ gpio0_right=NULL;
+ //VL6180x_ErrLog("Fail to init sensor_right\n\r");
+ printf("Failed to init sensor_right\n\r");
+ }
+ else
+ {
+ n_dev++;
+ }
+ if(n_dev==0)
+ return 1;
+ else
+ return 0;
}
--- a/x_nucleo_6180xa1.h Mon Oct 19 13:54:17 2015 +0200
+++ b/x_nucleo_6180xa1.h Tue Oct 20 16:44:28 2015 +0200
@@ -47,11 +47,11 @@
#include "STMPE1600_class.h"
#include "DevI2C.h"
-/** New device addresses */ //FIXME sistemare i nuovi indirizzi da assegnare ai sensori
+/** New device addresses */
#define NEW_SENSOR_TOP_ADDRESS 0x10
-//#define NEW_SENSOR_LEFT_ADDRESS 0x33
-//#define NEW_SENSOR_BOTTOM_ADDRESS 0x34
-//#define NEW_SENSOR_RIGHT_ADDRESS 0x35
+#define NEW_SENSOR_BOTTOM_ADDRESS 0x11
+#define NEW_SENSOR_LEFT_ADDRESS 0x12
+#define NEW_SENSOR_RIGHT_ADDRESS 0x13
/* Classes--------------------------------------------------------------------*/
@@ -61,25 +61,69 @@
X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
{
gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
- sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0);
+ sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0);
+ gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
+ sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, PA_4);
+ gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
+ sensor_left=new VL6180X(*dev_i2c, *gpio0_left, D13);
+ gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
+ sensor_right=new VL6180X(*dev_i2c, *gpio0_right, PA_10);
}
~X_NUCLEO_6180XA1()
{
if(gpio0_top!=NULL)
- delete[] gpio0_top;
+ {
+ delete gpio0_top;
+ gpio0_top=NULL;
+ }
if(sensor_top!=NULL)
- delete[] sensor_top;
+ {
+ delete sensor_top;
+ sensor_top=NULL;
+ }
+ if(gpio0_bottom!=NULL)
+ {
+ delete gpio0_bottom;
+ gpio0_bottom=NULL;
+ }
+ if(sensor_bottom!=NULL)
+ {
+ delete sensor_bottom;
+ sensor_bottom=NULL;
+ }
+ if(gpio0_left!=NULL)
+ {
+ delete gpio0_left;
+ gpio0_left=NULL;
+ }
+ if(sensor_left!=NULL)
+ {
+ delete sensor_left;
+ sensor_left=NULL;
+ }
+ if(gpio0_right!=NULL)
+ {
+ delete gpio0_right;
+ gpio0_right=NULL;
+ }
+ if(sensor_right!=NULL)
+ {
+ delete sensor_right;
+ sensor_right=NULL;
+ }
}
DevI2C *dev_i2c;
STMPE1600DigiOut *gpio0_top;
+ STMPE1600DigiOut *gpio0_bottom;
+ STMPE1600DigiOut *gpio0_left;
+ STMPE1600DigiOut *gpio0_right;
VL6180X *sensor_top;
-
- //pin gpio1: bottom=PA4, left=D13, right=PA10
- //VL6180X *vl6180x_left;
- //VL6180X *vl6180x_bottom;
- //VL6180X *vl6180x_right;
+ VL6180X *sensor_bottom;
+ VL6180X *sensor_left;
+ VL6180X *sensor_right;
+
//Display *display;
static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor