TILE-SENSA reference

TILE-SENSA top

LED access

The RGB LED can be accessed on the following pins:

from machine import Pin, Signal

led_r = Signal('X2', Pin.OUT, value=0, invert=True)
led_g = Signal('X3', Pin.OUT, value=0, invert=True)
led_b = Signal('X4', Pin.OUT, value=0, invert=True)

led_r.on()
led_r.off()

HDC temperature and humidity sensor

A simple class to control and read the HDC2080 sensor is:

class HDC2080:
    def __init__(self, i2c, addr=64):
        self.i2c = i2c
        self.addr = addr

    def is_ready(self):
        return self.i2c.readfrom_mem(self.addr, 0x0f, 1)[0] & 1 == 0

    def measure(self):
        self.i2c.writeto_mem(self.addr, 0x0f, b'\x01')

    def temperature(self):
        data = self.i2c.readfrom_mem(self.addr, 0x00, 2)
        data = data[0] | data[1] << 8
        return data / 0x10000 * 165 - 40

    def humidity(self):
        data = self.i2c.readfrom_mem(self.addr, 0x02, 2)
        data = data[0] | data[1] << 8
        return data / 0x10000 * 100

Usage is:

import machine
machine.Pin('EN_3V3').on() # enable power on SENSA bus
i2c = machine.I2C('X')
hdc = HDC2080(i2c)
while True:
    hdc.measure()
    while not hdc.is_ready():
        machine.idle()
    print(hdc.temperature(), hdc.humidity())

OPT lux sensor

A simple class to control and read the OPT3001 sensor is:

class OPT3001:
    def __init__(self, i2c, addr=69):
        self.i2c = i2c
        self.addr = addr

    def is_ready(self):
        return bool(self.i2c.readfrom_mem(self.addr, 0x01, 2)[1] & 0x80)

    def measure(self):
        self.i2c.writeto_mem(self.addr, 0x01, b'\xca\x10')

    def lux(self):
        data = self.i2c.readfrom_mem(self.addr, 0, 2)
        return 0.01 * 2 ** (data[0] >> 4) * ((data[0] & 0x0f) << 8 | data[1])

Usage is:

import machine
machine.Pin('EN_3V3').on() # enable power on SENSA bus
i2c = machine.I2C('X')
opt = OPT3001(i2c)
while True:
    opt.measure()
    while not opt.is_ready():
        machine.idle()
    print(opt.lux())