done.
This commit is contained in:
parent
c6582fdc97
commit
fa6e90cbe0
12
SI1145.py
12
SI1145.py
@ -22,10 +22,12 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
import logging
|
#import logging
|
||||||
import time
|
import time
|
||||||
|
from translate_layer import I2C_Device
|
||||||
|
|
||||||
|
#import Adafruit_GPIO.I2C as I2C
|
||||||
|
|
||||||
import Adafruit_GPIO.I2C as I2C
|
|
||||||
|
|
||||||
# COMMANDS
|
# COMMANDS
|
||||||
SI1145_PARAM_QUERY = 0x80
|
SI1145_PARAM_QUERY = 0x80
|
||||||
@ -152,12 +154,10 @@ SI1145_REG_CHIPSTAT = 0x30
|
|||||||
SI1145_ADDR = 0x60
|
SI1145_ADDR = 0x60
|
||||||
|
|
||||||
class SI1145(object):
|
class SI1145(object):
|
||||||
def __init__(self, address=SI1145_ADDR, busnum=I2C.get_default_bus()):
|
def __init__(self, i2cbus, address=SI1145_ADDR):
|
||||||
|
|
||||||
self._logger = logging.getLogger('SI1145')
|
|
||||||
|
|
||||||
# Create I2C device.
|
# Create I2C device.
|
||||||
self._device = I2C.Device(address, busnum)
|
self._device = I2C_Device(i2cbus, address)
|
||||||
|
|
||||||
#reset device
|
#reset device
|
||||||
self._reset()
|
self._reset()
|
||||||
|
12
boot.py
12
boot.py
@ -1,8 +1,16 @@
|
|||||||
|
|
||||||
import machine
|
import machine
|
||||||
import SI1145.py
|
import time
|
||||||
|
import SI1145
|
||||||
|
|
||||||
i2c = machine.I2C(scl=machine.Pin(27), sda=machine.Pin(26))
|
i2c = machine.I2C(scl=machine.Pin(27), sda=machine.Pin(26))
|
||||||
i2c_addr = 0x60 # default ADDR for SI1145
|
|
||||||
|
|
||||||
|
s = SI1145.SI1145(i2c)
|
||||||
|
|
||||||
|
s.readIR()
|
||||||
|
s.readUV()
|
||||||
|
s.readVisible()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
19
translate_layer.py
Normal file
19
translate_layer.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class I2C_Device:
|
||||||
|
def __init__(self, i2c_dev, i2c_addr):
|
||||||
|
self._device = i2c_dev
|
||||||
|
self._addr = i2c_addr
|
||||||
|
|
||||||
|
def write8(self, register, data):
|
||||||
|
b = data.to_bytes(1, 'little')
|
||||||
|
self._device.writeto_mem(self._addr, register, b)
|
||||||
|
|
||||||
|
def readU8(self, register):
|
||||||
|
result = self._device.readfrom_mem(self._addr, register, 1)
|
||||||
|
return result[0]
|
||||||
|
|
||||||
|
def readU16LE(self, register):
|
||||||
|
result = self._device.readfrom_mem(self._addr, register, 2)
|
||||||
|
r = int.from_bytes(result, 'little')
|
||||||
|
return r
|
Loading…
Reference in New Issue
Block a user