Exemplo n.º 1
0
def test_setup():
    sys.modules['smbus'] = mock.Mock()
    sys.modules['smbus'].SMBus = MockSMBus

    import veml6075

    uv_sensor = veml6075.VEML6075()
    uv_sensor.set_shutdown(False)
    uv_sensor.set_high_dynamic_range(False)
    uv_sensor.set_integration_time('800ms')
    uva, uvb = uv_sensor.get_measurements()
    uv_comp1, uv_comp2 = uv_sensor.get_comparitor_readings()
    del uv_sensor
Exemplo n.º 2
0
    def _get_data(self):
        data = None
        with self._open_hardware() as i2c_bus:
            sensor = veml6075.VEML6075(i2c_addr=self.device[0],
                                       i2c_dev=i2c_bus)
            sensor.set_shutdown(False)
            sensor.set_high_dynamic_range(False)
            sensor.set_integration_time('100ms')

            uva, uvb = sensor.get_measurements()
            uv_comp1, uv_comp2 = sensor.get_comparitor_readings()
            uv_indices = sensor.convert_to_index(uva, uvb, uv_comp1, uv_comp2)

            data = {}
            data['uva'] = uva
            data['uvb'] = uvb
            data['uvi'] = max(0, uv_indices[2])  # Do not allow lower then zero

        return data
Exemplo n.º 3
0
from machine import I2C, Pin
import ssd1306
import veml6075
import time

time.sleep_ms(500)
i2c = I2C(scl=Pin(5), sda=Pin(4))
uv = veml6075.VEML6075(i2c)  # instantiate VEML6075 class
connected = uv.initUV()
oled = ssd1306.SSD1306_I2C(128, 64, i2c, 0x3c)
oled.fill(0)

while True:
    if connected == True:
        UVI, UVIA, UVIB = uv.readUV()
    oled.fill(0)
    oled.text("UV information", 0, 0)
    if connected == True:
        oled.text("UVIA        {0:.1f}".format(UVIA), 0, 20)
        oled.text("UVIB        {0:.1f}".format(UVIB), 0, 30)
        oled.text("UVI avg     {0:.1f}".format(UVI), 0, 40)
    else:
        oled.text("UV sensor NC", 0, 20)
    oled.show()
    time.sleep_ms(3000)
Exemplo n.º 4
0
    elif 3 <= avg_uv_index < 6:
        return "MEDIUM"
    elif 6 <= avg_uv_index < 8:
        return "HIGH"
    elif 8 <= avg_uv_index < 11:
        return "V. HIGH"
    elif avg_uv_index > 11:
        return "EXTREME"
    else:
        return ""


bus = smbus.SMBus(1)

# Set up UV sensor
uv_sensor = veml6075.VEML6075(i2c_dev=bus)
uv_sensor.set_shutdown(False)
uv_sensor.set_high_dynamic_range(False)
uv_sensor.set_integration_time('100ms')

# Set up RGB matrix
rgbmatrix5x5 = RGBMatrix5x5()
rgbmatrix5x5.set_clear_on_exit()
rgbmatrix5x5.set_brightness(1.0)

# Set up OLED
oled = sh1106(spi(port=0, device=1, gpio_DC=9),
              rotate=2,
              height=128,
              width=128)
Exemplo n.º 5
0
#  Last Update: 22/09/2019

import veml6075
from machine import I2C, Pin
i2c = I2C(sda=Pin(5), scl=Pin(4))
sensor = veml6075.VEML6075(i2c=i2c)
sensor.uv_index
"""
MPY: soft reboot
MicroPython v1.11-8-g48dcbbe60 on 2019-05-29; ESP module with ESP8266
Type "help()" for more information.
>>> import gc
>>> gc.collect()
>>> gc.mem_free()
33024
>>> import veml6075
>>> gc.collect()
>>> gc.mem_free()
30512
>>> from machine import I2C, Pin
>>> i2c = I2C(sda=Pin(5), scl=Pin(4))
>>> sensor = veml6075.VEML6075(i2c=i2c)
>>> gc.collect()
>>> gc.mem_free()
30208
>>> 

32.25 Kb -> 100 %
 2.75 Kb ->   x %
 
32.75 * x = 100 * 2.75