Skip to content

Commit fa80b7c

Browse files
Add showbattery app for testing
1 parent 142c232 commit fa80b7c

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "ShowBattery",
3+
"publisher": "MicroPythonOS",
4+
"short_description": "Minimal app",
5+
"long_description": "Demonstrates the simplest app.",
6+
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.helloworld/icons/com.micropythonos.helloworld_0.0.2_64x64.png",
7+
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.helloworld/mpks/com.micropythonos.helloworld_0.0.2.mpk",
8+
"fullname": "com.micropythonos.showbattery",
9+
"version": "0.0.2",
10+
"category": "development",
11+
"activities": [
12+
{
13+
"entrypoint": "assets/hello.py",
14+
"classname": "Hello",
15+
"intent_filters": [
16+
{
17+
"action": "main",
18+
"category": "launcher"
19+
}
20+
]
21+
}
22+
]
23+
}
24+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""
2+
8:44 4.15V
3+
8:46 4.13V
4+
5+
import time
6+
v = mpos.battery_voltage.read_battery_voltage()
7+
percent = mpos.battery_voltage.get_battery_percentage()
8+
text = f"{time.localtime()}: {v}V is {percent}%"
9+
text
10+
11+
from machine import ADC, Pin # do this inside the try because it will fail on desktop
12+
adc = ADC(Pin(13))
13+
# Set ADC to 11dB attenuation for 0–3.3V range (common for ESP32)
14+
adc.atten(ADC.ATTN_11DB)
15+
adc.read()
16+
17+
scale factor 0.002 is (4.15 / 4095) * 2
18+
BUT shows 4.90 instead of 4.13
19+
BUT shows 5.018 instead of 4.65 (raw ADC read: 2366)
20+
SO substract 0.77
21+
# at 2366
22+
23+
2506 is 4.71 (not 4.03)
24+
scale factor 0.002 is (4.15 / 4095) * 2
25+
BUT shows 4.90 instead of 4.13
26+
BUT shows 5.018 instead of 4.65 (raw ADC read: 2366)
27+
SO substract 0.77
28+
# at 2366
29+
30+
USB power:
31+
2506 is 4.71 (not 4.03)
32+
2498
33+
2491
34+
35+
battery power:
36+
2482 is 4.180
37+
2470 is 4.170
38+
2457 is 4.147
39+
2433 is 4.109
40+
2429 is 4.102
41+
2393 is 4.044
42+
2369 is 4.000
43+
2343 is 3.957
44+
2319 is 3.916
45+
2269 is 3.831
46+
47+
"""
48+
49+
import lvgl as lv
50+
import time
51+
52+
import mpos.battery_voltage
53+
from mpos.apps import Activity
54+
55+
class Hello(Activity):
56+
57+
refresh_timer = None
58+
59+
# Widgets:
60+
raw_label = None
61+
62+
def onCreate(self):
63+
s = lv.obj()
64+
self.raw_label = lv.label(s)
65+
self.raw_label.set_text("starting...")
66+
self.raw_label.center()
67+
self.setContentView(s)
68+
69+
def onResume(self, screen):
70+
super().onResume(screen)
71+
72+
def update_bat(timer):
73+
#global l
74+
r = mpos.battery_voltage.read_raw_adc()
75+
v = mpos.battery_voltage.read_battery_voltage()
76+
percent = mpos.battery_voltage.get_battery_percentage()
77+
text = f"{time.localtime()}\n{r}\n{v}V\n{percent}%"
78+
#text = f"{time.localtime()}: {r}"
79+
print(text)
80+
self.update_ui_threadsafe_if_foreground(self.raw_label.set_text, text)
81+
82+
self.refresh_timer = lv.timer_create(update_bat,1000,None) #.set_repeat_count(10)
83+
84+
def onPause(self, screen):
85+
super().onPause(screen)
86+
if self.refresh_timer:
87+
self.refresh_timer.delete()

0 commit comments

Comments
 (0)