Skip to content

Commit

Permalink
Update .ino
Browse files Browse the repository at this point in the history
  • Loading branch information
SauviaTron committed Nov 17, 2023
1 parent 299d330 commit b799f5c
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 1,338 deletions.
6 changes: 0 additions & 6 deletions 2_Firmware/.vscode/arduino.json

This file was deleted.

593 changes: 0 additions & 593 deletions 2_Firmware/.vscode/c_cpp_properties.json

This file was deleted.

6 changes: 0 additions & 6 deletions 2_Firmware/2_SensorPressure_BMP280/.vscode/arduino.json

This file was deleted.

597 changes: 0 additions & 597 deletions 2_Firmware/2_SensorPressure_BMP280/.vscode/c_cpp_properties.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


// > The libraries you need :
#include <Wire.h> // For I2C
#include <Wire.h> // For I2C
#include "BMP280_Functions.h" // Adafruit and custom library for BMP280


Expand Down
128 changes: 0 additions & 128 deletions 2_Firmware/2_VEML6040/2_VEML6040.ino

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Last Update: 17/11/2023
* Author: Andrea Sauviat
* E-mail: [email protected]
*
* Description: How to use the RGBW Light sensor ?
*
* GitHub : https://github.com/SauviaTron/Mini_RAK-Tracker
* Datasheet : https://www.vishay.com/docs/84276/veml6040.pdf
*
*/


// > The libraries you need :
#include <Wire.h> // For I2C
#include "VEML6040.h" // In order to use the VEML6040


// —————————————————————————————————————————————————————————————————————————————————————————————— //
// GLOBAL VARIABLES //
// —————————————————————————————————————————————————————————————————————————————————————————————— //

VEML6040 RGBWSensor;
uint16_t Red, Green, Blue, White, CCT ;
float AmbientLight ;

bool Enable_SerialPrint = true ; // Display information or not on the serial monitor


// —————————————————————————————————————————————————————————————————————————————————————————————— //
// SETUP() //
// —————————————————————————————————————————————————————————————————————————————————————————————— //

void setup() {

// > Configure the baud rate
Serial.begin( 115200 ) ;
while ( !Serial ) {} ; // Wait for the serial to be available
delay(2500) ; // Add a custom delay for user to 'see' the setup function


// > Welcome Msg
Serial.println( "Welcome to the VEML6040 test program ! " ) ;


// > Configure the I2C
Wire.begin();


// > Configure the RGBW Light Sensor
if( !RGBWSensor.begin() ) { // If the sensor can not boot up
Serial.println("ERROR: couldn't detect the sensor"); // Display n error msg
while(1){} // Do nothing
}
RGBWSensor.Configuration( );
// If you want to change the operating mode, the sampling and so on, that in the VEML6040_Configuration function.

}


// —————————————————————————————————————————————————————————————————————————————————————————————— //
// LOOP() //
// —————————————————————————————————————————————————————————————————————————————————————————————— //

void loop() {

// > New loop
Serial.println(".");

RGBWSensor.Configuration() ; delay(325) ; // Adding delay to the sensor wake-up
RGBWSensor.getData(&Red, &Green, &Blue, &White, &AmbientLight, &CCT ); // Get Sensor info
RGBWSensor.Sleep(); // Put back the sensor to sleep mode

delay(1000);

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdint.h>
/*
The MIT License (MIT)
Expand All @@ -23,12 +24,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <Arduino.h>
#include "Wire.h"
#ifndef __MATH_H
#include <math.h>
#endif
#include "veml6040.h"
#include "VEML6040.h"


VEML6040::VEML6040(void) {
Expand Down Expand Up @@ -71,19 +72,27 @@ uint16_t VEML6040::read(uint8_t commandCode) {
}

uint16_t VEML6040::getRed(void) {
return(read(COMMAND_CODE_RED));
uint16_t red = read(COMMAND_CODE_RED) ;
Serial.println( (String)"Red : " + red );
return red;
}

uint16_t VEML6040::getGreen(void) {
return(read(COMMAND_CODE_GREEN));
uint16_t green = read(COMMAND_CODE_GREEN) ;
Serial.println( (String)"Green : " + green );
return green;
}

uint16_t VEML6040::getBlue(void) {
return(read(COMMAND_CODE_BLUE));
uint16_t blue = read(COMMAND_CODE_BLUE) ;
Serial.println( (String)"Blue : " + blue );
return blue;
}

uint16_t VEML6040::getWhite(void) {
return(read(COMMAND_CODE_WHITE));
uint16_t white = read(COMMAND_CODE_WHITE) ;
Serial.println( (String)"White : " + white );
return white;
}

float VEML6040::getAmbientLight(void) {
Expand All @@ -109,6 +118,8 @@ float VEML6040::getAmbientLight(void) {
default: ambientLightInLux = -1;
break;
}

Serial.println( (String)"Ambient light : " + ambientLightInLux );
return ambientLightInLux;
}

Expand All @@ -123,6 +134,67 @@ uint16_t VEML6040::getCCT(float offset) {
ccti = ((float)red-(float)blue) / (float)green;
ccti = ccti + offset;
cct = 4278.6 * pow(ccti,-1.2455);


Serial.println( (String)"Correlated Color Temperature in 260K : " + (uint16_t)cct );
return((uint16_t)cct);
}

void VEML6040::Configuration( ) {

begin();
setConfiguration(VEML6040_IT_320MS + VEML6040_AF_AUTO + VEML6040_SD_ENABLE);
delay(10);
Serial.println(" VEML6040 - WakeUp");
}

void VEML6040::Sleep(){
setConfiguration( VEML6040_IT_40MS + // Integration Time setting
VEML6040_AF_AUTO + // Auto force mode - Auto
VEML6040_SD_DISABLE); // Chip shutdown - Disable Color sensor
Serial.println(" VEML6040 - Sleep");
}

void VEML6040::getData( uint16_t *Red, uint16_t *Green, uint16_t *Blue, uint16_t *White, float *AmbientLight, uint16_t *CCT ){

*Red = read(COMMAND_CODE_RED);
*Green = read(COMMAND_CODE_GREEN);
*Blue = read(COMMAND_CODE_BLUE);
*White = read(COMMAND_CODE_WHITE) ;

float ccti = ((float)*Red-(float)*Blue) / (float)*Green;
ccti = ccti + 0.5 ;
float CCT_float = 4278.6 * pow(ccti,-1.2455);
*CCT = (uint16_t)CCT_float ;

uint16_t sensorValue = *Green ;

switch(lastConfiguration & 0x70) {

case VEML6040_IT_40MS: *AmbientLight = sensorValue * VEML6040_GSENS_40MS;
break;
case VEML6040_IT_80MS: *AmbientLight = sensorValue * VEML6040_GSENS_80MS;
break;
case VEML6040_IT_160MS: *AmbientLight = sensorValue * VEML6040_GSENS_160MS;
break;
case VEML6040_IT_320MS: *AmbientLight = sensorValue * VEML6040_GSENS_320MS;
break;
case VEML6040_IT_640MS: *AmbientLight = sensorValue * VEML6040_GSENS_640MS;
break;
case VEML6040_IT_1280MS: *AmbientLight = sensorValue * VEML6040_GSENS_1280MS;
break;
default: *AmbientLight = -1;
break;
}

Serial.print( (String)" R(" + *Red );
Serial.print( (String)") G(" + *Green );
Serial.print( (String)") B(" + *Blue );
Serial.print( (String)") W(" + *White ); Serial.println(")") ;
Serial.println( (String)" Ambient light : " + *AmbientLight );
Serial.println( (String)" Correlated Color Temperature in 260K : " + *CCT );


}



Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class VEML6040 {
uint16_t getWhite(void);
uint16_t getCCT(float offset = 0.5);
float getAmbientLight(void);

void Configuration( );
void Sleep() ;
void getData( uint16_t *Red, uint16_t *Green, uint16_t *Blue, uint16_t *White, float *AmbientLight, uint16_t *CCT );
};

#endif

0 comments on commit b799f5c

Please sign in to comment.