I’m always excited to get my hands on new sensors, so when I saw the APDS-9960 RGB and gesture sensor breakout board from SparkFun I ordered one immediately. The neat thing about this sensor is that it does a lot for its tiny size and relatively low cost.
The features this sensor offers are:
- Proximity measurement
- Ambient light intensity measurement
- Color detection
- Simple gesture detection including left, right, up, down, foward, and back
- More complex gestures are apparently possible, although I haven’t seen evidence of this yet
SparkFun offers an Arduino library for the sensor, but no other platforms are supported yet. I really wanted to use the sensor with the Raspberry Pi so I quickly ported it. The connections I’m using are:
I put the code up on BitBucket at https://bitbucket.org/justin_woodman/apds-9960-raspberry-pi-library. You can clone the repository using:
In order to get it working you’ll need to install wiringPi for I2C and interrupt support. Just follow the installation instruction at the wiringPi website.
Once you have wiringPi installed you can build any of the examples. So the GestureTest example can be built using the compile string:
g++ -Wall -o GestureTest GestureTest.cpp APDS9960_RPi.cpp -lwiringPi
It’ll be easier to write makefiles for larger projects so you don’t have to keep doing that, but for testing it’s fine. Before you run the program you’ll need to set up I2C and the interrupt with:
gpio load i2c
gpio edge 7 falling
You might get a warning with the i2c load, which you can safely ignore. Run the program with:
And wave your hand over the sensor to see what it does. Neat right?? I’ll be digging further into this code to see if I can get more complex gesture sensing to work if someone doesn’t beat me to it. Have fun!