Exemplo n.º 1
0
def run_example():
    '''Runs all of the methods from the i2c driver. Imports are included in the
    method for re-importing any updates when testing.

    '''
    import si7021
    import machine
    i2c = machine.I2C(machine.Pin(5), machine.Pin(4))

    temp_sensor = si7021.Si7021(i2c)
    print('Serial:              {value}'.format(value=temp_sensor.serial))
    print('Identifier:          {value}'.format(value=temp_sensor.identifier))
    print('Temperature:         {value}'.format(value=temp_sensor.temperature))
    print('Relative Humidity:   {value}'.format(
        value=temp_sensor.relative_humidity))

    temp_sensor.reset()
    print('\nModule reset.\n')

    print('Temperature:         {value}'.format(value=temp_sensor.temperature))
    print('Relative Humidity:   {value}'.format(
        value=temp_sensor.relative_humidity))

    print('Fahrenheit:          {value}'.format(
        value=si7021.convert_celcius_to_fahrenheit(temp_sensor.temperature)))
Exemplo n.º 2
0
def fetch_and_publish():
    sensor = si7021.Si7021()

    client = umqtt.simple.MQTTClient(config['mqtt']['client_id'],
                                     config['mqtt']['broker']['server'])
    client.connect()

    client.publish(config['mqtt']['topic'].encode('ascii'),
                   json.dumps({
                       'temperature': sensor.readTemp(),
                       'humidity': sensor.readRH()
                    }).encode('ascii')
                   )
    client.disconnect()
def get():
    import logging
    logger = logging.getLogger(__name__)
    import machine
    import si7021
    from utime import sleep

    #esp8266: i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
    i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
    try:
        sensor = si7021.Si7021(i2c)
        sample = {}
        sample["value1"] = round(sensor.relative_humidity, 1)
        sample["value2"] = round(
            si7021.convert_celcius_to_fahrenheit(sensor.temperature_quick), 1)
    except:
        sample = None
    return sample
import si7021
import machine
from machine import Pin, I2C  
i2c = I2C(scl=Pin(22), sda=Pin(21)) #ESP32 Dev Board /myown
temp_sensor = si7021.Si7021(i2c)
print('Temp :{value}'.format(value=temp_sensor.temperature))
print('Humid:{value}'.format(value=temp_sensor.relative_humidity))
#print (temp_sensor.temperature)
#print (temp_sensor.relative_humidity)
Exemplo n.º 5
0
dhtPin = 13  # DHT wired to pin 13
loopTime = 1  # Short pause single measurements
count = 1  # single measurement

# For DHT22 - This sensor does not seem too accurate

# Set up object for reading sensors

dht22 = dht.DHT22(machine.Pin(dhtPin))
dhtTempUnit = 'C'
dhtRHUnit = 'RH'
dhtTempId = '02001'
dhtHumId = '02002'

# For si7021 - using default I2C address
SiBoard = si7021.Si7021()
siTempUnit = 'C'
siRHUnit = 'RH'
siTempId = '02003'
siHumId = '02004'

# set up socket
# Get local IP address
wlan = network.WLAN(network.STA_IF)
hostip = wlan.ifconfig()[0]
port = 10000

# Open a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = (hostip, port)
sock.bind(server_address)
Exemplo n.º 6
0
while True:
    print("\r\n\r\nPacket No #{}".format(cnt))
    temp, pa, hum = bme.values
    print("*********************")
    print("BME280/BMP280 values:")
    print("*********************")
    temp, pa, hum = bme.values
    print('temp:', temp, ' Hum:', hum, 'PA:', pa)
    d.fill(0)
    d.text("#", 95, 50)
    d.text(str(cnt), 102, 50)
    d.text("Temp. " + temp, 0, 0)
    d.text("PA " + pa, 0, 20)
    #time.sleep(5)

    tsensor = si7021.Si7021(i2c)
    print("**************")
    print("Si7021 values:")
    print("**************")
    print('temp:', tsensor.temperature, ' Hum:', tsensor.relative_humidity)

    d.text("Hum. " + str(round(tsensor.relative_humidity, 2)), 0, 10)
    d.show()

    if s.data_ready():
        print("**************")
        print("CSS811 values:")
        print("**************")
        print('eCO2: %d ppm, TVOC: %d ppb' % (s.eCO2, s.tVOC))

        d.text('eCO2 ppm', 0, 30)
Exemplo n.º 7
0
#function to read user input for Mode E: Custom 
def custom_mode():
        Threshold_Temp = input("Threshold Temperature: ")
        Threshold_RH = input("Threshold Humidity: ")
        Threshold_Light = input("Threshold Light Intensity: ")
        value = "You have selected:\n"
        value += "Threshold Temperature: " + str(Threshold_Temp) + " C\n"
        value += "Threshold Humidity: "+ str(Threshold_RH)+" %\n"
        value += "Threshold Light Intensity: " + str(Threshold_Light)+" lux\n"
        print(value)


        
i2c = I2C(scl=Pin(5),sda=Pin(4), freq=100000)   #address of the slave
thsensor = si7021.Si7021(i2c)                   #connect ESP8266 to temperature and humidity sensor
luxsensor = tsl2561.TSL2561(i2c)                #connect ESP8266 to light sensor

#connection to wifi
print('Connecting Wifi...')
ap_if = network.WLAN(network.AP_IF)
ap_if.active(False)

sta_if =network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Andy','12345678') #used our own hotspot  
while not sta_if.isconnected():
	pass
print('Wifi Connected')

#connection to MQTT ( thingspeak mqtt broker used here )
# debugging for other modules
esp.osdebug(esp.LOG_ERROR)
pms5003.set_debug(False)
asyncio.set_debug(False)
asyncio.core.set_debug(False)
MQTTClient.DEBUG = False

operating_mode = NORMAL_MODE

log.info('Reset Cause = %d', machine.reset_cause())

i2c = I2C(scl=Pin(26), sda=Pin(27))
ds3231 = urtc.DS3231(i2c, address=0x68)
adc = ADS1219(i2c, address=0x41)
temp_humid_sensor = si7021.Si7021(i2c)

timestamp_unix = None  #  TODO implement without using a global

# all measurements are stored and retreived to/from 
# a centralized repo
repo = MeasurementRepo()

# slot=2 configures SD Card to use the SPI3 controller (VSPI), DMA channel = 2
# slot=3 configures SD Card to use the SPI2 controller (HSPI), DMA channel = 1
sd = SDCard(slot=3, sck=Pin(18), mosi=Pin(23), miso=Pin(19), cs=Pin(4))

# loop until mount() stops raising exception "OSError: 16"
# which is related to this error "sdmmc_common: sdmmc_init_csd: send_csd returned 0x109"
while True:
    try:
Exemplo n.º 9
0
import network
from umqtt.simple import MQTTClient
import machine
import ubinascii
import ujson
import utime
import tsl2561
import si7021
from machine import I2C, Pin

# Set sensor Settings
i2c_lux = I2C(scl=Pin(5), sda=Pin(4))
sensor_lux = tsl2561.TSL2561(i2c_lux)
sensor_lux.gain(16)
sensor_lux.integration_time(402)
sensor_temp = si7021.Si7021(64)

# Connect to broker
ap_if = network.WLAN(network.AP_IF)
ap_if.active(False)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('EEERover', 'exhibition')
client = MQTTClient(machine.unique_id(), '192.168.0.10')
client.connect()

# Publish reading
payload = ujson.dumps({
    'device_id': str(machine.unique_id()),
    'broad_lux': sensor_lux._read()[0],
    'ir_lux': sensor_lux._read()[1],
Exemplo n.º 10
0
# sensor ESP8206-01 script
import json
import urequests
import random
import time
from machine import I2C, Pin
from i2c_lcd8050 import I2cLcd
import si7021
import machine

DEFAULT_I2C_ADDR = 0x27

i2C_c = machine.I2C(-1, machine.Pin(2), machine.Pin(0))
i2C_l = I2C(scl=Pin(2), sda=Pin(0))
temp_sensor = si7021.Si7021(i2C_c)
lcd = I2cLcd(i2C_l, DEFAULT_I2C_ADDR, 2, 16)


def http_post(probe_id, temp, humidity):
    url = 'http://floriaaan.alwaysdata.net/atmos/measure/add/'
    datas = {'probe_id': probe_id, 'temp': temp, 'humidity': humidity}
    headers = {'charset': 'utf-8', 'Access-Control-Allow-Headers': '*'}
    resp = urequests.post(url, data=json.dumps(datas), headers=headers)
    lcd.clear()
    lcd.putstr("Requête envoyée")
    time.sleep(2)


def moyenneTemp():
    temp = 0
    for i in range(0, 5):
Exemplo n.º 11
0
from machine import Pin, I2C
import si7021

## this project neopixelpad

__i2c = I2C(scl=Pin(22), sda=Pin(21), freq=100000)
__temp_sensor = si7021.Si7021(__i2c)


def temperature():
    return __temp_sensor.temperature


def humidity():
    return __temp_sensor.relative_humidity