Wish VEML6075 Library wrap

thetahsk

Active Member
Licensed User
Longtime User
I give up. I can't wrap libraries. The data I get is nonsensical.
Can someone wrap either...

Don't give up.
Here's a small example of an quick and dirty transportation from veml6075_fulltest.ino to B4R.
Install the Adafruit BUS-IO libs https://www.arduinolibraries.info/libraries/adafruit-bus-io and the VEML6075 libs in your Arduino IDE.



B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Private UVA,UVB,UVI As Float
    Private timer1 As Timer
End Sub


Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    VEML6075_Setup
    timer1.Initialize("timer1_Tick",1000)
    timer1.Enabled=True
End Sub

Sub timer1_Tick
    RunNative("read_UVA_UVB_UVIndex",1)    ' 0 for simulation / 1 for normal operation
    Log("UVA=",UVA," UVB=",UVB," UVI=",UVI)
End Sub


Sub VEML6075_Setup()
    RunNative("setup", Null)
End Sub



#if C
    
 // https://github.com/adafruit/Adafruit_VEML6075/tree/master/examples/veml6075_fulltest
#include <Wire.h>
#include <Adafruit_VEML6075.h>

Adafruit_VEML6075 uv = Adafruit_VEML6075();

void setup(B4R::Object* o) {
  Serial.begin(115200);
  Serial.println("VEML6075 Full Test");
  if (! uv.begin()) {
    Serial.println("Failed to communicate with VEML6075 sensor, check wiring?");
      
  }
  Serial.println("Found VEML6075 sensor");
   // Set the integration constant
  uv.setIntegrationTime(VEML6075_100MS);
  // Get the integration constant and print it!
  Serial.print("Integration time set to ");
  switch (uv.getIntegrationTime()) {
    case VEML6075_50MS: Serial.print("50"); break;
    case VEML6075_100MS: Serial.print("100"); break;
    case VEML6075_200MS: Serial.print("200"); break;
    case VEML6075_400MS: Serial.print("400"); break;
    case VEML6075_800MS: Serial.print("800"); break;
  }
  Serial.println("ms");

  // Set the high dynamic mode
  uv.setHighDynamic(true);
  // Get the mode
  if (uv.getHighDynamic()) {
    Serial.println("High dynamic reading mode");
  } else {
    Serial.println("Normal dynamic reading mode");
  }

  // Set the mode
  uv.setForcedMode(false);
  // Get the mode
  if (uv.getForcedMode()) {
    Serial.println("Forced reading mode");
  } else {
    Serial.println("Continuous reading mode");
  }

  // Set the calibration coefficients
  uv.setCoefficients(2.22, 1.33,  // UVA_A and UVA_B coefficients
                     2.95, 1.74,  // UVB_C and UVB_D coefficients
                     0.001461, 0.002591); // UVA and UVB responses
  }
 
 
 void read_UVA_UVB_UVIndex(B4R::Object* o) {
 
  if (o->toULong()<1) {
  Serial.println("Simulation ");
  b4r_main::_uva=1.1;
  b4r_main::_uvb=2.22;
  b4r_main::_uvi=3.333;
 
  }
  else
  {
  b4r_main::_uva=uv.readUVA();
  b4r_main::_uvb=uv.readUVB();
  b4r_main::_uvi=uv.readUVI();
 
  Serial.print("Raw UVA reading:  "); Serial.println(uv.readUVA());
  Serial.print("Raw UVB reading:  "); Serial.println(uv.readUVB());
  Serial.print("UV Index reading: "); Serial.println(uv.readUVI());
 }
}
 
#end if
 
Last edited:
Top