- sudo apt-get install -y python-smbus
- pip install opt3001
import opt3001 from opt3001
address = 0x44
opt = opt3001.OPT3001(address)
# Configure to run in Continuous conversions mode
opt.write_config_reg(opt3001.I2C_LS_CONFIG_CONT_FULL_800MS)
while(True):
print(opt.read_lux_float())
time.sleep(1)
Add following line to /etc/modules
to start i2c module on startup:
i2c_dev
Run following commands to start the i2c modules manually:
$ modprobe i2c-bcm2708
$ modprobe i2c_dev
Install i2c-tools
to test with the terminal
$ sudo apt-get install i2c-tools
Run following command to get the address of the opt3001
$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Run the following command to test the opt30001
$ i2cget -y 1 0x44 0x00
0x0b
Constant | Description | Value |
---|---|---|
I2C_LS_CONFIG_DEFAULT | OPT3001 default settings | 0xc810 |
I2C_LS_CONFIG_CONT_FULL_800MS | settings for continuous measurement | 0xcc10 |
I2C_LS_REG_RESULT | Result Register | 0x00 |
I2C_LS_REG_CONFIG | Configuration Register | 0x01 |
I2C_LS_REG_LOWLIMIT | Low Limit Register | 0x02 |
I2C_LS_REG_HIGHLIMIT | High Limit Register | 0x03 |
I2C_LS_REG_MANUFACTURERID | Manufacturer ID | 0x7E |
I2C_LS_REG_DEVICEID | Device ID Register | 0x7F |
Input:
- address - i2c address of the opt3001
- bus - default 1
Read the brightness of the opt3001 with two fixed decimal places
Read the brightness of the opt3001 as float
Read manufacture id of the opt3001
Read device id of the opt3001
Write data to config register
Input:
- data - configuration data to write to registry
reads a register of the opt3001
Write to a register of the opt3001
Input:
- adr - registeradress to write to
- data - 16bit data to write to registry
python setup.py sdist bdist_wheel
twine upload dist/*
- Thomas Pöhlmann (@perryrh0dan)
This repository was generated by tmpo