Silica Sensor Node board sends custom ble advertising for the Gateway board

Dependencies:   X_NUCLEO_IKS01A2_SPI3W

Fork of sensor-node-ble by Roberto Spelta

Getting started with mbed SensorNode BLE

Information

History project:

  • 26/01/2017 - First Release

This project uses the Bluetooth Low Energy in order to send advertaisments every second. These payloads are read by the Visible Things Gateway board, more about it here . Every advertaisments contains sensors data read form the SensorTile and the Silica Sensor Board. For details please read the document in the MAN folder,

The application:

  • reads sensors data (accelerometer, gyroscope, lux, pressure, temperature, proximity, magnetometer)
  • send these data by BLE

You can compile this project in three ways:

1. Using the Online compiler.

Information

Learn how to use the Online compiler reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/online_comp/ page.

2. Using the compiler on your PC

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/cli/ page.
The name of the machine is SILICA_SENSOR_NODE.

3. Exporting to 3rd party tools (IDE)

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/third_party/ page. We have exported the project for you, please read here

Warning

This example requires a Visible Things Gateway board. If you don't have this board you can use RF Connect app from an Android phone just to see the raw data sent from the SensorNode.

Committer:
rspelta
Date:
Fri Jan 26 18:26:48 2018 +0100
Revision:
5:26b07c500aa2
Parent:
3:94aee6f716b7
fix comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rspelta 3:94aee6f716b7 1 /******************************************************************************
rspelta 3:94aee6f716b7 2 * SFE_VL6180x.cpp
rspelta 3:94aee6f716b7 3 * Library for VL6180x time of flight range finder.
rspelta 3:94aee6f716b7 4 * Casey Kuhns @ SparkFun Electronics
rspelta 3:94aee6f716b7 5 * 10/29/2014
rspelta 3:94aee6f716b7 6 * https://github.com/sparkfun/
rspelta 3:94aee6f716b7 7 *
rspelta 3:94aee6f716b7 8 * The VL6180x by ST micro is a time of flight range finder that
rspelta 3:94aee6f716b7 9 * uses pulsed IR light to determine distances from object at close
rspelta 3:94aee6f716b7 10 * range. The average range of a sensor is between 0-200mm
rspelta 3:94aee6f716b7 11 *
rspelta 3:94aee6f716b7 12 * In this file are the functions in the VL6180x class
rspelta 3:94aee6f716b7 13 *
rspelta 3:94aee6f716b7 14 * Resources:
rspelta 3:94aee6f716b7 15 * This library uses the Arduino Wire.h to complete I2C transactions.
rspelta 3:94aee6f716b7 16 *
rspelta 3:94aee6f716b7 17 * Development environment specifics:
rspelta 3:94aee6f716b7 18 * IDE: Arduino 1.0.5
rspelta 3:94aee6f716b7 19 * Hardware Platform: Arduino Pro 3.3V/8MHz
rspelta 3:94aee6f716b7 20 * VL6180x Breakout Version: 1.0
rspelta 3:94aee6f716b7 21 *
rspelta 3:94aee6f716b7 22 *
rspelta 3:94aee6f716b7 23 * This code is beerware. If you see me (or any other SparkFun employee) at the
rspelta 3:94aee6f716b7 24 * local pub, and you've found our code helpful, please buy us a round!
rspelta 3:94aee6f716b7 25 *
rspelta 3:94aee6f716b7 26 * Distributed as-is; no warranty is given.
rspelta 3:94aee6f716b7 27 ******************************************************************************/
rspelta 3:94aee6f716b7 28
rspelta 3:94aee6f716b7 29
rspelta 3:94aee6f716b7 30 #include "VL6180x.h"
rspelta 3:94aee6f716b7 31
rspelta 3:94aee6f716b7 32 //VL6180x::VL6180x(PinName sda, PinName scl, uint8_t addr) : m_i2c(sda, scl), m_addr(addr) {}
rspelta 3:94aee6f716b7 33
rspelta 3:94aee6f716b7 34 VL6180x::VL6180x(I2C *i2c, uint8_t addr) : m_i2c(i2c), m_addr(addr)
rspelta 3:94aee6f716b7 35 {
rspelta 3:94aee6f716b7 36 m_i2c->frequency(400000);
rspelta 3:94aee6f716b7 37 PE1801_setRegister( GPIO_SET_DIR_LOW, 0x40 ); // only IO6 setted as output
rspelta 3:94aee6f716b7 38 PE1801_setRegister( GPIO_SET_DIR_MID, 0 );
rspelta 3:94aee6f716b7 39 PE1801_setRegister( GPIO_SET_DIR_HIGH, 0 );
rspelta 3:94aee6f716b7 40 PE1801_setRegister( GPIO_SET_LOW, 0x40 ); // set 1 DEV_RESN
rspelta 3:94aee6f716b7 41 }
rspelta 3:94aee6f716b7 42
rspelta 3:94aee6f716b7 43 int VL6180x::VL6180xInit(void){
rspelta 3:94aee6f716b7 44 uint8_t data; //for temp data storage
rspelta 3:94aee6f716b7 45
rspelta 3:94aee6f716b7 46 data = VL6180x_getRegister(VL6180X_SYSTEM_FRESH_OUT_OF_RESET);
rspelta 3:94aee6f716b7 47 wait_ms(50);
rspelta 3:94aee6f716b7 48 if(data != 1) {
rspelta 3:94aee6f716b7 49 printf("error\n\r");
rspelta 3:94aee6f716b7 50 return VL6180x_FAILURE_RESET;
rspelta 3:94aee6f716b7 51 }
rspelta 3:94aee6f716b7 52
rspelta 3:94aee6f716b7 53 //Required by datasheet
rspelta 3:94aee6f716b7 54 //http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf
rspelta 3:94aee6f716b7 55 VL6180x_setRegister(0x0207, 0x01);
rspelta 3:94aee6f716b7 56 VL6180x_setRegister(0x0208, 0x01);
rspelta 3:94aee6f716b7 57 VL6180x_setRegister(0x0096, 0x00);
rspelta 3:94aee6f716b7 58 VL6180x_setRegister(0x0097, 0xfd);
rspelta 3:94aee6f716b7 59 VL6180x_setRegister(0x00e3, 0x00);
rspelta 3:94aee6f716b7 60 VL6180x_setRegister(0x00e4, 0x04);
rspelta 3:94aee6f716b7 61 VL6180x_setRegister(0x00e5, 0x02);
rspelta 3:94aee6f716b7 62 VL6180x_setRegister(0x00e6, 0x01);
rspelta 3:94aee6f716b7 63 VL6180x_setRegister(0x00e7, 0x03);
rspelta 3:94aee6f716b7 64 VL6180x_setRegister(0x00f5, 0x02);
rspelta 3:94aee6f716b7 65 VL6180x_setRegister(0x00d9, 0x05);
rspelta 3:94aee6f716b7 66 VL6180x_setRegister(0x00db, 0xce);
rspelta 3:94aee6f716b7 67 VL6180x_setRegister(0x00dc, 0x03);
rspelta 3:94aee6f716b7 68 VL6180x_setRegister(0x00dd, 0xf8);
rspelta 3:94aee6f716b7 69 VL6180x_setRegister(0x009f, 0x00);
rspelta 3:94aee6f716b7 70 VL6180x_setRegister(0x00a3, 0x3c);
rspelta 3:94aee6f716b7 71 VL6180x_setRegister(0x00b7, 0x00);
rspelta 3:94aee6f716b7 72 VL6180x_setRegister(0x00bb, 0x3c);
rspelta 3:94aee6f716b7 73 VL6180x_setRegister(0x00b2, 0x09);
rspelta 3:94aee6f716b7 74 VL6180x_setRegister(0x00ca, 0x09);
rspelta 3:94aee6f716b7 75 VL6180x_setRegister(0x0198, 0x01);
rspelta 3:94aee6f716b7 76 VL6180x_setRegister(0x01b0, 0x17);
rspelta 3:94aee6f716b7 77 VL6180x_setRegister(0x01ad, 0x00);
rspelta 3:94aee6f716b7 78 VL6180x_setRegister(0x00ff, 0x05);
rspelta 3:94aee6f716b7 79 VL6180x_setRegister(0x0100, 0x05);
rspelta 3:94aee6f716b7 80 VL6180x_setRegister(0x0199, 0x05);
rspelta 3:94aee6f716b7 81 VL6180x_setRegister(0x01a6, 0x1b);
rspelta 3:94aee6f716b7 82 VL6180x_setRegister(0x01ac, 0x3e);
rspelta 3:94aee6f716b7 83 VL6180x_setRegister(0x01a7, 0x1f);
rspelta 3:94aee6f716b7 84 VL6180x_setRegister(0x0030, 0x00);
rspelta 3:94aee6f716b7 85
rspelta 3:94aee6f716b7 86 return 0;
rspelta 3:94aee6f716b7 87 }
rspelta 3:94aee6f716b7 88 VL6180x::~VL6180x(void) {
rspelta 3:94aee6f716b7 89 };
rspelta 3:94aee6f716b7 90
rspelta 3:94aee6f716b7 91 void VL6180x::VL6180xDefautSettings(void){
rspelta 3:94aee6f716b7 92 //Recommended settings from datasheet
rspelta 3:94aee6f716b7 93 //http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf
rspelta 3:94aee6f716b7 94
rspelta 3:94aee6f716b7 95 //Enable Interrupts on Conversion Complete (any source)
rspelta 3:94aee6f716b7 96 VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, (4 << 3)|(4) ); // Set GPIO1 high when sample complete
rspelta 3:94aee6f716b7 97
rspelta 3:94aee6f716b7 98
rspelta 3:94aee6f716b7 99 VL6180x_setRegister(VL6180X_SYSTEM_MODE_GPIO1, 0x10); // Set GPIO1 high when sample complete
rspelta 3:94aee6f716b7 100 VL6180x_setRegister(VL6180X_READOUT_AVERAGING_SAMPLE_PERIOD, 0x30); //Set Avg sample period
rspelta 3:94aee6f716b7 101 VL6180x_setRegister(VL6180X_SYSALS_ANALOGUE_GAIN, 0x46); // Set the ALS gain
rspelta 3:94aee6f716b7 102 VL6180x_setRegister(VL6180X_SYSRANGE_VHV_REPEAT_RATE, 0xFF); // Set auto calibration period (Max = 255)/(OFF = 0)
rspelta 3:94aee6f716b7 103 VL6180x_setRegister(VL6180X_SYSALS_INTEGRATION_PERIOD, 0x63); // Set ALS integration time to 100ms
rspelta 3:94aee6f716b7 104 VL6180x_setRegister(VL6180X_SYSRANGE_VHV_RECALIBRATE, 0x01); // perform a single temperature calibration
rspelta 3:94aee6f716b7 105 //Optional settings from datasheet
rspelta 3:94aee6f716b7 106 //http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf
rspelta 3:94aee6f716b7 107 VL6180x_setRegister(VL6180X_SYSRANGE_INTERMEASUREMENT_PERIOD, 0x09); // Set default ranging inter-measurement period to 100ms
rspelta 3:94aee6f716b7 108 VL6180x_setRegister(VL6180X_SYSALS_INTERMEASUREMENT_PERIOD, 0x0A); // Set default ALS inter-measurement period to 100ms
rspelta 3:94aee6f716b7 109 VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x24); // Configures interrupt on ‘New Sample Ready threshold event’
rspelta 3:94aee6f716b7 110 //Additional settings defaults from community
rspelta 3:94aee6f716b7 111 VL6180x_setRegister(VL6180X_SYSRANGE_MAX_CONVERGENCE_TIME, 0x32);
rspelta 3:94aee6f716b7 112 VL6180x_setRegister(VL6180X_SYSRANGE_RANGE_CHECK_ENABLES, 0x10 | 0x01);
rspelta 3:94aee6f716b7 113 VL6180x_setRegister16bit(VL6180X_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, 0x7B );
rspelta 3:94aee6f716b7 114 VL6180x_setRegister16bit(VL6180X_SYSALS_INTEGRATION_PERIOD, 0x64);
rspelta 3:94aee6f716b7 115
rspelta 3:94aee6f716b7 116 VL6180x_setRegister(VL6180X_READOUT_AVERAGING_SAMPLE_PERIOD,0x30);
rspelta 3:94aee6f716b7 117 VL6180x_setRegister(VL6180X_SYSALS_ANALOGUE_GAIN,0x40);
rspelta 3:94aee6f716b7 118 VL6180x_setRegister(VL6180X_FIRMWARE_RESULT_SCALER,0x01);
rspelta 3:94aee6f716b7 119 }
rspelta 3:94aee6f716b7 120 void VL6180x::getIdentification(struct VL6180xIdentification *temp){
rspelta 3:94aee6f716b7 121
rspelta 3:94aee6f716b7 122 temp->idModel = VL6180x_getRegister(VL6180X_IDENTIFICATION_MODEL_ID);
rspelta 3:94aee6f716b7 123 temp->idModelRevMajor = VL6180x_getRegister(VL6180X_IDENTIFICATION_MODEL_REV_MAJOR);
rspelta 3:94aee6f716b7 124 temp->idModelRevMinor = VL6180x_getRegister(VL6180X_IDENTIFICATION_MODEL_REV_MINOR);
rspelta 3:94aee6f716b7 125 temp->idModuleRevMajor = VL6180x_getRegister(VL6180X_IDENTIFICATION_MODULE_REV_MAJOR);
rspelta 3:94aee6f716b7 126 temp->idModuleRevMinor = VL6180x_getRegister(VL6180X_IDENTIFICATION_MODULE_REV_MINOR);
rspelta 3:94aee6f716b7 127
rspelta 3:94aee6f716b7 128 temp->idDate = VL6180x_getRegister16bit(VL6180X_IDENTIFICATION_DATE);
rspelta 3:94aee6f716b7 129 temp->idTime = VL6180x_getRegister16bit(VL6180X_IDENTIFICATION_TIME);
rspelta 3:94aee6f716b7 130 }
rspelta 3:94aee6f716b7 131
rspelta 3:94aee6f716b7 132
rspelta 3:94aee6f716b7 133 uint8_t VL6180x::changeAddress(uint8_t old_address, uint8_t new_address){
rspelta 3:94aee6f716b7 134
rspelta 3:94aee6f716b7 135 //NOTICE: IT APPEARS THAT CHANGING THE ADDRESS IS NOT STORED IN NON-VOLATILE MEMORY
rspelta 3:94aee6f716b7 136 // POWER CYCLING THE DEVICE REVERTS ADDRESS BACK TO 0X29
rspelta 3:94aee6f716b7 137
rspelta 3:94aee6f716b7 138 if( old_address == new_address) return old_address;
rspelta 3:94aee6f716b7 139 if( new_address > 127) return old_address;
rspelta 3:94aee6f716b7 140
rspelta 3:94aee6f716b7 141 VL6180x_setRegister(VL6180X_I2C_SLAVE_DEVICE_ADDRESS, new_address);
rspelta 3:94aee6f716b7 142
rspelta 3:94aee6f716b7 143 return VL6180x_getRegister(VL6180X_I2C_SLAVE_DEVICE_ADDRESS);
rspelta 3:94aee6f716b7 144 }
rspelta 3:94aee6f716b7 145
rspelta 3:94aee6f716b7 146
rspelta 3:94aee6f716b7 147
rspelta 3:94aee6f716b7 148 uint8_t VL6180x::getDistance() {
rspelta 3:94aee6f716b7 149 uint8_t distance;
rspelta 3:94aee6f716b7 150 VL6180x_setRegister(VL6180X_SYSRANGE_START, 0x01); //Start Single shot mode
rspelta 3:94aee6f716b7 151 wait_ms(10);
rspelta 3:94aee6f716b7 152 distance = VL6180x_getRegister(VL6180X_RESULT_RANGE_VAL);
rspelta 3:94aee6f716b7 153 VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);
rspelta 3:94aee6f716b7 154 return distance;
rspelta 3:94aee6f716b7 155 }
rspelta 3:94aee6f716b7 156
rspelta 3:94aee6f716b7 157 float VL6180x::getAmbientLight(vl6180x_als_gain VL6180X_ALS_GAIN)
rspelta 3:94aee6f716b7 158 {
rspelta 3:94aee6f716b7 159 //First load in Gain we are using, do it everytime incase someone changes it on us.
rspelta 3:94aee6f716b7 160 //Note: Upper nibble shoudl be set to 0x4 i.e. for ALS gain of 1.0 write 0x46
rspelta 3:94aee6f716b7 161 VL6180x_setRegister(VL6180X_SYSALS_ANALOGUE_GAIN, (0x40 | VL6180X_ALS_GAIN)); // Set the ALS gain
rspelta 3:94aee6f716b7 162
rspelta 3:94aee6f716b7 163 //Start ALS Measurement
rspelta 3:94aee6f716b7 164 VL6180x_setRegister(VL6180X_SYSALS_START, 0x01);
rspelta 3:94aee6f716b7 165
rspelta 3:94aee6f716b7 166 wait_ms(100); //give it time...
rspelta 3:94aee6f716b7 167
rspelta 3:94aee6f716b7 168 VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);
rspelta 3:94aee6f716b7 169
rspelta 3:94aee6f716b7 170 //Retrieve the Raw ALS value from the sensoe
rspelta 3:94aee6f716b7 171 unsigned int alsRaw = VL6180x_getRegister16bit(VL6180X_RESULT_ALS_VAL);
rspelta 3:94aee6f716b7 172
rspelta 3:94aee6f716b7 173 //Get Integration Period for calculation, we do this everytime incase someone changes it on us.
rspelta 3:94aee6f716b7 174 unsigned int alsIntegrationPeriodRaw = VL6180x_getRegister16bit(VL6180X_SYSALS_INTEGRATION_PERIOD);
rspelta 3:94aee6f716b7 175
rspelta 3:94aee6f716b7 176 float alsIntegrationPeriod = 100.0 / alsIntegrationPeriodRaw ;
rspelta 3:94aee6f716b7 177
rspelta 3:94aee6f716b7 178 //Calculate actual LUX from Appnotes
rspelta 3:94aee6f716b7 179
rspelta 3:94aee6f716b7 180 float alsGain = 0.0;
rspelta 3:94aee6f716b7 181
rspelta 3:94aee6f716b7 182 switch (VL6180X_ALS_GAIN){
rspelta 3:94aee6f716b7 183 case GAIN_20: alsGain = 20.0; break;
rspelta 3:94aee6f716b7 184 case GAIN_10: alsGain = 10.32; break;
rspelta 3:94aee6f716b7 185 case GAIN_5: alsGain = 5.21; break;
rspelta 3:94aee6f716b7 186 case GAIN_2_5: alsGain = 2.60; break;
rspelta 3:94aee6f716b7 187 case GAIN_1_67: alsGain = 1.72; break;
rspelta 3:94aee6f716b7 188 case GAIN_1_25: alsGain = 1.28; break;
rspelta 3:94aee6f716b7 189 case GAIN_1: alsGain = 1.01; break;
rspelta 3:94aee6f716b7 190 case GAIN_40: alsGain = 40.0; break;
rspelta 3:94aee6f716b7 191 }
rspelta 3:94aee6f716b7 192
rspelta 3:94aee6f716b7 193 //Calculate LUX from formula in AppNotes
rspelta 3:94aee6f716b7 194
rspelta 3:94aee6f716b7 195 float alsCalculated = (float)0.32 * ((float)alsRaw / alsGain) * alsIntegrationPeriod;
rspelta 3:94aee6f716b7 196
rspelta 3:94aee6f716b7 197 return alsCalculated;
rspelta 3:94aee6f716b7 198 }
rspelta 3:94aee6f716b7 199
rspelta 3:94aee6f716b7 200 // --- Private Functions --- //
rspelta 3:94aee6f716b7 201
rspelta 3:94aee6f716b7 202 uint8_t VL6180x::VL6180x_getRegister(uint16_t registerAddr)
rspelta 3:94aee6f716b7 203 {
rspelta 3:94aee6f716b7 204
rspelta 3:94aee6f716b7 205 uint8_t data;
rspelta 3:94aee6f716b7 206 char data_write[2];
rspelta 3:94aee6f716b7 207 char data_read[1];
rspelta 3:94aee6f716b7 208 data_write[0] = (registerAddr >> 8) & 0xFF; //MSB of register address
rspelta 3:94aee6f716b7 209 data_write[1] = registerAddr & 0xFF; //LSB of register address
rspelta 3:94aee6f716b7 210 m_i2c->write(m_addr, data_write, 2,0);
rspelta 3:94aee6f716b7 211 m_i2c->read(m_addr,data_read,1,1);
rspelta 3:94aee6f716b7 212 //Read Data from selected register
rspelta 3:94aee6f716b7 213 data=data_read[0];
rspelta 3:94aee6f716b7 214 return data;
rspelta 3:94aee6f716b7 215
rspelta 3:94aee6f716b7 216 /*
rspelta 3:94aee6f716b7 217 #if 1
rspelta 3:94aee6f716b7 218 char reg[] = { 0, 0 };
rspelta 3:94aee6f716b7 219 char ret[] = { 0, 0 };
rspelta 3:94aee6f716b7 220 m_i2c->write(m_addr, &reg[0], 2);
rspelta 3:94aee6f716b7 221 m_i2c->read(m_addr, ret, 1 );
rspelta 3:94aee6f716b7 222 printf("%02x, %02x, %02x\n\r", ret[0], ret[1], m_addr );
rspelta 3:94aee6f716b7 223 #else
rspelta 3:94aee6f716b7 224 char reg[] = { 0x0FU, 0 };
rspelta 3:94aee6f716b7 225 char ret[] = { 0, 0 };
rspelta 3:94aee6f716b7 226 m_i2c->frequency(400000);
rspelta 3:94aee6f716b7 227 m_i2c->write(0xBE, &reg[0], 1, 1);
rspelta 3:94aee6f716b7 228 m_i2c->read(0xBE, ret, 1 );
rspelta 3:94aee6f716b7 229 printf("%02x, %02x, %02x\n\r", ret[0], ret[1], m_addr );
rspelta 3:94aee6f716b7 230 #endif
rspelta 3:94aee6f716b7 231 return ret[0];*/
rspelta 3:94aee6f716b7 232 }
rspelta 3:94aee6f716b7 233
rspelta 3:94aee6f716b7 234 uint16_t VL6180x::VL6180x_getRegister16bit(uint16_t registerAddr)
rspelta 3:94aee6f716b7 235 {
rspelta 3:94aee6f716b7 236 uint8_t data_low;
rspelta 3:94aee6f716b7 237 uint8_t data_high;
rspelta 3:94aee6f716b7 238 uint16_t data;
rspelta 3:94aee6f716b7 239
rspelta 3:94aee6f716b7 240 char data_write[2];
rspelta 3:94aee6f716b7 241 char data_read[2];
rspelta 3:94aee6f716b7 242 data_write[0] = (registerAddr >> 8) & 0xFF; //MSB of register address
rspelta 3:94aee6f716b7 243 data_write[1] = registerAddr & 0xFF; //LSB of register address
rspelta 3:94aee6f716b7 244 m_i2c->write(m_addr, data_write, 2,0);
rspelta 3:94aee6f716b7 245 m_i2c->read(m_addr,data_read,2,1);
rspelta 3:94aee6f716b7 246 data_high = data_read[0]; //Read Data from selected register
rspelta 3:94aee6f716b7 247 data_low = data_read[1]; //Read Data from selected register
rspelta 3:94aee6f716b7 248 data = (data_high << 8)|data_low;
rspelta 3:94aee6f716b7 249
rspelta 3:94aee6f716b7 250 return data;
rspelta 3:94aee6f716b7 251 }
rspelta 3:94aee6f716b7 252
rspelta 3:94aee6f716b7 253 void VL6180x::PE1801_setRegister(uint8_t registerAddr, uint8_t data)
rspelta 3:94aee6f716b7 254 {
rspelta 3:94aee6f716b7 255 char w2_data[2];
rspelta 3:94aee6f716b7 256
rspelta 3:94aee6f716b7 257 w2_data[0] = registerAddr;
rspelta 3:94aee6f716b7 258 w2_data[1] = data;
rspelta 3:94aee6f716b7 259 m_i2c->write( PE180_ADDRESS, w2_data, 2 );
rspelta 3:94aee6f716b7 260 }
rspelta 3:94aee6f716b7 261
rspelta 3:94aee6f716b7 262 void VL6180x::VL6180x_setRegister(uint16_t registerAddr, uint8_t data)
rspelta 3:94aee6f716b7 263 {
rspelta 3:94aee6f716b7 264 char data_write[3];
rspelta 3:94aee6f716b7 265 data_write[0] = (registerAddr >> 8) & 0xFF; //MSB of register address
rspelta 3:94aee6f716b7 266 data_write[1] = registerAddr & 0xFF; //LSB of register address
rspelta 3:94aee6f716b7 267 data_write[2] = data & 0xFF;
rspelta 3:94aee6f716b7 268 m_i2c->write(m_addr, data_write, 3);
rspelta 3:94aee6f716b7 269 }
rspelta 3:94aee6f716b7 270
rspelta 3:94aee6f716b7 271 void VL6180x::VL6180x_setRegister16bit(uint16_t registerAddr, uint16_t data)
rspelta 3:94aee6f716b7 272 {
rspelta 3:94aee6f716b7 273 char data_write[4];
rspelta 3:94aee6f716b7 274 data_write[0] = (registerAddr >> 8) & 0xFF; //MSB of register address
rspelta 3:94aee6f716b7 275 data_write[1] = registerAddr & 0xFF; //LSB of register address
rspelta 3:94aee6f716b7 276 data_write[2] = (data >> 8) & 0xFF;
rspelta 3:94aee6f716b7 277 data_write[3] = data & 0xFF;
rspelta 3:94aee6f716b7 278 m_i2c->write(m_addr, data_write, 4);
rspelta 3:94aee6f716b7 279 }