-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_battery_reading.py
executable file
·38 lines (33 loc) · 1.06 KB
/
get_battery_reading.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
#!/usr/bin/env python3
# GPIO 25 - Encoder A for Motor1
# GPIO 22 - Encoder B for Motor1
# GPIO 24 - Encoder A for Motor2
# GPIO 23 - Encoder B for Motor2
import Libraries.Thunderborg as ThunderBorg
import sys
import time
TB = ThunderBorg.ThunderBorg() # Create a new ThunderBorg object
TB.Init() # Set the board up (checks the board is connected)
if not TB.foundChip:
boards = ThunderBorg.ScanForThunderBorg()
if len(boards) == 0:
print("No ThunderBorg found, check you are attached :)")
else:
print(
f"No ThunderBorg at address {TB.i2cAddress}, \
but we did find boards:"
)
for board in boards:
print(" %02X (%d)" % (board, board))
print(
"If you need to change the I²C address change the setup line so \
it is correct, e.g."
)
print("TB.i2cAddress = 0x%02X" % (boards[0]))
sys.exit()
TB.SetBatteryMonitoringLimits(11, 13)
try:
while True:
print(TB.GetBatteryReading(), end="\r")
except KeyboardInterrupt:
TB.MotorsOff()