1 from unittest import TestCase
 
   2 from testing import yes_no
 
   4 class TestMMA8451Interactive(TestCase):
 
   6     def test_read_value(self):
 
  10         if not(yes_no("Is MMA8451 wired to SCL {} SDA {} and held still".format(board.SCL, board.SDA))):
 
  11             return # test trivially passed
 
  13         # from https://github.com/adafruit/Adafruit_CircuitPython_MMA8451/blob/29e31a0bb836367bc73763b83513105252b7b264/examples/simpletest.py
 
  14         import adafruit_mma8451
 
  16         i2c = busio.I2C(board.SCL, board.SDA)
 
  17         sensor = adafruit_mma8451.MMA8451(i2c)
 
  19         x, y, z = sensor.acceleration
 
  20         absolute = math.sqrt(x**2, y**2, z**2)
 
  21         self.assertTrue(9 <=absolute <= 11, "Not earth gravity")
 
  23         orientation = sensor.orientation
 
  24         self.assertTrue(orientation in (
 
  25             adafruit_mma8451.PL_PUF,
 
  26             adafruit_mma8451.PL_PUB,
 
  27             adafruit_mma8451.PL_PDF,
 
  28             adafruit_mma8451.PL_PDB,
 
  29             adafruit_mma8451.PL_LRF,
 
  30             adafruit_mma8451.PL_LRB,
 
  31             adafruit_mma8451.PL_LLF,
 
  32             adafruit_mma8451.PL_LLB,
 
  35 class TestBNO055Interactive(TestCase):
 
  37     def test_read_value(self):
 
  39         Access all sensor values as per
 
  40         https://github.com/adafruit/Adafruit_CircuitPython_BNO055/blob/bdf6ada21e7552c242bc470d4d2619b480b4c574/examples/values.py
 
  44         import adafruit_bno055
 
  46         i2c = busio.I2C(board.SCL, board.SDA)
 
  47         sensor = adafruit_bno055.BNO055(i2c)
 
  55         sensor.linear_acceleration
 
  59 class TestGPSInteractive(TestCase):
 
  61     def test_read_value(self):
 
  62         import microcontroller
 
  66         # configure the last available UART (first uart often for REPL)
 
  67         uartId, txId, rxId = microcontroller.uartPorts[-1]
 
  68         txPin = microcontroller.Pin(txId)
 
  69         rxPin = microcontroller.Pin(rxId)
 
  70         uart = busio.UART(txPin, rxPin, baudrate=9600, timeout=3000)
 
  72         gps = adafruit_gps.GPS(uart)
 
  74         gps.send_command('PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
 
  75         gps.send_command('PMTK220,1000')
 
  77         self.awaitTrue("GPS fix", lambda: gps.has_fix)
 
  78         self.assertTrue(gps.satellites is not None)
 
  79         self.assertTrue(-90 <= gps.latitude < 90)
 
  80         self.assertTrue(-180 <= gps.longitude < 180)