Skip to content

Commit ccae8b2

Browse files
committed
CircuitPython battery voltage code
1 parent 306ca74 commit ccae8b2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import board
2+
import analogio
3+
4+
vbat_voltage = analogio.AnalogIn(board.D9)
5+
6+
7+
def get_voltage(pin):
8+
return (pin.value * 3.3) / 65536 * 2
9+
10+
11+
battery_voltage = get_voltage(vbat_voltage)
12+
print("VBat voltage: {:.2f}".format(battery_voltage))

0 commit comments

Comments
 (0)