]> Repositories - Adafruit_Blinka-hackapet.git/blob - python/testing/implementation/all/busio.py
099499ee6283c084d4b5cd277ac69cbfbfa44ac5
[Adafruit_Blinka-hackapet.git] / python / testing / implementation / all / busio.py
1 from unittest import TestCase
2 from testing import yes_no
3
4 class TestMMA8451Interactive(TestCase):
5
6     def test_read_value(self):
7         import math
8         import board
9         gc.collect()
10         if not(yes_no("Is MMA8451 wired to SCL {} SDA {} and held still".format(board.SCL, board.SDA))):
11             return # test trivially passed
12         import busio
13         # from https://github.com/adafruit/Adafruit_CircuitPython_MMA8451/blob/29e31a0bb836367bc73763b83513105252b7b264/examples/simpletest.py
14         import adafruit_mma8451
15         # Initialize I2C bus.
16         i2c = busio.I2C(board.SCL, board.SDA)
17         sensor = adafruit_mma8451.MMA8451(i2c)
18
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")
22
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,
33         ))
34
35 class TestBNO055Interactive(TestCase):
36
37     def test_read_value(self):
38         """
39         Access all sensor values as per
40         https://github.com/adafruit/Adafruit_CircuitPython_BNO055/blob/bdf6ada21e7552c242bc470d4d2619b480b4c574/examples/values.py
41         """
42         import board
43         import busio
44         import adafruit_bno055
45
46         i2c = busio.I2C(board.SCL, board.SDA)
47         sensor = adafruit_bno055.BNO055(i2c)
48
49         sensor.temperature
50         sensor.accelerometer
51         sensor.magnetometer
52         sensor.gyroscope
53         sensor.euler
54         sensor.quaternion
55         sensor.linear_acceleration
56         sensor.gravity
57
58
59 class TestGPSInteractive(TestCase):
60
61     def test_read_value(self):
62         import microcontroller
63         import busio
64         import adafruit_gps
65
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)
71
72         gps = adafruit_gps.GPS(uart)
73
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')
76         gps.update()
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)