<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Newbie failing on the first clock + battery with PaperS3]]></title><description><![CDATA[<p dir="auto">I bought PaperS3 to build a dashboard displaying current time, weather forecast and bus departures. So far, I am unable to build a skeleton even after three weeks. My intention is to display the current time and a battery level and take a sleep for one minute. When running on a battery, I use deep sleep, because I target charging once per month. If connected to USB, I use a standard sleep to keep the USB connection (deep sleep kills it). Can you review my latest code please?</p>
<pre><code>import M5
from M5 import *
import time, machine

SLEEP_MS = 60_000
WIDTH = 540

def get_battery():
    try:
        return Power.getBatteryLevel()
    except:
        return None

def is_charging():
    try:
        return Power.isCharging()
    except:
        return False

def draw_screen():
    Widgets.setRotation(2)
    Widgets.fillScreen(0xFFFFFF)

    t = time.localtime()
    day = t[2]
    month = t[1]
    year = t[0]
    h = t[3]
    m = t[4]

    batt = get_battery()
    batt_str = f"{batt}%" if batt is not None else "--%"

    date_str = f"{day}.{month}.{year}"
    time_str = f"{h:02d}:{m:02d}"
    battery_str = f"Battery: {batt_str}"

    FONT = Widgets.FONTS.DejaVu56

    y_start = 250
    spacing = 120

    Widgets.Label(date_str, WIDTH//2 - 100, y_start, 1.0,
                  0x000000, 0xFFFFFF, FONT)

    Widgets.Label(time_str, WIDTH//2 - 75, y_start + spacing, 1.0,
                  0x000000, 0xFFFFFF, FONT)

    Widgets.Label(battery_str, WIDTH//2 - 175, y_start + spacing * 2, 1.0,
                  0x000000, 0xFFFFFF, FONT)

    M5.update()

def main():
    M5.begin()

    if is_charging():
        while True:
            draw_screen()
            time.sleep(2)
            try:
                machine.lightsleep(SLEEP_MS)
            except:
                time.sleep_ms(SLEEP_MS)
    else:
        draw_screen()
        time.sleep(2)
        try:
            machine.deepsleep(SLEEP_MS)
        except:
            time.sleep_ms(SLEEP_MS)

if __name__ == "__main__":
    main()
</code></pre>
<p dir="auto">So far I used AI tools to build the code. Thank you</p>
]]></description><link>https://community.m5stack.com/topic/7852/newbie-failing-on-the-first-clock-battery-with-papers3</link><generator>RSS for Node</generator><lastBuildDate>Mon, 18 May 2026 14:02:54 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7852.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Oct 2025 05:34:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Newbie failing on the first clock + battery with PaperS3 on Thu, 09 Oct 2025 06:47:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/literakl" aria-label="Profile: literakl">@<bdi>literakl</bdi></a> so are you able to display current time and battery level at all...forget about sleep option for now</p>
]]></description><link>https://community.m5stack.com/post/30053</link><guid isPermaLink="true">https://community.m5stack.com/post/30053</guid><dc:creator><![CDATA[robski]]></dc:creator><pubDate>Thu, 09 Oct 2025 06:47:59 GMT</pubDate></item></channel></rss>