<?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[M5StickC and 18650C hat problem]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I am using M5StickC and 18650C hat together and encountering a weird issue.<br />
First, when assembling them to each other with the designated screws, it seem to disrupt the on/off button or something because it can't be pressed after wise, and maybe related to the fact that my code suddenly gets stuck for no reason.<br />
This is my code(basically I expected to see led on while it is not in sleep mode):</p>
<p dir="auto">#include &lt;WiFi.h&gt;<br />
#include &lt;M5StickC.h&gt;<br />
#include "arduino_secrets.h"</p>
<p dir="auto">char *ssid[] = { SECRET_SSID1 , SECRET_SSID2 , SECRET_SSID3 , SECRET_SSID4 , SECRET_SSID5 };<br />
char *pass[] = { SECRET_PASS1 , SECRET_PASS2 , SECRET_PASS3 , SECRET_PASS4 , SECRET_PASS5 };</p>
<p dir="auto">//#define TIME_TO_SLEEP_SECONDS 3600<br />
#define TIME_TO_SLEEP_SECONDS 60</p>
<p dir="auto">const int LED = 10;<br />
int sm;<br />
String deviceID;<br />
bool sentData = false;</p>
<p dir="auto">void setup() {</p>
<p dir="auto">M5_Setup();</p>
<p dir="auto">wifiTask();</p>
<p dir="auto">}</p>
<p dir="auto">void loop() {</p>
<p dir="auto">wifiTask();</p>
<p dir="auto">M5.update();</p>
<p dir="auto">getSm();</p>
<p dir="auto">if(sentData)<br />
{<br />
Serial.println("Going to sleep, good night");<br />
Serial.flush();<br />
delay(3500);<br />
M5.Axp.DeepSleep(SLEEP_SEC(TIME_TO_SLEEP_SECONDS));<br />
}</p>
<p dir="auto">loopAnalysis();</p>
<p dir="auto">}</p>
<p dir="auto">void getSm() {<br />
#define SMPIN 33<br />
float smVal = analogRead(SMPIN);<br />
float smFloat = smVal * 0.01 + (float) sm * 0.99;<br />
sm = (int) smFloat;<br />
}</p>
<p dir="auto">int httpRequest() {<br />
static WiFiClient client;<br />
static const char WEBSITE[] = "<a href="http://api.pushingbox.com" target="_blank" rel="noopener noreferrer nofollow ugc">api.pushingbox.com</a>";<br />
static const String devid = "v2928F6149137678";</p>
<p dir="auto">client.stop();</p>
<p dir="auto">if (client.connect(WEBSITE, 80)) {<br />
Serial.println("connecting...");<br />
client.print("GET /pushingbox?devid=" + devid<br />
+ "&amp;deviceID=" + (String) deviceID<br />
+ "&amp;sm="      + (String) sm<br />
);<br />
client.println(" HTTP/1.1");<br />
client.print("Host: ");<br />
client.println(WEBSITE);<br />
client.println("Connection: close");<br />
client.println();<br />
Serial.println("Sent data");<br />
sentData = true;<br />
return 1;<br />
} else {<br />
Serial.println("failed to connect to http");<br />
return 0;<br />
}<br />
}</p>
<p dir="auto">void wifiTask() {<br />
static int state = 0;<br />
static int wifiConnectTry = 0;<br />
static int wifiRestartTry = 0;<br />
static int network = 0;<br />
static int wifiStatus = WL_IDLE_STATUS;<br />
static int httpStatus = 0;<br />
static int httpConnectTry = 0;<br />
static unsigned long previousMillis = 0;<br />
unsigned long currentMillis = 0;</p>
<pre><code>#define WIFI_CONNECT_TIMEOUT 10000 // seconds waiting between re-connection attempts
#define HTTP_CONNECT_TIMEOUT 5000
#define HTTP_CONNECTED 1
#define HTTP_DISCONNECTED 0
</code></pre>
<p dir="auto">enum WIFI_STATE_TYPE { WIFI_CONNECT,<br />
HTTP_CONNECT,<br />
HTTP_POLL,<br />
WIFI_STATE_RESTART = 255<br />
};</p>
<p dir="auto">switch ( state )<br />
{<br />
case WIFI_CONNECT:<br />
if ( wifiStatus == WL_CONNECTED )<br />
{<br />
Serial.println("WIFI Connected");<br />
printWifiStatus();<br />
state++;<br />
digitalWrite( LED , LOW );<br />
break;<br />
}<br />
if ( millis() - previousMillis &lt; WIFI_CONNECT_TIMEOUT &amp;&amp; wifiConnectTry &gt; 0 )<br />
{<br />
break;<br />
}</p>
<pre><code>if ( wifiConnectTry &gt; 9 )
{
  state = WIFI_STATE_RESTART;
  break;
}

if ( wifiRestartTry &gt; 1 )
{
  wifiRestartTry = 0;
  network++;
  if (network == 5) {
    network = 0;
  }
  Serial.println( "Switched to network: " + String(network));
  break;  
}

wifiStatus = WiFi.begin( ssid[network], pass[network] );
previousMillis = millis();
wifiConnectTry++;
Serial.print( "Try: " );
Serial.print( wifiConnectTry );
Serial.print( " Status: " );
Serial.println( wifiStatus );
break;
</code></pre>
<p dir="auto">case HTTP_CONNECT:<br />
if (httpStatus == HTTP_CONNECTED) {<br />
state++;<br />
break;<br />
}<br />
if ( millis() - previousMillis &lt; HTTP_CONNECT_TIMEOUT &amp;&amp; httpConnectTry &gt; 0 )<br />
{<br />
break;<br />
}</p>
<pre><code>if ( httpConnectTry &gt; 10 )
{
  state = WIFI_STATE_RESTART;
  break;
}
httpStatus = httpRequest();
previousMillis = millis();
httpConnectTry++;
Serial.print( "http Try: " );
Serial.print( httpConnectTry );
Serial.print( " http Status: " );
Serial.println( httpStatus );
break;
</code></pre>
<p dir="auto">case HTTP_POLL:<br />
httpStatus = httpRequest();<br />
if (httpStatus == HTTP_DISCONNECTED) {<br />
if (WiFi.status() == WL_CONNECTED) {<br />
state = HTTP_CONNECT;<br />
break;<br />
}<br />
else {<br />
state = WIFI_STATE_RESTART;<br />
break;<br />
}<br />
}<br />
break;<br />
default:<br />
state = 0;<br />
wifiConnectTry = 0;<br />
wifiStatus = WL_IDLE_STATUS;<br />
httpConnectTry = 0;<br />
httpStatus = HTTP_DISCONNECTED;<br />
WiFi.disconnect();<br />
Serial.println( "WiFi restart" );<br />
wifiRestartTry++;<br />
break;<br />
}</p>
<p dir="auto">}</p>
<p dir="auto">void printWifiStatus() {<br />
static byte mac[6];<br />
Serial.print("SSID: ");<br />
Serial.println(WiFi.SSID());</p>
<p dir="auto">IPAddress ip = WiFi.localIP();<br />
Serial.print("IP Address: ");<br />
Serial.println(ip);</p>
<p dir="auto">long rssi = WiFi.RSSI();<br />
Serial.print("signal strength (RSSI):");<br />
Serial.print(rssi);<br />
Serial.println(" dBm");</p>
<p dir="auto">WiFi.macAddress(mac);<br />
String mac0,mac1,mac2,mac3,mac4,mac5;<br />
mac0 = String(mac[0],HEX);<br />
mac1 = String(mac[1],HEX);<br />
mac2 = String(mac[2],HEX);<br />
mac3 = String(mac[3],HEX);<br />
mac4 = String(mac[4],HEX);<br />
mac5 = String(mac[5],HEX);<br />
deviceID = String(mac5 + ":" + mac4 + ":" + mac3 + ":" + mac2 + ":" + mac1 + ":" + mac0);<br />
Serial.print("mac address: "); Serial.println(deviceID);<br />
}</p>
<p dir="auto">void loopAnalysis()<br />
{<br />
static unsigned long previousMillis = 0;<br />
static unsigned long lastMillis = 0;<br />
static unsigned long minLoopTime = 0xFFFFFFFF;<br />
static unsigned long maxLoopTime = 0;<br />
static unsigned long loopCounter = 0;</p>
<p dir="auto">#define INTERVAL 1000</p>
<p dir="auto">unsigned long currentMillis = millis();<br />
if ( currentMillis - previousMillis &gt; INTERVAL )<br />
{<br />
Serial.print( "Loops: " );<br />
Serial.print( loopCounter );<br />
Serial.print( " ( " );<br />
Serial.print( minLoopTime );<br />
Serial.print( " / " );<br />
Serial.print( maxLoopTime );<br />
Serial.println( " )" );<br />
previousMillis = currentMillis;<br />
loopCounter = 0;<br />
minLoopTime = 0xFFFFFFFF;<br />
maxLoopTime = 0;<br />
}<br />
loopCounter++;<br />
unsigned long loopTime = currentMillis - lastMillis;<br />
lastMillis = currentMillis;<br />
if ( loopTime &lt; minLoopTime )<br />
{<br />
minLoopTime = loopTime;<br />
}<br />
if ( loopTime &gt; maxLoopTime )<br />
{<br />
maxLoopTime = loopTime;<br />
}</p>
<p dir="auto">}</p>
<p dir="auto">void M5_Setup() {<br />
M5.begin();<br />
M5.Axp.ScreenBreath(0);<br />
pinMode(LED,OUTPUT);<br />
digitalWrite(LED,LOW);<br />
}</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://community.m5stack.com/topic/2166/m5stickc-and-18650c-hat-problem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 04:14:07 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2166.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Jul 2020 14:51:50 GMT</pubDate><ttl>60</ttl></channel></rss>