Class: IoT::MAX44009
- Inherits:
-
Object
- Object
- IoT::MAX44009
- Defined in:
- lib/iot/max44009.rb
Overview
MAX44009 - low-power ambient Light Sensor Output: digital, Bus: I²C, Range: 0.045..188,000 Lux, VCC: 1.7..3.6V, Operating Current: 0.65µA datasheets.maximintegrated.com/en/ds/MAX44009.pdf
Constant Summary collapse
- MAX44009_DEFAULT_ADDRESS =
0x4A
- MAX44009_REG_INTR_STATUS =
MAX44009 Register Map
0x00
- MAX44009_REG_INTR_ENABLE =
Interrupt Status Register
0x01
- MAX44009_REG_CONFIG =
Interrupt Enable Register
0x02
- MAX44009_REG_LUX_HIGH =
Configuration Register
0x03
- MAX44009_REG_LUX_LOW =
Lux High Byte
0x04
- MAX44009_REG_THRES_UP_HI =
Lux Low Byte
0x05
- MAX44009_REG_THRES_LO_HI =
Upper Threshold High Byte
0x06
- MAX44009_REG_THRES_TIMER =
Upper Threshold Low Byte
0x07
- MAX44009_REG_INTR_ENABLE_NO_ASSRT =
MAX44009 INTERRUPT ENABLE REGISTER
0x00
- MAX44009_REG_INTR_ENABLE_TRIGGER =
The INT pin and the INTS bit are not asserted even if an interrupt event has occurred
0x01
- MAX44009_REG_CONFIG_CONTMODE_DEFAULT =
MAX44009 CONFIGURATION REGISTER
0x00
- MAX44009_REG_CONFIG_CONTMODE_CONTIN =
Default mode
0x80
- MAX44009_REG_CONFIG_MANUAL_DEFAULT =
Continuous mode
0x00
- MAX44009_REG_CONFIG_MANUAL_MODEON =
Default mode of configuration is used for the IC
0x40
- MAX44009_REG_CONFIG_CDR_NODIVIDED =
Manual mode of configuration is used for the IC
0x00
- MAX44009_REG_CONFIG_CDR_DIVIDED =
Current not divided. All of the photodiode current goes to the ADC
0x08
- MAX44009_REG_CONFIG_INTRTIMER_800 =
Current divided by 8
0x00
- MAX44009_REG_CONFIG_INTRTIMER_400 =
Integration Time = 800ms, This is a preferred mode for boosting low-light sensitivity
0x01
- MAX44009_REG_CONFIG_INTRTIMER_200 =
Integration Time = 400ms
0x02
- MAX44009_REG_CONFIG_INTRTIMER_100 =
Integration Time = 200ms
0x03
- MAX44009_REG_CONFIG_INTRTIMER_50 =
Integration Time = 100ms, This is a preferred mode for high-brightness applications
0x04
- MAX44009_REG_CONFIG_INTRTIMER_25 =
Integration Time = 50ms, Manual Mode only
0x05
- MAX44009_REG_CONFIG_INTRTIMER_12_5 =
Integration Time = 25ms, Manual Mode only
0x06
- MAX44009_REG_CONFIG_INTRTIMER_6_25 =
Integration Time = 12.5ms, Manual Mode only
0x07
- DEVICE =
Integration Time = 6.25ms, Manual Mode only
MAX44009_DEFAULT_ADDRESS
Instance Method Summary collapse
-
#initialize(i2c_bus = '/dev/i2c-1') ⇒ MAX44009
constructor
I2C sensor address.
- #lux ⇒ Object
- #name ⇒ Object
- #read_sensor ⇒ Object
- #write_config ⇒ Object
Constructor Details
#initialize(i2c_bus = '/dev/i2c-1') ⇒ MAX44009
I2C sensor address
39 40 41 42 43 44 45 46 |
# File 'lib/iot/max44009.rb', line 39 def initialize(i2c_bus='/dev/i2c-1') @sensor_name = 'MAX44009' @i2c_bus = i2c_bus @device = I2CDevice.new(address: DEVICE, driver: I2CDevice::Driver::I2CDev.new(@i2c_bus)) write_config() @length = 2 @value = read_sensor end |
Instance Method Details
#lux ⇒ Object
64 65 66 67 68 |
# File 'lib/iot/max44009.rb', line 64 def lux # Return value in LX read_sensor @value end |
#name ⇒ Object
48 49 50 |
# File 'lib/iot/max44009.rb', line 48 def name @sensor_name end |
#read_sensor ⇒ Object
58 59 60 61 62 |
# File 'lib/iot/max44009.rb', line 58 def read_sensor # Read data back from MAX44009_REG_LUX_HIGH(0x03), 2 bytes, luminance MSB, luminance LSB data = @device.i2cget(MAX44009_REG_LUX_HIGH, 2) @value = data_to_lux(data) end |
#write_config ⇒ Object
52 53 54 55 56 |
# File 'lib/iot/max44009.rb', line 52 def write_config() # Select the configuration register data from the given provided values config = (MAX44009_REG_CONFIG_CONTMODE_CONTIN | MAX44009_REG_CONFIG_MANUAL_MODEON | MAX44009_REG_CONFIG_CDR_NODIVIDED | MAX44009_REG_CONFIG_INTRTIMER_800) @device.i2cset(MAX44009_REG_CONFIG, config) end |