Ejemplo n.º 1
0
def main():
    # How often to sample the ADS [sec]
    sampling = 0.5

    # Create an array of LEDs
    meter = led.meter([26, 12, 16, 20, 21], 13000, 15000)

    # Create the ADS
    sensor = ads1115.ADS1115()

    # Loop forever and display the results
    try:
        while True:
            light = sensor.read_adc(0)
            meter.display(light)

    except KeyboardInterrupt:
        print("Exit!", file=sys.stderr)
        meter.off()
Ejemplo n.º 2
0
def main():
    # How often to sample the BME [sec]
    sampling = 0.5

    try:
        # create an AF_INET, STREAM socket (TCP)
        udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    except socket.error as msg:
        print("Failed to create socket: {:s}".format(msg[1]), file=sys.stderr)
        sys.exit()

    # Create an array of LEDs
    meter = led.meter([26, 12, 16, 20, 21], min_value=21, max_value=24)

    # Create the ADS
    sensor = ads1115.ADS1115()

    # Loop forever and display the results
    while True:
        try:
            light = sensor.read_adc(0)
            temperature, pressure, humidity = bme280.readBME280All()
            meter.display(temperature)
            print("{:s},{:2.4f},{:4.4f},{:2.4f},{:d}".format(
                datetime.datetime.utcnow().strftime('%Y,%m,%d,%H,%M,%S.%f'),
                temperature, pressure, humidity, light))

            # Send data to the server
            msg = "{:d},{:f}".format(udp_user, temperature)
            udp.sendto(bytes(msg, 'utf-8'), (udp_host, udp_port))

            # Pause to set our sampling rate
            time.sleep(sampling)

        except KeyboardInterrupt:
            print("Exit!", file=sys.stderr)
            meter.off()
            sys.exit()
        except socket.error as msg:
            print("Server Error: {:s}".format(msg[1]), file=sys.stderr)
Ejemplo n.º 3
0
def main():
    # How often to sample the BME [sec]
    sampling = 0.5

    # Create an array of LEDs
    meter = led.meter([26, 12, 16, 20, 21], min_value=21, max_value=24)

    # Create the ADS
    sensor = ads1115.ADS1115()

    # Loop forever and display the results
    try:
        while True:
            light = sensor.read_adc(0)
            temperature, pressure, humidity = bme280.readBME280All()
            meter.display(temperature)
            print("{:s},{:2.4f},{:4.4f},{:2.4f},{:d}".format(
                datetime.utcnow().strftime('%Y,%m,%d,%H,%M,%S.%f'),
                temperature, pressure, humidity, light))

    except KeyboardInterrupt:
        print("Exit!", file=sys.stderr)
        meter.off()
Ejemplo n.º 4
0
 def __init__(self, i2c):
     self.i2c = i2c
     self.adc = ads1115.ADS1115(i2c)
     self.heating_pin = Pin(PIN_HEATING_NO2, Pin.OUT)
     self.red_val = 0
     self.ox_val = 0
Ejemplo n.º 5
0
from machine import I2C
from machine import Pin
import time
import ads1115

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
sensor = ads1115.ADS1115(i2c)
time.sleep_ms(500)

while True:
    # print(sensor.read())
    print(sensor.read(4, 0))
    time.sleep_ms(20)
Ejemplo n.º 6
0
# Live plotting ADC ADS1115's readings
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import sys
sys.path.append('../week3')
import ads1115

fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)

length = 100
sensor = ads1115.ADS1115()

D = []


def update(data):
    print data
    D.append(data)
    while len(D) > length:
        D.pop(0)
    line.set_xdata(range(0, len(D)))
    line.set_ydata(D)
    return line,


def data_gen():
    #while True:
    #yield np.random.rand(10)
Ejemplo n.º 7
0
global settings_flag
settings_flag = 0

spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 100000
spi.mode = 0b00

hv = MCP4725.MCP4725(address=0x60)
sv = MCP4725.MCP4725(address=0x61)
bme = BME280(t_mode=BME280_OSAMPLE_8,
             p_mode=BME280_OSAMPLE_8,
             h_mode=BME280_OSAMPLE_8)
pm = pmsensor.Honeywell()
adxl = adxl345.ADXL345()
ads = ads1115.ADS1115()

node1 = serial.Serial(port='/dev/rfcomm0', baudrate=9600, timeout=8)
node2 = serial.Serial(port='/dev/rfcomm1', baudrate=9600, timeout=8)

db = InfluxDBClient(database='log')


def set_sv(volt):
    global sv
    global sval
    val = int((float(volt) / gain) * 4096 / 3.3)
    if val > sval:
        i = sval
        while i < val:
            sv.set_voltage(i, False)
Ejemplo n.º 8
0
def adc_sensor_setup(_scl, _sda, _freq):
    print("Analogue to Digital Converter Sensor Setup")
    i2c = I2C(scl=Pin(_scl), sda=Pin(_sda), freq=_freq)
    s = ads1115.ADS1115(i2c)
    time.sleep_ms(500)
    return s