Exemple #1
0
	def test_set_heater_off(self, mock):
		i2c_mock = self.__get_mock_pi([0x04])
		mock.return_value=i2c_mock

		RHTEMP = Si7021()
		RHTEMP.heater = False
		i2c_mock.i2c_write_device.assert_called_with(ANY,[0xE6, 0x00])
Exemple #2
0
def rover_initialize():

    global RMotor, LMotor, MotorWake, AtmoSensor

    AtmoSensor = Si7021(SMBus(1))

    MotorWake = LED(17)
    MotorWake.off()

    #Args are GPIO Pins for forward, backward, and motor controller sleep
    LMotor = Motor(20, 21)  # Motor(19, 26, 13)
    RMotor = Motor(19, 26)  # Motor(20, 21, 13)

    print("""



    #############
    x for exit
    wasd keys for directional controls. Capital letters for custom turns.
    c for 180
    b for Box Pattern

    r for Atmospheric Report
    #############

    """)

    return True
Exemple #3
0
    def start(self):
        self.logger.info("Starting")
        self.smbus = SMBus(self.busNumber)
        self.si7021 = Si7021(self.smbus)
        self.si7021.reset()

        self.bme208 = Bme280(self.smbus)
        self.bme208.setup()

        self.timer.start(True)
        self.logger.info("Started")
from si7021 import Si7021
from time import sleep
from smbus import SMBus

sensor = Si7021(SMBus(1))
i = 0

# Why the f**k does it have a heater?


def get_temp():
    """Returns long string of temp in C. Use %.2f *F" % (a[1]*1.8 + 32) to adjust."""
    return sensor.read()[1]


def get_humid():
    """Returns long string of humidity in %. Use %.1f %%RH to format."""
    return sensor.read()[0]


# while i <= 60:
#     print("%.1f %%RH, %.1f °C" % sensor.read())
#     # sensor.heater_mA = 50
#     a = sensor.read()
#     # print(type(a))
#     # print(str(a))
#     # print("%.1f %%RH" % a[0])
#     print("%.2f *F" % (a[1]*1.8 + 32))
#     sleep(5)
#
#     # print("%.1f %%RH, %.1f °C" % sensor.read())
Exemple #5
0
def run():
    from si7021 import Si7021
    sensor = Si7021()
    print(sensor.readTemp(), sensor.readRH())
Exemple #6
0
 def __init__(self):
     confs = utils.getConfiguration(self.name)
     print("Hygrometer initialized - configuration found")
     sensor = Si7021(SMBus(1))
Exemple #7
0
def init_sensors(kind):
    global bme680, si7021, sht31, pmsx003, anemo, vane, rain
    global cwop, display

    # ===== pin configuration, see also Projects/kicad/esp32-weather/README.md
    if kind == "lolin-d32":
        scl0, sda0 = 23, 22  # bme680, si7021, sht31
        scl1, sda1 = 18, 4  # oled
        scl2, sda2 = 13, 12  # expansion
        pm_tx, pm_rx = 25, 26  # pmsa003
        anemo_pin = 39  # anemometer pulse
        vane_pin = 36  # wind vane analog
        rain_pin = 34  # rain pulse
        pow_3v3 = 32  # active-low power for anemo/vane/rain/pmsa003
    else:
        raise ("Unknown board kind: " + kind)

    # ===== init devices

    # show splash screen on display
    from ssd1306 import SSD1306_I2C

    try:
        scl1_pin = machine.Pin(scl1)
        sda1_pin = machine.Pin(sda1, pull=machine.Pin.PULL_UP)  # pup: helps presence detection
        display = SSD1306_I2C(128, 64, machine.I2C(scl=scl1_pin, sda=sda1_pin, freq=1000000))
        display.fill(1)
        display.fill_rect(10, 10, 108, 44, 0)
        display.text("WCC Weather", 20, 20, 1)
        display.show()
        log.info("Found display")
    except Exception as e:
        display = None
        log.warning("No display: %s", e)

    # start power for anemo, vane, etc.
    pow_3v3_pin = machine.Pin(pow_3v3, machine.Pin.OUT)
    pow_3v3_pin(0)

    # I2C bus for primary sensors
    scl0_pin = machine.Pin(scl0)
    sda0_pin = machine.Pin(sda0)
    i2c0_dev = machine.I2C(scl=scl0_pin, sda=sda0_pin, freq=100000)

    # BME680 temperature/humidity/pressure/voc
    from bme680 import BME680

    try:
        bme680 = BME680(i2c0_dev)
        bme680.set_gas_heater_temperature(320)
        bme680.set_gas_heater_duration(100)
        log.info("Found BME680")
    except Exception as e:
        bme680 = None
        log.warning("No BME680 found: %s", e)

    # SI7021 temperature/humidity
    from si7021 import Si7021

    try:
        si7021 = Si7021(i2c0_dev)
        si7021.convert()
        log.info("Found Si7021")
    except Exception as e:
        si7021 = None
        log.warning("No Si7021 found: %s", e)

    # SHT31 temperature/humidity
    from sht31 import SHT31

    try:
        sht31 = SHT31(i2c0_dev)
        sht31.convert()
        log.info("Found SHT31")
    except Exception as e:
        sht31 = None
        log.warning("No SHT31 found: %s", e)

    # PMSx003 PM sensor
    from pms_x003 import PMSx003

    try:
        pmsx003 = PMSx003(tx=pm_tx, rx=pm_rx)
        log.info("Found PMSx003")
    except Exception as e:
        pmsx003 = None
        log.warning("No PMSx003 found: %s", e)

    # Anemometer and wind vane
    from wind import Anemo, Vane
    from counter import Counter

    try:
        # configure pin with pull-up
        machine.Pin(anemo_pin, mode=machine.Pin.IN)
        anemo_ctr = Counter(0, anemo_pin)
        anemo_ctr.filter(10)  # 10us filter
        anemo = Anemo(anemo_ctr, 2.5)  # 2.5 mph per Hz
        anemo.start()
    except Exception as e:
        anemo = None
        log.exc(e, "Anemometer failed to init")
    try:
        vane = Vane(vane_pin, 140, 1600, 15)
        vane.start()
    except Exception as e:
        vane = None
        log.exc(e, "Wind vane failed to init")

    # init rain gauge
    pass

    # init CWOP
    try:
        from cwop import send_wx

        cwop = send_wx
    except ImportError:
        log.warning("Cannot import CWOP, skipping")
Exemple #8
0
    A = 17.27
    B = 237.7
    alpha = ((A * t_air_c) / (B + t_air_c)) + math.log(rel_humidity / 100.0)
    return (B * alpha) / (A - alpha)


led3 = pyb.LED(3)
led4 = pyb.LED(4)

# flashing LEDs together at 10 Hz to confirm program start
for j in range(20):
    pyb.delay(100)
    led4.toggle()
    led3.toggle()

sensor = Si7021()
i = 1
led4.on()
led3.off()

# flashing LEDs alternating at 5 Hz to confirm that sensor object was creadted successfully
for j in range(10):
    pyb.delay(200)
    led4.toggle()
    led3.toggle()

previous_temp = 1000

while True:
    humidity, temp = sensor.readRH(), sensor.readTemp()
    # humidity, temp = sensor.relative_humidity, sensor.temperature
Exemple #9
0
	def test_get_heater_off(self, mock):
		mock.return_value=self.__get_mock_pi([0xFB])

		RHTEMP = Si7021()
		self.assertFalse(RHTEMP.heater)
Exemple #10
0
	def test_get_heater_on(self, mock):
		mock.return_value=self.__get_mock_pi([0x04])

		RHTEMP = Si7021()
		self.assertTrue(RHTEMP.heater)
Exemple #11
0
	def test_relative_humidity_0xFF(self, mock):
		mock.return_value=self.__get_mock_pi([0xFF,0xFF])

		RHTEMP = Si7021()
		temp = RHTEMP.relative_humidity
		self.assertEqual(int(temp), 118)
Exemple #12
0
	def test_relative_humidity_0x00(self, mock):
		mock.return_value=self.__get_mock_pi([0,0])

		RHTEMP = Si7021()
		temp = RHTEMP.relative_humidity
		self.assertEqual(temp, -6)
Exemple #13
0
	def test_temperature_0xFF(self, mock):
		mock.return_value=self.__get_mock_pi([0xFF,0xFF])

		RHTEMP = Si7021()
		temp = RHTEMP.temperature
		self.assertEqual(int(temp), 128)
Exemple #14
0
	def test_temperature_0x00(self, mock):
		mock.return_value=self.__get_mock_pi([0,0])

		RHTEMP = Si7021()
		temp = RHTEMP.temperature
		self.assertEqual(temp, -46.85)
Exemple #15
0
time.sleep(1.5)

# Connect to WiFi and show IP address
ip_addr = do_connect()
ip_node = ip_addr.split('.')[3]
led.set_text('    ')
led.set_text(' {:>4}'.format('.' + ip_node))
time.sleep(2)

# Set system time from time server pool.ntp.org
# Do this once a day to reduce time server loading.
# Call machine.RTC().datetime() rest of the time.
#settime()

# Temp and RH sensor
sns = Si7021(scl=cfg_gpio['sns_scl'], sda=cfg_gpio['sns_sda'])


def show_time(hr, mn):
    # Adjust for time zone offset
    hr += cfg_time['tz_offset']
    if hr < 0:
        hr += 24
    hr = hr % 24

    # Convert 24 hour to 12 hour time
    if hr == 0:
        hr = 12
    elif hr > 12:
        hr -= 12
Exemple #16
0
        .format(sett['rh_res'], sett['temp_res'], sett['res']))
    print("   Vdd status: 0x{0:02X} ({1})".format(sett["vdds"],
                                                  sett["vdds_str"]))
    print("   Heater status: 0x{0:02X} ({1})".format(sett['htre'],
                                                     sett['htre_str']))
    print("   Heater current: 0x{0:02X} ({1:4.2f}mA)".format(
        sett["heater"], sett["heater_curr"] * 0.01))
    print("   User register RAW value: 0x{0:02X} ({0:#010b})".format(
        sett["user"]))
    return


# -----------------------------------------------------

print("Init si7021 class...")
si = Si7021(1, Si7021.SI7021_DEF_ADDR)

print("Issuing reset to Si7021...")
si.Reset()

print("Reading S/N & F/W...", end=' ')
sn = si.ReadSN()
if (sn['ok'] == 0):
    print(" Success.")
    print("   Device name: 0x{0:02X} ({1})".format(sn['device'],
                                                   sn['device_str']))
    print("   Firmware version: 0x{0:02X} (v{1})".format(
        sn['fw'], sn['fw_str']))
    print("   Serial number: {0}".format(byte_array_to_string(sn['sn'])))
else:
    print("Errors occured.")
 def __init__(self):
     self.sensor = Si7021(SMBus(1))