Skip to content

Commit f49f34f

Browse files
authored
Merge pull request #2753 from adafruit/picowbell_doubler
Picowbell doubler battery monitor code
2 parents 45500df + 52b8af1 commit f49f34f

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

PiCowbell_Doubler/Arduino_PiCowbell_Doubler_Battery_Monitor/.pico_rp2040.test.only

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-FileCopyrightText: 2024 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#define LED LED_BUILTIN
6+
7+
void setup() {
8+
Serial.begin(115200);
9+
// while (!Serial) delay(1); // wait for serial port
10+
pinMode(LED, OUTPUT);
11+
delay (100);
12+
Serial.println("PiCowbell Doubler Battery Monitor");
13+
14+
}
15+
16+
void loop() {
17+
digitalWrite(LED, HIGH);
18+
// get the on-board voltage
19+
float vsys = analogRead(A3) * 3 * 3.3 / 1023.0;
20+
Serial.printf("Vsys: %0.1f V", vsys);
21+
Serial.println();
22+
23+
digitalWrite(LED, LOW);
24+
delay(5000);
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: 2024 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
from analogio import AnalogIn
8+
from digitalio import DigitalInOut, Direction
9+
10+
led = DigitalInOut(board.LED)
11+
led.direction = Direction.OUTPUT
12+
13+
analog_in = AnalogIn(board.A3)
14+
15+
def get_vsys(pin):
16+
return ((pin.value * 3) * 3.3) / 65536
17+
18+
while True:
19+
led.value = True
20+
print(f"The battery level is: {get_vsys(analog_in):.1f}V")
21+
led.value = False
22+
time.sleep(5)

0 commit comments

Comments
 (0)