Main Content

apds9960

Connect to APDS9960 sensor on Arduino hardware using I2C bus

Description

The apds9960 object reads gesture, proximity, and measures clear light and color (RGB) values using the APDS9960 sensor connected to the I2C bus of the Arduino® hardware. You can read the data from the sensor in MATLAB® using the Object Functions.

Creation

Description

apds9960obj = apds9960(arduinoobj) creates a sensor object with default property values.

apds9960obj = apds9960(arduinoobj,Name,Value) creates a sensor object with properties using one or more name-value pair arguments.

Input Arguments

expand all

Connection to the hardware specified as an object.

Example: arduinoobj = arduino('COM4', 'Nano33BLE', 'Libraries', 'APDS9960') creates a connection to the APDS9960 sensor.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

BitRate sets the rate at which data is received from the sensor, ranging 100000 to 400000.

Example: apds9960obj = apds9960(arduinoobj,'BitRate',100000)

Data Types: double

I2C bus number, specified as 0 or 1. The default value is 0 for all Arduino boards except Nano 33 BLE Sense.

Example: apds9960obj = apds9960(arduinoobj, 'Bus', 1) creates the sensor object on the I2C Bus 1 of the hardware.

Data Types: double

Properties

expand all

This property is read-only.

I2C device address of the APDS9960 sensor, specified as a nonnegative integer.

Example:

>> apds9960obj.I2CAddress
ans = 
      57 

Data Types: double

This property is read-only.

I2C bus number, specified as 0 or 1. The default value is 0.

Example:

>> apds9960obj.Bus
ans = 
      0 

Data Types: double

This property is read-only.

The serial clock pin for the serial clock signal that the I2C central generates, returned as a character vector.

Example:

>> apds9960obj.SCLPin
ans = 
      'A5' 

Data Types: char

This property is read-only.

A serial data pin for a serial data signal, returned as a character vector.

Example:

>> apds9960obj.SDAPin
ans = 
      'A4' 

Data Types: char

This property is read-only.

The bus speed set for I2C communication, specified as a positive integer in bits/s.

Example:

>> apds9960obj.BitRate
ans = 
      100000

Data Types: double

You can access individual sensor properties for the sensor configurations such as Gesture, Proximity, and Color.

Proximity

Select gain for the proximity data value.

Example:

>> apds9960obj.Proximity.Gain = 4;

Sets the LED pulse width during a proximity pulse.

Example:

>> apds9960obj.Proximity.PulseWidth = 8;

Specifies the number of pulses to be generated on LED. For example, if you set the pulse count value to 8, the LED generates 8 pulses.

Example:

>> apds9960obj.Proximity.PulseCount =8;

Intensity of the IR emission is selectable using four, factory-calibrated, current levels. Sets LED Drive Strength in proximity mode.

Example:

>> apds9960obj.Proximity.LEDCurrent = 25;

Gesture

Select gain for the gesture data value.

Example:

>> apds9960obj.Gesture.Gain = 4;

Sets the LED pulse width during a gesture pulse.

Example:

>> apds9960obj.Gesture.PulseWidth = 8;

Specifies the number of pulses to be generated on LED. For example, if you set the pulse count value to 8, the LED generates 8 pulses.

Example:

>> apds9960obj.Gesture.PulseCount =8;

Intensity of the IR emission is selectable using four, factory calibrated, current levels. Sets LED Drive Strength in gesture mode.

Example:

>> apds9960obj.Gesture.LEDCurrent = 25;

Color

Select gain for the color data value.

Example:

>> apds9960obj.Color.Gain = 4;

Proximity and Gesture

If a higher intensity is required, then use the LED boost current to boost the current up to an additional 300%. Changing the LED boost current in the proximity configuration, changes the value of the gesture configuration and vice versa.

Example:

>> apds9960obj.Gesture.LEDBoost = 100;

Object Functions

readColorReads clear light and RGB components through APDS9960 sensor
readProximityRead the proximity from APDS9960 sensor
readGestureRead gesture through APDS9960 sensor

Examples

Create Connection to APDS9960 Sensor

Create an arduino object.

arduinoobj = arduino('COM4', 'Nano33BLE', 'Libraries', 'APDS9960')
  arduino with properties:

                  Port: 'COM4'
                 Board: 'Nano33BLE'
         AvailablePins: {'D0-D13', 'A0-A7'}
  AvailableDigitalPins: {'D0-D13', 'A0-A7'}
      AvailablePWMPins: {'D0-D13'}
   AvailableAnalogPins: {'A0-A3', 'A6-A7'}
    AvailableI2CBusIDs: [0, 1]
AvailableSerialPortIDs: [1]
             Libraries: {'APDS9960', 'I2C'}
Show all properties

Create the sensor object.

apds9960obj = apds9960(arduinoobj)
  APDS9960 with properties:

         I2CAddress: 57 ('0x39')
                Bus: 1
             SCLPin: 'SCL1'
             SDAPin: 'SDA1'
            BitRate: 100000 (bits/s)
Show all properties

Create Connection to APDS9960 Sensor with Name-Value pair arguments

Create a sensor object with the bus number 1 and bit rate of 400000.

clear apds9960obj;
apds9960obj = apds9960(arduinoobj, 'Bus', 1, 'BitRate', 400000)
  APDS9960 with properties:

         I2CAddress: 57 ('0x39')
                Bus: 1
             SCLPin: 'SCL1'
             SDAPin: 'SDA1'
            BitRate: 400000 (bits/s)
Show all properties

Change APDS9960 Sensor Configuration

Create a sensor object with the bus number 1 and bit rate of 400000.

clear apds9960obj;
apds9960obj = apds9960(arduinoobj, 'Bus', 1, 'BitRate', 100000)
  APDS9960 with properties:

         I2CAddress: 57 ('0x39')
                Bus: 1
             SCLPin: 'SCL1'
             SDAPin: 'SDA1'
            BitRate: 100000 (bits/s)
            Gesture: [1x1 GestureConfiguration]
          Proximity: [1x1 ProximityConfiguration]
              Color: [1x1 ColorConfiguration]

Access the gesture properties.

apds9960obj.Gesture
ans = 
  Gesture Configuration with properties:

         Gain: 4
   LEDCurrent: 100
     LEDBoost: 100
   PulseCount: 10
   PulseWidth: 8

Change the gesture gain value to 1 and display the gesture properties.

% Sensor configuration
% Change Gain settings of Gesture
apds9960obj.Gesture.Gain = 1;
% Display Gesture
apds9960obj.Gesture
ans = 
  Gesture Configuration with properties:

         Gain: 1
   LEDCurrent: 50
     LEDBoost: 100
   PulseCount: 50
   PulseWidth: 8
Introduced in R2021b