<?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[M5Paper: how to detect USB power?]]></title><description><![CDATA[<p dir="auto">Hi there. I'm stucking in a problem that drives me a bit crazy since days: How to detect USB power in M5paper?<br />
<strong>The project:</strong> A station table for swiss public transport that shows me the next few trains and busses from the station near my home with destination and departure time including delay information. Swiss public transport ist usually very accurate in time but sometimes a train has +1 ... +5 minutes delay. As the station is very close I tend to leave my home as late as possible. This display will help to determine the required stress level while preparing my backpack and taking my shoes on.<br />
<strong>How it is done:</strong> I get the stationboard data from API <a href="http://transport.opendata.ch" target="_blank" rel="noopener noreferrer nofollow ugc">transport.opendata.ch</a> and pick the required information out of the returned JSON file. A prototyp in UIFlow works but need a lot of time to parse the JSON so now I am coding with the arduino environment which does it much faster (very much faster!). The M5Paper shall do the following: wake up by RTC, connect to my Wifi, get the JSON, parse it, update display and go to sleep for one minute until RTC wakes it up for the next round. Save as much power as possible to keep the battery time as long as possible.<br />
<strong>Now the Problem:</strong> While plugged to USB for charging, the M5Paper does not stay in sleep mode. It wakes up immediately and update every few seconds. This penetrates the transport API much more than required and I want to avoid that. So the idea is a simple <em>if (usbpower) then sleep(60seconds) else shutdown(60seconds)</em> but there is no official way to detect if charging or not in M5Paper (some other M5 devices have that). My first idea of getting battery voltage is not reliable enough as sometimes it returns high and sometimes low values while charging. Anyone has an idea?</p>
]]></description><link>https://community.m5stack.com/topic/5028/m5paper-how-to-detect-usb-power</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Mar 2026 23:13:58 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/5028.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Feb 2023 06:53:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5Paper: how to detect USB power? on Fri, 03 Feb 2023 18:10:45 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/22587">@holofloh</a></p>
<p dir="auto">cool, glad it worked.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/20003</link><guid isPermaLink="true">https://community.m5stack.com/post/20003</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Fri, 03 Feb 2023 18:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper: how to detect USB power? on Fri, 03 Feb 2023 17:41:06 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Felix,</p>
<p dir="auto">I was thinking way to far to solve this problem. The end of my main loop looks now like this:</p>
<pre><code>// If on battery power the system go to sleep and waiting for the wakeup call by RTC
// If on USB power the system stay awake so undo what shutdown() did and waste some time before repeating the main loop
    M5.shutdown(sleepseconds);
    M5.enableMainPower();
    M5.RTC.clearIRQ();
    delay(sleepseconds*1000);
</code></pre>
<p dir="auto">it seems to work.</p>
]]></description><link>https://community.m5stack.com/post/20002</link><guid isPermaLink="true">https://community.m5stack.com/post/20002</guid><dc:creator><![CDATA[holofloh]]></dc:creator><pubDate>Fri, 03 Feb 2023 17:41:06 GMT</pubDate></item><item><title><![CDATA[Reply to M5Paper: how to detect USB power? on Fri, 03 Feb 2023 11:15:34 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/22587">@holofloh</a></p>
<p dir="auto">what you can try is the following. First call the function for a shutdown (which will succeed on battery power, but fail when running from USB), so after that use some <code>delay()</code> to prevent too frequent updates.</p>
<p dir="auto">You should get an idea what I mean from this example <a href="https://github.com/felmue/MyM5StackExamples/blob/main/M5Paper/NonFlickeringUpdateAfterShutdown.ino#L100" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> (about line 100).</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/20001</link><guid isPermaLink="true">https://community.m5stack.com/post/20001</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Fri, 03 Feb 2023 11:15:34 GMT</pubDate></item></channel></rss>