Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
ClosedCube Arduino Library for
ClosedCube OPT3001 Digital Ambient Light Sensor (ALS) with High Precision Human Eye Response Breakout
Arduino and ESP32 Library for
OPT300x Digital Ambient Light Sensor Family (ALS) with High Precision Human Eye Response
=====================================================================================================

This is breakout board for [Texas Instruments OPT3001](http://www.ti.com/product/OPT3001) Digital Ambient Light Sensor (ALS) Sensor

[![](https://github.com/closedcube/ClosedCube_OPT3001_Arduino/blob/master/images/B060_OPT3001_Pic1.jpg)](https://www.tindie.com/stores/closedcube/)
[![](https://github.com/closedcube/ClosedCube_OPT3001_Arduino/blob/master/images/B060_OPT3001_Pic2.jpg)](https://www.tindie.com/stores/closedcube/)

### Where to Buy?

<a href="https://www.tindie.com/stores/closedcube/?ref=offsite_badges&utm_source=sellers_closedcube&utm_medium=badges&utm_campaign=badge_medium"><img src="https://d2ss6ovg47m0r5.cloudfront.net/badges/tindie-mediums.png" alt="I sell on Tindie" width="150" height="78"></a>
This Library was tested sucessfully with:
OPT3001 and OPT3004 on Arduino Uno and ESP32C6


120 changes: 0 additions & 120 deletions examples/opt3001demo/opt3001demo.ino

This file was deleted.

131 changes: 131 additions & 0 deletions examples/opt300xdemo/opt300xdemo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*

This is example for OPT300x Digital Ambient Light Sensor Family
Tested on OPT 3001 and 3004

Initial Date: 02-Dec-2015
Last Eddit: 05.07.2025 bs MS added ESP32 suport generalised frome OPT3001 to
OPT300x Family

Hardware connections for Arduino Uno:
VDD to 3.3V DC
SDA to A4
SCL to A5
GND to common ground

Written by AA for ClosedCube

MIT License

*/

#include "OPT300x.h"
#include <Wire.h>

OPT300x opt300x;

#define OPT300x_ADDRESS 0x44

// to suport ESP32 pin assignment, I2C pins need to be defined
#ifdef ESP32
#define I2C_SDA 6
#define I2C_SCL 7
#endif

void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("OPT300x Test");
delay(2000);
#ifdef ESP32
Wire.begin(I2C_SDA, I2C_SCL);
#else
Wire.begin();
#endif
opt300x.begin(OPT300x_ADDRESS);
Serial.print("OPT300x Manufacturer ID");
Serial.println(opt300x.readManufacturerID());
Serial.print("OPT300x Device ID");
Serial.println(opt300x.readDeviceID());

configureSensor();
printResult("High-Limit", opt300x.readHighLimit());
printResult("Low-Limit", opt300x.readLowLimit());
Serial.println("----");
}

void loop() {
OPT300x_S result = opt300x.readResult();
printResult("OPT300x", result);
delay(500);
}

void configureSensor() {
OPT300x_Config newConfig;

newConfig.RangeNumber = B1100;
newConfig.ConvertionTime = B0;
newConfig.Latch = B1;
newConfig.ModeOfConversionOperation = B11;

OPT300x_ErrorCode errorConfig = opt300x.writeConfig(newConfig);
if (errorConfig != NO_ERROR)
printError("OPT300x configuration", errorConfig);
else {
OPT300x_Config sensorConfig = opt300x.readConfig();
Serial.println("OPT300x Current Config:");
Serial.println("------------------------------");

Serial.print("Conversion ready (R):");
Serial.println(sensorConfig.ConversionReady, HEX);

Serial.print("Conversion time (R/W):");
Serial.println(sensorConfig.ConvertionTime, HEX);

Serial.print("Fault count field (R/W):");
Serial.println(sensorConfig.FaultCount, HEX);

Serial.print("Flag high field (R-only):");
Serial.println(sensorConfig.FlagHigh, HEX);

Serial.print("Flag low field (R-only):");
Serial.println(sensorConfig.FlagLow, HEX);

Serial.print("Latch field (R/W):");
Serial.println(sensorConfig.Latch, HEX);

Serial.print("Mask exponent field (R/W):");
Serial.println(sensorConfig.MaskExponent, HEX);

Serial.print("Mode of conversion operation (R/W):");
Serial.println(sensorConfig.ModeOfConversionOperation, HEX);

Serial.print("Polarity field (R/W):");
Serial.println(sensorConfig.Polarity, HEX);

Serial.print("Overflow flag (R-only):");
Serial.println(sensorConfig.OverflowFlag, HEX);

Serial.print("Range number (R/W):");
Serial.println(sensorConfig.RangeNumber, HEX);

Serial.println("------------------------------");
}
}

void printResult(String text, OPT300x_S result) {
if (result.error == NO_ERROR) {
Serial.print(text);
Serial.print(": ");
Serial.print(result.lux);
Serial.println(" lux");
} else {
printError(text, result.error);
}
}

void printError(String text, OPT300x_ErrorCode error) {
Serial.print(text);
Serial.print(": [ERROR] Code #");
Serial.println(error);
}
4 changes: 2 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
##################################################################
# Syntax Coloring Map For ClosedCube OPT3001 Digital Ambient Light Sensor Library
# Syntax Coloring Map For OPT300x Digital Ambient Light Sensor Library
##################################################################

##################################################################
# Datatypes (KEYWORD1)
##################################################################

ClosedCube_OPT3001 KEYWORD1
OPT300x KEYWORD1

##################################################################
# Methods and Functions (KEYWORD2)
Expand Down
16 changes: 8 additions & 8 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=ClosedCube OPT3001
version=1.1.2
author=ClosedCube
maintainer=ClosedCube <github@closedcube.com>
sentence=Arduino library for Texas Instruments OPT3001 Digital Ambient Light Sensor (ALS)
paragraph=Arduino library for Texas Instruments OPT3001 Digital Ambient Light Sensor (ALS)
name=OPT300x
version=1.2.0
author=ClosedCube and Miro Sieber
maintainer=Miro Sieber <your.email@example.com>
sentence=Arduino and ESP32 library for Texas Instruments OPT300x Digital Ambient Light Sensor Family
paragraph=This library provides an easy-to-use interface for the Texas Instruments OPT300x family of digital ambient light sensors, supporting initialization, configuration, and light intensity measurement over I2C. Compatible with Arduino and ESP32 platforms.
category=Sensors
url=https://github.com/closedcube/ClosedCube_OPT3001_Arduino
architectures=*
url=[https://github.com/mirosieber/OPT300x](https://github.com/mirosieber/OPT300x)
architectures=\*
Loading