Beaglebone and VCNL4010 proximity and ambient light sensor python example

0
155
beaglebone and vcnl4010 layout
beaglebone and vcnl4010 layout

In this article we look at another acceleration sensor – this time its the VCNL4010 and we will connect it to our Beaglebone and we will have a python example

First lets take a look at the sensor in question

The VCNL4010 is a fully integrated proximity and ambient light sensor. Fully integrated means that the infrared emitter is included in the package. It has 16 bit resolution. It includes a signal processing IC and features standard I2C communication interface. It features an interrupt function.

PROXIMITY FUNCTION
• Built-in infrared emitter and photo-pin-diode for proximity
function
• 16 bit effective resolution for proximity detection range
ensures excellent cross talk immunity
• Programmable LED drive current from 10 mA to 200 mA in
10 mA steps
• Excellent ambient light suppression by modulating the
infrared signal
• Proximity distance up to 200 mm

AMBIENT LIGHT FUNCTION
• Built-in ambient light photo-pin-diode with close-tohuman-eye sensitivity
• 16 bit dynamic range from 0.25 lx to 16 klx
• 100 Hz and 120 Hz flicker noise rejection

FEATURES

• Integrated modules: infrared emitter (IRED), ambient light sensor (ALS-PD), proximity sensor (PD), and signal conditioning IC
• Interrupt function
• Supply voltage range VDD: 2.5 V to 3.6 V
• Supply voltage range IR anode: 2.5 V to 5 V
• Communication via I2C interface
• I2C Bus H-level range: 1.7 V to 5 V
• Low stand by current consumption: 1.5 μA

Parts Required

NameLink
BeagleboneBeagleBone Black TI AM335x Cortex-A8 development BB-Black Rev.C
VCNL4010Multiple Function Sensor Development Tools Proximity/Light Sensor VCNL4000 (1 piece)
Connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Schematic/Connection

beaglebone and vcnl4010 layout
beaglebone and vcnl4010 layout

Code Example

# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# VCNL4010
# This code is designed to work with the VCNL4010_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Light?sku=VCNL4010_I2CS#tabs-0-product_tabset-2
 
import smbus
import time
 
# Get I2C bus
bus = smbus.SMBus(1)
 
# VCNL4010 address, 0x13(19)
# Select command register, 0x80(128)
#		0xFF(255)	Enable ALS and proximity measurement, LP oscillator
bus.write_byte_data(0x13, 0x80, 0xFF)
# VCNL4010 address, 0x13(19)
# Select proximity rate register, 0x82(130)
#		0x00(00)	1.95 proximity measeurements/sec
bus.write_byte_data(0x13, 0x82, 0x00)
# VCNL4010 address, 0x13(19)
# Select ambient light register, 0x84(132)
#		0x9D(157)	Continuos conversion mode, ALS rate 2 samples/sec
bus.write_byte_data(0x13, 0x84, 0x9D)
 
time.sleep(0.8)
 
# VCNL4010 address, 0x13(19)
# Read data back from 0x85(133), 4 bytes
# luminance MSB, luminance LSB, Proximity MSB, Proximity LSB
data = bus.read_i2c_block_data(0x13, 0x85, 4)
 
# Convert the data
luminance = data[0] * 256 + data[1]
proximity = data[2] * 256 + data[3]
 
# Output data to screen
print "Ambient Light Luminance : %d lux" %luminance
print "Proximity of the Device : %d" %proximity

 

Output

Run this example and you should see the following , cover the sensor and alter the light on it

vcnl4010 output
vcnl4010 output

Links

https://www.vishay.com/docs/83462/vcnl4010.pdf

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.