Componentes

Sensor de luz ambiente OPT3001

O OPT3001 da TI mede a luz em lux como o olho a vê, de 0.01 a 83865 lux, com faixa automática, por I2C em 0x44.

Apelidos: módulo OPT3001, CJMCU-3001, ClosedCube OPT3001, medidor de lux. Seu filtro bloqueia o infravermelho, então ele concorda com o olho onde um fotodiodo comum lê alto sob luz incandescente. Uma tela escurece com ele; uma estufa registra dados com ele.

Pins

Pin O que faz
VCC, GND Alimentação, de 3 a 5 V na placa.
SCL, SDA I2C. A placa já traz os pull-ups.
INT A interrupção de limiar ou de conversão pronta, ativa em nível baixo.

Propriedades

address, 0x44 a 0x47. lux é a luz; o controle deslizante a altera.

Lendo no Arduino

Com a biblioteca da ClosedCube, que o Mokxi inclui como ClosedCube_OPT3001.h:

#include <ClosedCube_OPT3001.h>
ClosedCube_OPT3001 opt3001;

void setup() {
  Serial.begin(9600);
  opt3001.begin(0x44);
  OPT3001_Config config;
  config.rawData = 0;
  config.RangeNumber = 0b1100;
  config.ModeOfConversionOperation = 0b11;
  opt3001.writeConfig(config);
}

void loop() {
  Serial.println(opt3001.readResult().lux);
  delay(500);
}

Como ele se comunica

Sixteen-bit registers: 0x00 the result, an exponent and a twelve-bit mantissa, lux = 0.01 x 2^E x R; 0x01 the configuration (range, 100 or 800 ms, the mode and the flags); 0x02 and 0x03 the limits; 0x7E 0x5449 and 0x7F 0x3001. It powers up shut down; continuous mode converts every 100 or 800 ms and sets the conversion ready flag, which reading the configuration clears.

O que não é modelado

A contagem de falhas e a resposta espectral: o controle deslizante é a leitura.

Common mistakes

Reading the result before a conversion has finished: it reads zero until the first one, 100 or 800 ms after the mode is set.