Esempio n. 1
0
    def update(self):
        """Get the latest data from Enviro pHAT."""
        from envirophat import analog, leds, light, motion, weather

        # Light sensor reading: 16-bit integer
        self.light = light.light()
        if self.use_leds:
            # pylint: disable=no-value-for-parameter
            leds.on()
        # the three color values scaled agains the overall light, 0-255
        self.light_red, self.light_green, self.light_blue = light.rgb()
        if self.use_leds:
            # pylint: disable=no-value-for-parameter
            leds.off()

        # accelerometer readings in G
        self.accelerometer_x, self.accelerometer_y, self.accelerometer_z = \
            motion.accelerometer()

        # raw magnetometer reading
        self.magnetometer_x, self.magnetometer_y, self.magnetometer_z = \
            motion.magnetometer()

        # temperature resolution of BMP280 sensor: 0.01°C
        self.temperature = round(weather.temperature(), 2)

        # pressure resolution of BMP280 sensor: 0.16 Pa, rounding to 0.1 Pa
        # with conversion to 100 Pa = 1 hPa
        self.pressure = round(weather.pressure() / 100.0, 3)

        # Voltage sensor, reading between 0-3.3V
        self.voltage_0, self.voltage_1, self.voltage_2, self.voltage_3 = \
            analog.read_all()
Esempio n. 2
0
def get_temps():
    """Get measured temperatures from envirophat and raspberry pi CPU sensor.
    Calculate offset measured temp. Format for further use.
    """
    global cpu_temp
    global temp
    global tempmed
    global temp_calibrated

    cpu_temp = vcgencmd.measure_temp()

    temp = weather.temperature()
    temp_calibrated = temp - ((cpu_temp - temp)/factor)
    tempmed = '{:.1f}'.format(round(temp_calibrated, 2))
def get_url_params():
  t = weather.temperature()
  p = weather.pressure(unit='hPa')
  h = None
  l = light.light()
  # Python's datetmie doesn't have timezone info.
  # You may need to set system timezone as JST. (hint: sudo raspi-config)
  # FIXME: the code will post wrong datetime. should be keep in UTC??(is the hint wrong?)
  ts = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S%z")
  s = "dt=%s" % (ts)
  s += "&temperature=%f" % (t)
  s += "&pressure=%f" % (p)
  # s += "&humidity=%f" % (h)
  s += "&illuminance=%f" % (l)
  # s += "&voltage=#{v}"
  return s
Esempio n. 4
0
write("--- Enviro pHAT Monitoring ---")

try:
    while True:
        rgb = light.rgb()
        analog_values = analog.read_all()

        output = """
Temp: {t}c
Pressure: {p}Pa
Light: {c}
RGB: {r}, {g}, {b} 
Heading: {h}
Analog: 0: {a0}, 1: {a1}, 2: {a2}, 3: {a3}
""".format(
        t = round(weather.temperature(),2),
        p = round(weather.pressure(),2),
        c = light.light(),
        r = rgb[0],
        g = rgb[1],
        b = rgb[2],
        h = motion.heading(),
        a0 = analog_values[0],
        a1 = analog_values[1],
        a2 = analog_values[2],
        a3 = analog_values[3]
    )
        output = output.replace("\n","\n\033[K")
        write(output)
        lines = len(output.split("\n"))
        write("\033[{}A".format(lines - 1))
Esempio n. 5
0
import time

from envirophat import weather, leds


print("""This example will detect motion using the accelerometer.

Press Ctrl+C to exit.

""")

threshold = None

try:
    while True:
        temperature = weather.temperature()

        if threshold is None:
            threshold = temperature + 2

        print("{} degrees celcius".format(temperature))
        if temperature > threshold:
            leds.on()
        else:
            leds.off()

        time.sleep(0.1)

except KeyboardInterrupt:
    pass
Esempio n. 6
0
#!/usr/bin/env python

from envirophat import light, motion, weather, analog, leds
import time

while True:
    print("LEDs on...")
    leds.on()
    time.sleep(1)
    print("LEDs off...")
    leds.off()
    print("Light...")
    print(light.rgb())
    print("Motion...")
    print(motion.heading())
    print(motion.magnetometer())
    print(motion.accelerometer())
    print("Weather...")
    print(weather.temperature())
    print(weather.pressure())
    print("Analog...")
    print(analog.values())
    time.sleep(1)