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

    5V stops working m5stickc

    M5 Stick/StickC
    4
    8
    11.4k
    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.
    • O
      OS88
      last edited by

      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 BLE

      void 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);
      }

      1 Reply Last reply Reply Quote 0
      • m5stackM
        m5stack
        last edited by m5stack

        you could check your code does have operation for AXP192. usually esp32 sleep don't affect the AXP192 output.

        1 Reply Last reply Reply Quote 0
        • O
          OS88
          last edited by

          Hi,
          Thanks for the reply. Is there a way to reset AXP to its initial values?

          1 Reply Last reply Reply Quote 0
          • P
            Pepsi
            last edited by

            Is it the 5volt at the grove connector. Or the unit side?

            O 1 Reply Last reply Reply Quote 0
            • O
              OS88 @Pepsi
              last edited by

              @pepsi Both sides don't work

              1 Reply Last reply Reply Quote 0
              • P
                Pepsi
                last edited by

                @os88 said in 5V stops working m5stickc:

                //#include <M5StickC.h>

                I only had the problem, when i uploaded my code the StickC was on. If i turned it off, i was not able to turn it back on with the power button.

                Just like you i had commented out the m5stack.h code.

                //#include <M5StickC.h>

                Have you tried it when the code Is not uncommitted?

                1 Reply Last reply Reply Quote 1
                • ajb2k3A
                  ajb2k3
                  last edited by ajb2k3

                  @os88 said in 5V stops working m5stickc:

                  void setupPins(){
                  //M5.begin();
                  Serial.begin(115200);
                  prints();
                  pinMode(LED,OUTPUT);
                  digitalWrite(LED,LOW);
                  pinMode(leftSidePin, INPUT_PULLUP);
                  pinMode(rightSidePin, INPUT_PULLUP);
                  }

                  Should be at the beginning of the code and uncomment M5Begin.

                  UIFlow, so easy an adult can learn it!
                  If I don't know it, be patient!
                  I've ether not learned it or am too drunk to remember it!
                  Author of the WIP UIFlow Handbook!
                  M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                  1 Reply Last reply Reply Quote 1
                  • m5stackM
                    m5stack
                    last edited by

                    just like him said. don't comment the M5.begin();

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post