SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
cm32181_light.ino
Go to the documentation of this file.
1
30#include <Wire.h>
31#include <SPI.h>
32#include <Arduino.h>
33#include <LightSensorDrv.hpp>
34
35#ifndef SENSOR_SDA
36#define SENSOR_SDA 1
37#endif
38
39#ifndef SENSOR_SCL
40#define SENSOR_SCL 2
41#endif
42
43#ifndef SENSOR_IRQ
44#define SENSOR_IRQ 1
45#endif
46
48
49
50void setup()
51{
52 Serial.begin(115200);
53 while (!Serial);
54
55 pinMode(SENSOR_IRQ, INPUT_PULLUP);
56
57 if (!light.begin(Wire, CM32181_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
58 Serial.println("Failed to find CM32181 - check your wiring!");
59 while (1) {
60 delay(1000);
61 }
62 }
63
64 Serial.println("Init CM32181 Sensor success!");
65
66 int id = light.getChipID();
67 Serial.print("CM32181 ID = "); Serial.println(id);
68
69 /*
70 Sensitivity mode selection
71 SAMPLING_X1
72 SAMPLING_X2
73 SAMPLING_X1_8
74 SAMPLING_X1_4
75 */
77
78 //Power On sensor
79 light.powerOn();
80
81}
82
83
84void loop()
85{
86 // Get raw data
87 uint16_t raw = light.getRaw();
88
89 // Get conversion data , The manual does not provide information on how to obtain the
90 // calibration value, now use the calibration value 0.28 provided by the manual
91 float lux = light.getLux();
92 Serial.print(" RAW:"); Serial.print(raw);
93 Serial.print(" Lux:"); Serial.println(lux);
94 delay(500);
95}
96
97
98
@license MIT License
bool begin(SensorCommCustom::CustomCallback callback, uint8_t addr)
Initialize the sensor using custom callback interface.
High Sensitivity I2C Ambient Light Sensor (CM32181) driver.
void setSampling(Sampling sampling=SAMPLING_X1, IntegrationTime int_time=INTEGRATION_TIME_200MS)
Configure ALS sensitivity and integration time.
void powerOn()
Power on sensor (REG_ALS_CONF bit0 = 0).
float getLux()
Convert raw ALS to lux (approximate).
uint16_t getRaw()
Read raw ALS data (16-bit).
SensorCM32181 light
void setup()
#define SENSOR_SCL
#define SENSOR_SDA
#define SENSOR_IRQ
void loop()