I'm hoping to use Adafruit proximity sensors through I2C on a Bela mini.
I was hoping I might be able to bring in their Arduino code and work through the process of modifying it to work with the Bela, but this might be way beyond me at the moment.

Some things I've tried so far:
- I've downloaded the Adafruit libraries from Github into he /Bela/Libraries folder
- I followed this tutorial to try and get the .h files available so that they can be found using #include. However so far I've not had any success and get the following error:
'Adafruit_VCNL4040.h' file not found column: 10, line: 2
/root/Bela/projects/Adafruit_4040/render.cpp:2:10: fatal error: 'Adafruit_VCNL4040.h' file not found
#include <Adafruit_VCNL4040.h>
I'd appreciate any pointers to get me headed in the right direction!

Thanks!
So actually that's where I started, but I obviously didn't give it enough time as I've now at least got it to see the files.
Thanks for the heads on the functions!

a month later

I've got a little further with this as follows:
I started with one of the Bela examples that uses I2c communication:
https://github.com/BelaPlatform/Bela/tree/master/examples/Sensors/MPR121
And have been modifying the Adafruit Arduino code from here;
https://github.com/adafruit/Adafruit_APDS9960

My code so far is here: https://github.com/coldesstu/Bela_Adafruit_9960/tree/main
Please ignore the fact that I've not renamed all the functions to something more relevant like APDS9960, for now I've just been trying to get it to work!

So far I believe I have managed to establish communication with the 9960 as this:
std::cout << "checking connection\n";
uint8_t c = readRegister8(APDS9960_ID);


if (c != 0xAB) {
rt_printf("MPR121 read 0x%x instead of 0xAB\n", c);
return false;
} else {
std::cout << static_cast<int>(c)<< "\n";
}
Outputs as follows:
command sent to device 146 - (92 in hex)
171 (AB in hex)

I'm not sure if the write register code is working, although it doesn't return an error:
Outputs as follows:
command sent to device 146 - (92 in hex)
171 (AB in hex)

I'm not sure if the write register code is working, although it doesn't return an error:
And when I run the auxiliary task in the Bela program, I just get 0 returned for the proximity reading.
One major difference from the Arduino code seems to be the interrupt pin, do I need to have this in order to read the proximity values? The only thing I seem to be able to read from the device is it's ID...
Any help or tips much appreciated!

ok as you are having trouble and I already did this yesterday for a different device, I gave a go at porting the Adafruit library for Linux with a Bela example:

https://github.com/giuliomoro/Adafruit_APDS9960-linux

This builds and runs but of course it fails for me as I don't have the sensor. Download the zip archive and drag it on the Bela IDE, that should prompt the creation of a new project. Setting the example variable in render.cpp will select one of the three examples from the original Arduino library which I tried to replicate. Let me know if you have trouble.

7 days later

Amazing! Thank you so much, for some reason I didn't get a notification of your reply, so I only just saw this today.

It looks like it's getting some reading, though there is also an error message when using the Proximity example. as you can see. I will try to get to the bottom of it!
alt text

The colour sensing seems to work as expected.

Ok I pushed a change that should fix that. Try again and let me know