The APDS-9960 is an I2C device with advanced Gesture detection, Proximity detection, Digital Ambient Light Sense (ALS) and Color Sense (RGBC). It incorporates an IR LED and factory-calibrated LED driver.
Gesture detection
Gesture detection utilizes four directional photodiodes to
sense reflected IR energy (sourced by the integrated LED)
to convert physical motion information (i.e. velocity, direction and distance) to a digital information. The architecture of the gesture engine features automatic activation
(based on Proximity engine results), ambient light subtraction, cross-talk cancelation, dual 8-bit data converters, power saving inter-conversion delay, 32-dataset FIFO, and interrupt driven I2C communication. The gesture engine
accommodates a wide range of mobile device gesturing
requirements: simple UP-DOWN-RIGHT-LEFT gestures or
more complex gestures can be accurately sensed.
Code
1 2 3 4 5 6 7 8 9101112131415
importmachinefromtimeimportsleep_msfromuPy_APDS9960.apds9960LITEimportAPDS9960LITE#Init I2C Buss on RP2040sda=machine.Pin(12)scl=machine.Pin(13)i2c=machine.I2C(0,scl=scl,sda=sda)apds9960=APDS9960LITE(i2c)# Enable sensorapds9960.prox.enableSensor()# Enable Proximit sensingwhileTrue:sleep_ms(25)# wait for readout to be readyprint(apds9960.prox.proximityLevel)#Print the proximity value
Returns
1
0 1 1 1 1 1 0 1 1 2 2 1 1 1 1 1 0
Ambient Light
1 2 3 4 5 6 7 8 910111213141516171819202122
# from https://github.com/rlangoy/uPy_APDS9960importmachinefromtimeimportsleep,sleep_msfromAPDS9960LITEimportAPDS9960LITE#Init I2C Buss on RP2040sda=machine.Pin(12)scl=machine.Pin(13)i2c=machine.I2C(0,sda=sda,scl=scl,freq=400000)print(i2c)# create the driverapds9960=APDS9960LITE(i2c)apds9960.als.enableSensor()# Enable Light sensorsleep_ms(25)# Wait for readout to be ready#apds9960.powerOn(True)#print(apds9960.statusRegister())whileTrue:print(apds9960.als.ambientLightLevel,' ',end='')sleep(.1)
# from https://github.com/rlangoy/uPy_APDS9960frommachineimportPin,I2Cimportssd1306fromtimeimportsleep,sleep_msfromAPDS9960LITEimportAPDS9960LITE#Init I2C Buss on RP2040sda=Pin(12)scl=Pin(13)i2c=I2C(0,sda=sda,scl=scl,freq=400000)print(i2c)# create the driverapds9960=APDS9960LITE(i2c)apds9960.als.enableSensor()# Enable Light sensorsleep_ms(25)# Wait for readout to be ready# displayWIDTH=128ONE_THIRD_WIDTH=int(WIDTH/3)HEIGHT=64clock=Pin(2)data=Pin(3)RES=machine.Pin(4)DC=machine.Pin(5)CS=machine.Pin(6)spi=machine.SPI(0,sck=clock,mosi=data)oled=ssd1306.SSD1306_SPI(WIDTH,HEIGHT,spi,DC,RES,CS)defupdate_display(red,green,blue):oled.fill(0)# scale red, green and blue to the heightred=int(red*4)green=int(green*4)blue=int(blue*3)oled.fill(0)# rect_fill(x, y, width, height)oled.fill_rect(0,HEIGHT-red,ONE_THIRD_WIDTH,red,1)oled.fill_rect(ONE_THIRD_WIDTH,HEIGHT-green,ONE_THIRD_WIDTH,green,1)oled.fill_rect(ONE_THIRD_WIDTH*2,HEIGHT-blue,ONE_THIRD_WIDTH,blue,1)oled.text(str(red),0,56,0)oled.text(str(green),ONE_THIRD_WIDTH,56,0)oled.text(str(blue),ONE_THIRD_WIDTH*2,56,0)oled.show()whileTrue:# print(apds9960.als.ambientLightLevel,'', end='')red=apds9960.als.redLightLevelgreen=apds9960.als.greenLightLevelblue=apds9960.als.blueLightLevelupdate_display(red,green,blue)sleep(.05)