|
| 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