Arduino nano BLE sense use gesture (APDS9960) and other I2C device with Wire lib

Got an Arduino nano BLE sense, using the light sensor.

This code working :

#include <Arduino_APDS9960.h>
void setup() {
    Serial.begin(9600);
    APDS.begin();
}

void loop() {
    if (APDS.colorAvailable()){
        int r, g, b, alpha;
        APDS.readColor(r, g, b, alpha);
        Serial.print("alpha: ");
        Serial.println(alpha);
    }
    delay(100);
}

I want to send alpha value to an other Arduino by I2C protocol.
After connecting the other board and verify the communication is valid, I get this code:

#include <Arduino_APDS9960.h>
#include <Wire.h>

void setup() {
    Serial.begin(9600);
    APDS.begin();
    Wire.begin(); // Begin Wire as master ...
}

void loop() {
    if (APDS.colorAvailable()){
        int r, g, b, alpha;
        APDS.readColor(r, g, b, alpha);
        Wire.beginTransmission(10);
        Wire.write(alpha);
        Wire.endTransmission();
    }
    delay(100);
}

With the above code, the condition APDS.colorAvailable() is never True.
I don't know why ... Probably because I instantiate the Wire library ?

The APDS9960 library already initializes the I2C peripheral. Have a look into the Arduino_APDS9960 library. The two file are not very complicated. You can find it in the libraries folder inside your projects folder.

What happens when you comment this line: Wire.begin(); // Begin Wire as master ... ?

If that does not work you could change the order in setup() and see what happens then.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.