Пример #1
0
    def test_read_value(self):
        import math

        gc.collect()
        import board

        gc.collect()

        if not (yes_no(
                "Is MMA8451 wired to SCL {} SDA {} and held still".format(
                    board.SCL, board.SDA))):
            return  # test trivially passed
        # from https://github.com/adafruit/Adafruit_CircuitPython_MMA8451/blob/29e31a0bb836367bc73763b83513105252b7b264/examples/simpletest.py
        import adafruit_mma8451

        i2c = I2C(board.SCL, board.SDA)
        sensor = adafruit_mma8451.MMA8451(i2c)

        x, y, z = sensor.acceleration
        absolute = math.sqrt(x**2 + y**2 + z**2)
        self.assertTrue(9 <= absolute <= 11, "Not earth gravity")

        orientation = sensor.orientation
        self.assertTrue(orientation in (
            adafruit_mma8451.PL_PUF,
            adafruit_mma8451.PL_PUB,
            adafruit_mma8451.PL_PDF,
            adafruit_mma8451.PL_PDB,
            adafruit_mma8451.PL_LRF,
            adafruit_mma8451.PL_LRB,
            adafruit_mma8451.PL_LLF,
            adafruit_mma8451.PL_LLB,
        ))
Пример #2
0
    def test_read_value(self):

        import board

        gc.collect()
        import adafruit_bme280

        gc.collect()

        if not (yes_no("Is BME280 wired to SCL {} SDA {}".format(
                board.SCL, board.SDA))):
            return  # test trivially passed

        i2c = I2C(board.SCL, board.SDA)
        bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
        temperature = bme280.temperature
        humidity = bme280.humidity
        pressure = bme280.pressure
        altitude = bme280.altitude
        self.assertTrue(type(temperature) is float)
        self.assertTrue(type(humidity) is float)
        self.assertTrue(type(pressure) is float)
        self.assertTrue(type(altitude) is float)

        self.assertTrue(-50 <= temperature <= 50)
        self.assertTrue(0 <= humidity <= 100)
        self.assertTrue(900 <= pressure <= 1100)
        self.assertTrue(-1000 <= altitude <= 9, 848)
Пример #3
0
 def test_blink(self):
     """LED blinks when proper attributes set"""
     print()
     from adafruit_blinka.agnostic import sleep
     if not (led_hardwired) and not (yes_no(
             "Is LED wired to {}".format(led_pin))):
         return  # test trivially passed
     with DigitalInOut(led_pin) as led:
         led.direction = Direction.OUTPUT
         # should now be OUT, PUSH_PULL, value=0, and LED should light
         led.value = False if led_inverted else True
         self.assertTrue(yes_no("Is LED lit"))
         print("Winking LED...")
         for count in range(2):
             led.value = not (led.value)
             sleep(0.5)
             led.value = not (led.value)
             sleep(0.5)
         self.assertTrue(yes_no("Did LED wink twice"))
Пример #4
0
 def test_button_pull_down(self):
     print()
     """Pull-down button configured and detected"""
     with DigitalInOut(default_pin) as button:
         #button.direction = Direction.INPUT # implied
         try:
             button.pull = Pull.DOWN
         except NotImplementedError as e:
             print(e)
             return  # pull unsupported, test trivially passed
         except Exception as e:
             print(e)
             return  # pull unsupported, test trivially passed
         if (yes_no("Is Button wired from {} to VCC".format(default_pin))):
             self.assertTrue(button.value == False)
             self.assertTrue(
                 await_true("button pressed", lambda: button.value == True))