Issues uploading code to M5-Stick-C

Hi all,

directly: I am a complete newbee in regards to Arduino/ M5-Stick/... - So thanks for your support and it will propably be the most obvious solutions possible :smiley:

I purchased some M5-Stick-C (not Plus) to build myself some Tally-Lights with the following instruction:

I already followed all the steps and got it working #yeah
Since i last used them (~ mid october) the Sticks have bin powered off in the shelf.
For my next production, i wanted to load & test them.

Sadly, none of the 5 Sticks i have are able to power on, even after a whole night of charging.
So, i took one of them and used the M5 Burner to bring up some other software - which works without problem. I can power on & power off.

Once i tried to upload my Tally-Light-Code again, nothing happens.
Neither the Code nor the computer has been changed since the succesfull installation and as far as i see it, all information in Arduino are correct:

Board: M5Stick-C
Speed: 1500000
Port: COM3

It also seams to connect as the Test-Software installed via M5Burner isn't working anymore.
Nevertheless, Arduino freezes as "Hard resetting via RTS pin..." without restarting the M5-Stick (as it did in the past).

I would be happy for every suggestion on how to get my M5-Stick running again.
Thanks & Cheers

Felix


Arduino Version: 1.8.16
Hardware: M5Stick-C
OS: Win10

Code:

#ifdef ARDUINO_ARCH_AVR
#include <avr/pgmspace.h>
#else
#include <pgmspace.h>
#endif

// http://librarymanager/All#M5StickC https://github.com/m5stack/M5StickC
#include <M5StickC.h>
#include <WiFi.h>

// Download these from here
// https://github.com/kasperskaarhoj/SKAARHOJ-Open-Engineering/tree/master/ArduinoLibs
#include <SkaarhojPgmspace.h>
#include <ATEMbase.h>
#include <ATEMstd.h>

// Define the IP address of your ATEM switcher
IPAddress switcherIp(192,168,178,24);

// Put your wifi SSID and password here
const char* ssid = "my-ssid";
const char* password = "my-password";

// Set this to 1 if you want the orientation to update automatically
#define AUTOUPDATE_ORIENTATION 1

// You can customize the red/green/grey if you want
// http://www.barth-dev.de/online/rgb565-color-picker/
#define GRAY  0x0841 //   8   8  8
#define GREEN 0x0400 //   0 128  0
#define RED   0xF800 // 255   0  0

/////////////////////////////////////////////////////////////
// You probably don't need to change things below this line
#define LED_PIN 10

ATEMstd AtemSwitcher;

int orientation = 0;
int orientationPrevious = 0;
int orientationMillisPrevious = millis();
int buttonBMillis = 0;

int cameraNumber = 1;

int previewTallyPrevious = 1;
int programTallyPrevious = 1;
int cameraNumberPrevious = cameraNumber;

void setup() {
  Serial.begin(9600);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println("Connected to the WiFi network");

  // 初期化
  M5.begin();
  M5.MPU6886.Init();
  M5.Lcd.setRotation(orientation);

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);

  AtemSwitcher.begin(switcherIp);
  AtemSwitcher.serialOutput(0x80);
  AtemSwitcher.connect();

  // GPIO初期化
  pinMode(26, INPUT); // PIN  (INPUT, OUTPUT, ANALOG)無線利用時にはANALOG利用不可, DAC出力可
  pinMode(36, INPUT); // PIN  (INPUT,       , ANALOG)入力専用、INPUT_PULLUP等も不可
  pinMode( 0, INPUT); // PIN  (INPUT, OUTPUT,       )外部回路でプルアップ済み
  pinMode(32, INPUT); // GROVE(INPUT, OUTPUT, ANALOG)
  pinMode(33, INPUT); // GROVE(INPUT, OUTPUT, ANALOG)
}

void setOrientation() {
  float accX = 0, accY = 0, accZ = 0;
  M5.MPU6886.getAccelData(&accX, &accY, &accZ);
  //Serial.printf("%.2f   %.2f   %.2f \n",accX * 1000, accY * 1000, accZ * 1000);

  if (accZ < .9) {
    if (accX > .6) {
      orientation = 1;
    } else if (accX < .4 && accX > -.5) {
      if (accY > 0) {
        orientation = 0;
      } else {
        orientation = 2;
      }
    } else {
      orientation = 3;
    }
  }

  if (orientation != orientationPrevious) {
    Serial.printf("Orientation changed to %d\n", orientation);
    M5.Lcd.setRotation(orientation);
  }
}


void loop() {
  // ボタンの状態更新
  M5.update();

  if (AUTOUPDATE_ORIENTATION) {
    if (orientationMillisPrevious + 500 < millis()) {
      setOrientation();
      orientationMillisPrevious = millis();
    }
  }

  if (M5.BtnA.wasPressed()) {
    AtemSwitcher.changeProgramInput(cameraNumber);
  }
  if (M5.BtnB.wasPressed()) {
    setOrientation();
    buttonBMillis = millis();
  }

  if (M5.BtnB.isPressed() && buttonBMillis != 0 && buttonBMillis < millis() - 500) {
    Serial.println("Changing camera number");
    cameraNumber = (cameraNumber % 4) + 1;
    Serial.printf("New camera number: %d\n", cameraNumber);

    buttonBMillis = 0;
  }

  // Check for packets, respond to them etc. Keeping the connection alive!
  AtemSwitcher.runLoop();

  int programTally = AtemSwitcher.getProgramTally(cameraNumber);
  int previewTally = AtemSwitcher.getPreviewTally(cameraNumber);

  if ((orientation != orientationPrevious) || (cameraNumber != cameraNumberPrevious) || (programTallyPrevious != programTally) || (previewTallyPrevious != previewTally)) { // changed?
    if (programTally && !previewTally) { // only program
      drawLabel(RED, BLACK, LOW);
    } else if (programTally && previewTally) { // program AND preview
      drawLabel(RED, GREEN, LOW);
    } else if (previewTally && !programTally) { // only preview
      drawLabel(GREEN, BLACK, HIGH);
    } else if (!previewTally || !programTally) { // neither
      drawLabel(BLACK, GRAY, HIGH);
    }
  }

  programTallyPrevious = programTally;
  previewTallyPrevious = previewTally;
  cameraNumberPrevious = cameraNumber;
  orientationPrevious  = orientation;
}

void drawLabel(unsigned long int screenColor, unsigned long int labelColor, bool ledValue) {
  digitalWrite(LED_PIN, ledValue);
  M5.Lcd.fillScreen(screenColor);
  M5.Lcd.setTextColor(labelColor, screenColor);
  drawStringInCenter(String(cameraNumber), 8);
}

void drawStringInCenter(String input, int font) {
  int datumPrevious = M5.Lcd.getTextDatum();
  M5.Lcd.setTextDatum(MC_DATUM);
  M5.Lcd.drawString(input, M5.Lcd.width() / 2, M5.Lcd.height() / 2, font);
  M5.Lcd.setTextDatum(datumPrevious);
}

A link to the datasheet for the M5-stuff had been useful.... I wasn't born with any such stuff in my pockets...

you might have a depleted battery and the protection circuit won't let you charge it again.

That was my first thought, but using any Code via the M5Burner Application works without any issues and the display is working too. Even when tried with a pluged in USB-C Cable my Code won't work... Thanks for your help!

Sorry, i did not thought about that.
Is this any helpful? https://docs.m5stack.com/en/core/m5stickc
Thanks for your support!

did you quit the "M5Burner Application" when you tried to upload using the IDE?

No, but i just tried - sadly without success.
image

The automatic restart is not happening.
Manual Power off is possible, a manual start isn't.
The Screen now stays black until i apply other software....

Thanks for your help!

OK - So it seems the upload from the Arduino is happening but the reboot does not work for some reason...

no specific idea...

I just double-checked - I can upload other code without getting the issues (i testet with this one: M5StickC/Button.ino at master · m5stack/M5StickC · GitHub). It just seams to be the case with my code (see above)... Strange...

I just had a deeper look on the Upload-Info:

esptool.py v3.0-dev
Serial port COM3
Connecting......
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: 94:b9:7e:93:30:70
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 1500000
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 4096.0 kbit/s)...
Hash of data verified.
Compressed 17120 bytes to 11166...
Writing at 0x00001000... (100 %)
Wrote 17120 bytes (11166 compressed) at 0x00001000 in 0.1 seconds (effective 1095.7 kbit/s)...
Hash of data verified.
Compressed 702240 bytes to 427513...
Writing at 0x00010000... (3 %)
Writing at 0x00014000... (7 %)
Writing at 0x00018000... (11 %)
Writing at 0x0001c000... (14 %)
Writing at 0x00020000... (18 %)
Writing at 0x00024000... (22 %)
Writing at 0x00028000... (25 %)
Writing at 0x0002c000... (29 %)
Writing at 0x00030000... (33 %)
Writing at 0x00034000... (37 %)
Writing at 0x00038000... (40 %)
Writing at 0x0003c000... (44 %)
Writing at 0x00040000... (48 %)
Writing at 0x00044000... (51 %)
Writing at 0x00048000... (55 %)
Writing at 0x0004c000... (59 %)
Writing at 0x00050000... (62 %)
Writing at 0x00054000... (66 %)
Writing at 0x00058000... (70 %)
Writing at 0x0005c000... (74 %)
Writing at 0x00060000... (77 %)
Writing at 0x00064000... (81 %)
Writing at 0x00068000... (85 %)
Writing at 0x0006c000... (88 %)
Writing at 0x00070000... (92 %)
Writing at 0x00074000... (96 %)
Writing at 0x00078000... (100 %)
Wrote 702240 bytes (427513 compressed) at 0x00010000 in 6.8 seconds (effective 830.6 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 128...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 1536.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Does anyone know, what the "> WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?" means?

When uploading another code, i don't get this line.

Ok... I just kind of solved the problem.
I still have no idea, why the reseting did not work, but now it works again...
In my previous tests, i tried to come to the "connecting..." Part (around line 50).
Therefore, i jused another Network with no device with the named IP in it.
I now built up the setup with the correct network incl. the ATEM Mini Pro and it works... It seams like there is a bug in the code regarding the network connection, but with a network & device in it, it works without issues..... Strange... Sorry for the mess and thanks to all helpers! :slight_smile: