🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Newbie failing on the first clock + battery with PaperS3

    Scheduled Pinned Locked Moved UiFlow 2.0
    2 Posts 2 Posters 649 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      literakl
      last edited by

      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?

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

      So far I used AI tools to build the code. Thank you

      robskiR 1 Reply Last reply Reply Quote 0
      • robskiR Offline
        robski @literakl
        last edited by

        @literakl so are you able to display current time and battery level at all...forget about sleep option for now

        M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ, M5Tab, M5CardputerAdv, M5StackChan

        1 Reply Last reply Reply Quote 1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post