0

VEML6070 and TCA9548A
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

VEML6070 and TCA9548A

by jsalloneword on Mon Nov 20, 2017 5:40 pm

Hello,
I am using the TCA9548A in order to read 3 x VEML6070 sensors into one Arduino device. I am firstly , just trying to get two sensors into the device. owever, I don't seem to be able to instance a second VEML6070 sensor correctly. I am trying to follow the format of the code on the tutorial you provided.
https://learn.adafruit.com/adafruit-tca ... g-and-test

You wire two HMC5883 magnetometers and I am aiming to follow the same principle with two VEML6070 sensors.
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "Adafruit_VEML6070.h"

#define TCAADDR 0x70

/* Assign a unique ID to this sensor at the same time */
//Adafruit_HMC5883_Unified mag1 = Adafruit_HMC5883_Unified(1);
//Adafruit_HMC5883_Unified mag2 = Adafruit_HMC5883_Unified(2);

Adafruit_VEML6070 uv1 = Adafruit_VEML6070(1);
Adafruit_VEML6070 uv2 = Adafruit_VEML6070(2);

void displaySensorDetails(Adafruit_VEML6070 *uv)
{
 // sensor_t sensor;
  uv.begin(VEML6070_1_T);  // pass in the integration time constant
  Serial.println("VEML6070 Test"); Serial.println("");
  delay(500);
}

void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
}


void setup(void)
{
  Serial.begin(115200);
  // Serial.println("VEML6070 Test");
  //uv.begin(VEML6070_1_T);  // pass in the integration time constant
  //Serial.println("VEML6070 Test"); Serial.println("");

  /* Initialise the 1st sensor */
  tcaselect(2);
  if (!uv1.begin())
  {
    /* There was a problem detecting the HMC5883 ... check your connections */
    Serial.println("Ooops, no VEML6070 detected ... Check your wiring!");
    while (1);
  }

  /* Initialise the 2nd sensor */
  tcaselect(6);
  if (!uv2.begin())
  {
    /* There was a problem detecting the HMC5883 ... check your connections */
    Serial.println("Ooops, no VEML6070 detected ... Check your wiring!");
    while (1);
  }

  /* Display some basic information on this sensor */
  tcaselect(2);
  displaySensorDetails(&uv1);
  tcaselect(6);
  displaySensorDetails(&uv2);
}

void loop(void)
{
  /* Get a new sensor event */
  //sensors_event_t event;

  tcaselect(2);
  uv1.getEvent(&event);

  /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
  Serial.print("Sensor #1 - ");
  Serial.print("UV: "); Serial.println(uv1.readUV(1));

  tcaselect(6);
  uv2.getEvent(&event);
  /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
  Serial.print("Sensor #2 - ");
  Serial.print("UV: "); Serial.println(uv2.readUV(2));
  delay(500);
}


I get this error "no matching function call to Adafruit_VEML6070 uv2 = Adafruit_VEML6070(int);
so I presume I am calling the second instance of the second sensor incorrectly and Adafruit_VEML6070 will not allow an integer to be parsed through in this way. Having looked at the VEML6070 library on github I'm unsure how to do this.

I have also tried
Code: Select all | TOGGLE FULL SIZE
Adafruit_VEML6070 uv1 = Adafruit_VEML6070();
Adafruit_VEML6070 uv2 = Adafruit_VEML6070();


and in void setup()
Code: Select all | TOGGLE FULL SIZE
  Serial.begin(115200);
  uv1.begin(VEML6070_1_T);  // pass in the integration time constant
  uv2.begin(VEML6070_1_T);  // pass in the integration time constant


but I still get an error regarding how I have instanced the second sensor. If anyone can point me towards documentation on this that would be great.
Thank you

jsalloneword
 
Posts: 24
Joined: Wed Sep 28, 2016 4:14 am

Re: VEML6070 and TCA9548A

by adafruit_support_bill on Mon Nov 20, 2017 6:28 pm

The constructor for the VEML6070 does not take an ID parameter. You can tell them apart by what channel you have selected on the multiplexer.

Code: Select all | TOGGLE FULL SIZE
Adafruit_VEML6070 uv1 = Adafruit_VEML6070();
Adafruit_VEML6070 uv2 = Adafruit_VEML6070();

adafruit_support_bill
 
Posts: 63486
Joined: Sat Feb 07, 2009 10:11 am

Re: VEML6070 and TCA9548A

by jsalloneword on Tue Nov 21, 2017 10:37 am

Hello, thanks for your reply. I did attempt without the ID parameter but the code still won't compile.

Code: Select all | TOGGLE FULL SIZE
 if (!uv2.begin())

This line bring up an error 'no matching function/call to VEML6070 .begin()

Am I amble to instance more than one VEML6070 with that library?

This is what i have stripped the code back to.
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "Adafruit_VEML6070.h"

#define TCAADDR 0x70

/* Assign a unique ID to this sensor at the same time */

Adafruit_VEML6070 uv1 = Adafruit_VEML6070();
Adafruit_VEML6070 uv2 = Adafruit_VEML6070();



void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
}


void setup(void)
{
  Serial.begin(115200);
  uv1.begin(VEML6070_1_T);  // pass in the integration time constant
  uv2.begin(VEML6070_1_T);  // pass in the integration time constant


  /* Initialise the 1st sensor */
  tcaselect(2);
  if (!uv1.begin())
  {
    /* There was a problem detecting the VEML6070 ... check your connections */
    Serial.println("Ooops, no VEML6070 detected ... Check your wiring!");
    while (1);
  }

  /* Initialise the 2nd sensor */
  tcaselect(6);
  if (!uv2.begin())
  {
    /* There was a problem detecting the VEML6070 ... check your connections */
    Serial.println("Ooops, no VEML6070 detected ... Check your wiring!");
    while (1);
  }




}

void loop(void)
{
  /* Get a new sensor event */


  tcaselect(2);
  /* Display the results  */
  Serial.print("Sensor #1 - ");
  Serial.print("UV: "); Serial.println(uv1.readUV(1));

  tcaselect(6);
  /* Display the results  */
  Serial.print("Sensor #2 - ");
  Serial.print("UV: "); Serial.println(uv2.readUV(2));
  delay(500);
}

jsalloneword
 
Posts: 24
Joined: Wed Sep 28, 2016 4:14 am

Re: VEML6070 and TCA9548A

by adafruit_support_bill on Tue Nov 21, 2017 11:12 am

You need to pass the integration time to the begin() function as described in the guide:
https://learn.adafruit.com/adafruit-vem ... #load-demo

Code: Select all | TOGGLE FULL SIZE
uv.begin(VEML6070_1_T)

adafruit_support_bill
 
Posts: 63486
Joined: Sat Feb 07, 2009 10:11 am

Re: VEML6070 and TCA9548A

by jsalloneword on Tue Nov 21, 2017 12:24 pm

thanks for your reply.
I am doing that already in the code above inside of void setup but it does not resolve the error.

jsalloneword
 
Posts: 24
Joined: Wed Sep 28, 2016 4:14 am

Re: VEML6070 and TCA9548A

by adafruit_support_bill on Tue Nov 21, 2017 12:41 pm

I am doing that already in the code above inside of void setup but it does not resolve the error.

But you are calling begin a second time for each sensor. And in the second call you are not providing the required integration time.

Code: Select all | TOGGLE FULL SIZE
  if (!uv1.begin())
  {
    /* There was a problem detecting the VEML6070 ... check your connections */
    Serial.println("Ooops, no VEML6070 detected ... Check your wiring!");
    while (1);
  }

  /* Initialise the 2nd sensor */
  tcaselect(6);
  if (!uv2.begin())
  {
    /* There was a problem detecting the VEML6070 ... check your connections */
    Serial.println("Ooops, no VEML6070 detected ... Check your wiring!");
    while (1);
  }

adafruit_support_bill
 
Posts: 63486
Joined: Sat Feb 07, 2009 10:11 am

Re: VEML6070 and TCA9548A

by jsalloneword on Tue Nov 21, 2017 1:21 pm

Sorry ! I see what you mean now yes.

I've actually just removed the if conditions as I can't parse uv.begin(VEML6070_1_T) as a boolean only as a function.
Thanks for your help.

Functioning code for anyone also in need.
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "Adafruit_VEML6070.h"

#define TCAADDR 0x70

/* Assign a unique ID to this sensor at the same time */

Adafruit_VEML6070 uv1 = Adafruit_VEML6070();
Adafruit_VEML6070 uv2 = Adafruit_VEML6070();



void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
}


void setup(void)
{
  Serial.begin(115200);
  uv1.begin(VEML6070_1_T);  // pass in the integration time constant
  tcaselect(2);
  uv2.begin(VEML6070_1_T);  // pass in the integration time constant
  tcaselect(0);

  /* Initialise the 1st sensor */
  // connection state
  boolean notConnected = true;


  while (notConnected) {

    /* There was a problem detecting the VEML6070 ... check your connections */
    Serial.println("Ooops, no VEML6070 detected ... Check your wiring!");
    notConnected = false;
   

  }

}






void loop(void)
{
  /* Get a new sensor event */


  tcaselect(2);
  /* Display the results  */
  Serial.print("Sensor #1 - ");
  Serial.print("UV: "); Serial.println(uv1.readUV());
  delay(1000);
  tcaselect(6);
  /* Display the results  */
  Serial.print("Sensor #2 - ");
  Serial.print("UV: "); Serial.println(uv2.readUV());
  delay(1000);
}

jsalloneword
 
Posts: 24
Joined: Wed Sep 28, 2016 4:14 am

Re: VEML6070 and TCA9548A

by adafruit_support_bill on Tue Nov 21, 2017 1:23 pm

Good to hear you have it working. Thanks for the follow-up.

adafruit_support_bill
 
Posts: 63486
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.