-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiplex2.py
47 lines (36 loc) · 1.1 KB
/
multiplex2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
import board
import busio
import smbus2
import adafruit_bno055
import adafruit_mpl3115a2
import altimeter
RPI_BUS_NUM = 1
MULTIPLEXER_ADDR = 0x70
I2C_CH = [1 << i for i in range(8)]
bus = smbus2.SMBus(RPI_BUS_NUM)
i2c = busio.I2C(board.SCL, board.SDA)
sensors = {}
def setup():
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[2])
sensors['imu'] = adafruit_bno055.BNO055_I2C(i2c)
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[1])
sensors['alti1'] = altimeter.Altimeter(i2c)
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[6])
sensors['alti2'] = altimeter.Altimeter(i2c)
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[5])
sensors['alti3'] = altimeter.Altimeter(i2c)
def loop():
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[2])
print(sensors['imu'].acceleration)
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[1])
print(sensors['alti1'].pressure)
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[6])
print(sensors['alti2'].pressure)
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[5])
print(sensors['alti3'].pressure)
setup()
while True:
t0 =time.time()
loop()
print(time.time()-t0)