Hi,
I have a few M5StickC's that I didn't touch for a long time(~months), it only works when connected to cable.
What can I do to revive the battery?
Thanks
Posts made by OS88
-
M5StickC works only with cable connected
-
M5StickC and 18650C hat problem
Hi,
I am using M5StickC and 18650C hat together and encountering a weird issue.
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.
This is my code(basically I expected to see led on while it is not in sleep mode):#include <WiFi.h>
#include <M5StickC.h>
#include "arduino_secrets.h"char *ssid[] = { SECRET_SSID1 , SECRET_SSID2 , SECRET_SSID3 , SECRET_SSID4 , SECRET_SSID5 };
char *pass[] = { SECRET_PASS1 , SECRET_PASS2 , SECRET_PASS3 , SECRET_PASS4 , SECRET_PASS5 };//#define TIME_TO_SLEEP_SECONDS 3600
#define TIME_TO_SLEEP_SECONDS 60const int LED = 10;
int sm;
String deviceID;
bool sentData = false;void setup() {
M5_Setup();
wifiTask();
}
void loop() {
wifiTask();
M5.update();
getSm();
if(sentData)
{
Serial.println("Going to sleep, good night");
Serial.flush();
delay(3500);
M5.Axp.DeepSleep(SLEEP_SEC(TIME_TO_SLEEP_SECONDS));
}loopAnalysis();
}
void getSm() {
#define SMPIN 33
float smVal = analogRead(SMPIN);
float smFloat = smVal * 0.01 + (float) sm * 0.99;
sm = (int) smFloat;
}int httpRequest() {
static WiFiClient client;
static const char WEBSITE[] = "api.pushingbox.com";
static const String devid = "v2928F6149137678";client.stop();
if (client.connect(WEBSITE, 80)) {
Serial.println("connecting...");
client.print("GET /pushingbox?devid=" + devid
+ "&deviceID=" + (String) deviceID
+ "&sm=" + (String) sm
);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(WEBSITE);
client.println("Connection: close");
client.println();
Serial.println("Sent data");
sentData = true;
return 1;
} else {
Serial.println("failed to connect to http");
return 0;
}
}void wifiTask() {
static int state = 0;
static int wifiConnectTry = 0;
static int wifiRestartTry = 0;
static int network = 0;
static int wifiStatus = WL_IDLE_STATUS;
static int httpStatus = 0;
static int httpConnectTry = 0;
static unsigned long previousMillis = 0;
unsigned long currentMillis = 0;#define WIFI_CONNECT_TIMEOUT 10000 // seconds waiting between re-connection attempts #define HTTP_CONNECT_TIMEOUT 5000 #define HTTP_CONNECTED 1 #define HTTP_DISCONNECTED 0
enum WIFI_STATE_TYPE { WIFI_CONNECT,
HTTP_CONNECT,
HTTP_POLL,
WIFI_STATE_RESTART = 255
};switch ( state )
{
case WIFI_CONNECT:
if ( wifiStatus == WL_CONNECTED )
{
Serial.println("WIFI Connected");
printWifiStatus();
state++;
digitalWrite( LED , LOW );
break;
}
if ( millis() - previousMillis < WIFI_CONNECT_TIMEOUT && wifiConnectTry > 0 )
{
break;
}if ( wifiConnectTry > 9 ) { state = WIFI_STATE_RESTART; break; } if ( wifiRestartTry > 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;
case HTTP_CONNECT:
if (httpStatus == HTTP_CONNECTED) {
state++;
break;
}
if ( millis() - previousMillis < HTTP_CONNECT_TIMEOUT && httpConnectTry > 0 )
{
break;
}if ( httpConnectTry > 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;
case HTTP_POLL:
httpStatus = httpRequest();
if (httpStatus == HTTP_DISCONNECTED) {
if (WiFi.status() == WL_CONNECTED) {
state = HTTP_CONNECT;
break;
}
else {
state = WIFI_STATE_RESTART;
break;
}
}
break;
default:
state = 0;
wifiConnectTry = 0;
wifiStatus = WL_IDLE_STATUS;
httpConnectTry = 0;
httpStatus = HTTP_DISCONNECTED;
WiFi.disconnect();
Serial.println( "WiFi restart" );
wifiRestartTry++;
break;
}}
void printWifiStatus() {
static byte mac[6];
Serial.print("SSID: ");
Serial.println(WiFi.SSID());IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");WiFi.macAddress(mac);
String mac0,mac1,mac2,mac3,mac4,mac5;
mac0 = String(mac[0],HEX);
mac1 = String(mac[1],HEX);
mac2 = String(mac[2],HEX);
mac3 = String(mac[3],HEX);
mac4 = String(mac[4],HEX);
mac5 = String(mac[5],HEX);
deviceID = String(mac5 + ":" + mac4 + ":" + mac3 + ":" + mac2 + ":" + mac1 + ":" + mac0);
Serial.print("mac address: "); Serial.println(deviceID);
}void loopAnalysis()
{
static unsigned long previousMillis = 0;
static unsigned long lastMillis = 0;
static unsigned long minLoopTime = 0xFFFFFFFF;
static unsigned long maxLoopTime = 0;
static unsigned long loopCounter = 0;#define INTERVAL 1000
unsigned long currentMillis = millis();
if ( currentMillis - previousMillis > INTERVAL )
{
Serial.print( "Loops: " );
Serial.print( loopCounter );
Serial.print( " ( " );
Serial.print( minLoopTime );
Serial.print( " / " );
Serial.print( maxLoopTime );
Serial.println( " )" );
previousMillis = currentMillis;
loopCounter = 0;
minLoopTime = 0xFFFFFFFF;
maxLoopTime = 0;
}
loopCounter++;
unsigned long loopTime = currentMillis - lastMillis;
lastMillis = currentMillis;
if ( loopTime < minLoopTime )
{
minLoopTime = loopTime;
}
if ( loopTime > maxLoopTime )
{
maxLoopTime = loopTime;
}}
void M5_Setup() {
M5.begin();
M5.Axp.ScreenBreath(0);
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
}Thanks!
-
M5StickC 18650C hat grove port
Hi,
I couldn't understand from the description of the product, is the grove connection exposed when attaching this hat? or is canceled practically when using it?
Thanks. -
RE: 5V stops working m5stickc
Hi,
Thanks for the reply. Is there a way to reset AXP to its initial values? -
5V stops working m5stickc
Hi,
I have a few M5stickc's that I uploaded the added code, and after uploading it the 5V port stops giving voltage immediatly.
What could be the issue? I am using sleep mode, BLE, and reading some IO's basically.
This is the code://#include <M5StickC.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
//STATE MACHINE
#define NONE 0
#define LEFT_ACTIVE 1
#define RIGHT_ACTIVE 2
#define BOTH_ACTIVE 3
#define TIME_BEFORE_SLEEP 10000
#define TIME_BEFORE_SEND 2000
RTC_DATA_ATTR int lastState = NONE;
//#define BUTTON_PIN_BITMASK 0x4000001 //for pins 0,26
#define BUTTON_PIN_BITMASK 0x300000000 //for pins 32,33
int state = BOTH_ACTIVE;
int leftStatus;
int rightStatus;
const int leftSidePin = 32;
const int rightSidePin = 33;
const int LED = 10;
unsigned int pingTime = 0;
//************END STATE MACHINE//BLE****
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
bool deviceConnected = false;
bool firstConnection = false;#define SERVICE_UUID "801a272c-a57b-11ea-bb37-0242ac130002"
#define CHARACTERISTIC_UUID "801a29a2-a57b-11ea-bb37-0242ac130002"class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
firstConnection = true;
pingTime = millis();
};void onDisconnect(BLEServer* pServer) { deviceConnected = false; }
};
//END BLEvoid setup()
{
setupPins();startBLEServer();
//wakingUp();
//startSleep();
}void loop()
{
refreshStatus();
if (deviceConnected){
if (firstConnection) {
firstConnection = false;
delay(300);
pCharacteristic->setValue(state);
pCharacteristic->notify();
}
else if (millis() - pingTime > 5000) {
pingTime = millis();
pCharacteristic->setValue(state);
pCharacteristic->notify();
if ( state == NONE ) {
delay(300);
startSleep();
}
}
}
}void startSleep() {
gpio_hold_en(GPIO_NUM_32);
gpio_hold_en(GPIO_NUM_33);
gpio_deep_sleep_hold_en();
Serial.println("Active high will wake me up");
esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);
esp_deep_sleep_start();Serial.println("This will never be printed");
}void wakingUp(){
esp_sleep_wakeup_cause_t wakeup_reason;wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}refreshStatus();
}
void refreshStatus() {
readInputs();
getState();
reportStatus();
}
void reportStatus() {
if (state == NONE) {
if (lastState == RIGHT_ACTIVE) {
Serial.println("closed right side");
}
else if (lastState == LEFT_ACTIVE) {
Serial.println("closed left side");
}
else {
Serial.println("error - shouldn't be here L95");
}
}
else if (state == RIGHT_ACTIVE) {
Serial.println("Right side active");
}
else if (state == LEFT_ACTIVE) {
Serial.println("Left side active");
}
else if (state == BOTH_ACTIVE) {
Serial.println("Both active");
}
prints();
lastState = state;
}void readInputs() {
leftStatus = digitalRead(leftSidePin);
rightStatus = digitalRead(rightSidePin);
}void getState() {
if (!leftStatus && !rightStatus) {
state = NONE;
}
else if (!leftStatus && rightStatus) {
state = RIGHT_ACTIVE;
}
else if (leftStatus && !rightStatus) {
state = LEFT_ACTIVE;
}
else {
state = BOTH_ACTIVE; // default
}
Serial.printf("You are in state %d\n",state);
}void prints() {
Serial.printf("State: %d, Last state: %d, Left status: %d, Right status: %d,\n",state,lastState,leftStatus,rightStatus);
}void startBLEServer(){
BLEDevice::init("BLE");
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_INDICATE
);pCharacteristic->addDescriptor(new BLE2902());
pService->start();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(false);
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
BLEDevice::startAdvertising();
Serial.println("Waiting a client connection to notify...");
}void setupPins(){
//M5.begin();
Serial.begin(115200);
prints();
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
pinMode(leftSidePin, INPUT_PULLUP);
pinMode(rightSidePin, INPUT_PULLUP);
} -
PuppyC schematic
Hi,
I have a puppyC and can't find anywhere an example for it, or the least where the servos are connected to.
Thanks,
Omri.