Esempio n. 1
0
    def read(self, SIO):
        i2c = busio.I2C(board.SCL, board.SDA,
                        frequency=100000)  # freq slower for pm25
        sensor = AS726x_I2C(i2c)
        sensor.integration_time = self.T_integ
        sensor.gain = 64  # 1., 3.7, 16., 64.]
        sensor.start_measurement()
        self.t = time.time()
        time.sleep(2 * self.T_integ / 1000.)
        while not sensor.data_ready:
            time.sleep(0.05)

        # "typical" 45 counts / uW/cm^2 at gain 16, 166 ms integration
        n = 16 * 166 / (45. * self.T_integ * sensor.gain)  # normalization
        r, o, y, g, b, v = sensor.red * n, sensor.orange * n, sensor.yellow * n, sensor.green * n, sensor.blue * n, sensor.violet * n

        self.spectrum = (r, o, y, g, b, v)
        self.T = sensor.temperature
        self.raw = (sensor.raw_red, sensor.raw_orange, sensor.raw_yellow,
                    sensor.raw_green, sensor.raw_blue, sensor.raw_violet)

        print("\nAS726x spectrum (uW/cm^2) over", self.T_integ, "ms, at",
              self.T, "deg. C:")
        print(" * R", r, self.raw[0])
        print(" * O", o, self.raw[1])
        print(" * Y", y, self.raw[2])
        print(" * G", g, self.raw[3])
        print(" * B", b, self.raw[4])
        print(" * V", v, self.raw[5])

        SIO.log_readout(self.R_id, r, self.t)
        SIO.log_readout(self.O_id, o, self.t)
        SIO.log_readout(self.Y_id, y, self.t)
        SIO.log_readout(self.G_id, g, self.t)
        SIO.log_readout(self.B_id, b, self.t)
        SIO.log_readout(self.V_id, v, self.t)
        SIO.log_readout(self.T_id, self.T, self.t)

        # adjust for next readout
        rmax = max(self.raw)
        if rmax: self.T_integ = min(max((2**15) * self.T_integ / rmax, 3), 700)
        else: self.T_integ = 700
Esempio n. 2
0
import typer

from adafruit_as726x import AS726x_I2C
import adafruit_tca9548a
import board
import busio

# Initialize I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# mux
tca2 = adafruit_tca9548a.TCA9548A(i2c, address=0x72)


# spectral triad
ls = AS726x_I2C(tca2[6])
ls.conversion_mode = ls.MODE_2

# maximum value for ls reading
max_val = 16000

# max number of characters in each graph
max_graph = 80


def graph_map(x):
    return min(int(x * max_graph / max_val), max_graph)


def main(num: int = 100):
    for i in range(num):
Esempio n. 3
0
# from adafruit_as726x import AS726x_UART

# maximum value for sensor reading
max_val = 16000

# max number of characters in each graph
max_graph = 80


def graph_map(x):
    return min(int(x * max_graph / max_val), max_graph)


# for I2C use:
i2c = busio.I2C(board.SCL, board.SDA)
sensor = AS726x_I2C(i2c)

# for UART use:
# uart = busio.UART(board.TX, board.RX)
# sensor = AS726x_UART(uart)

sensor.conversion_mode = sensor.MODE_2

while True:
    # Wait for data to be ready
    while not sensor.data_ready:
        time.sleep(0.1)

    # plot plot the data
    print("\n")
    print("V: " + graph_map(sensor.violet) * "=")