Fix: just had to remove this line
while (!Serial);
Fix: just had to remove this line
while (!Serial);
So, for my project I need to power my M5Stack CoreS3 through an external power source.
I figured I just had to connect the 5V pin to the power source and GND to GND, but that doesn't quite work.
It seems like the CoreS3 boots up (display starts), but
I added a short sound to the code and I can hear it, but not as loud as with USB. Maybe it's some kind of power saving mode?
Would really appreciate any help I get!
This is the code I use:
#include <NeoPixelBus.h>
#include <M5Unified.h>
#include <ArduinoOTA.h>
#include <WiFi.h>
const char* wifi_ssids[] = {/*ssids*/};
const char* wifi_passwords[] = {/*passwords*/};
const int wifi_count = sizeof(wifi_ssids) / sizeof(wifi_ssids[0]);
const uint16_t numLeds = 38;
NeoPixelBus<NeoGrbFeature, NeoEsp32LcdX8Ws2812xMethod> strip1(numLeds, 37);
NeoPixelBus<NeoGrbFeature, NeoEsp32LcdX8Ws2812xMethod> strip2(numLeds, 5);
NeoPixelBus<NeoGrbFeature, NeoEsp32LcdX8Ws2812xMethod> strip3(numLeds, 6);
NeoPixelBus<NeoGrbFeature, NeoEsp32LcdX8Ws2812xMethod> strip4(numLeds, 7);
NeoPixelBus<NeoGrbFeature, NeoEsp32LcdX8Ws2812xMethod> strip5(numLeds, 1);
NeoPixelBus<NeoGrbFeature, NeoEsp32LcdX8Ws2812xMethod> strip6(numLeds, 36);
NeoPixelBus<NeoGrbFeature, NeoEsp32LcdX8Ws2812xMethod> strip7(numLeds, 35);
uint16_t hue = 0;
const uint16_t hueMax = 360;
const uint16_t hueDelta = 8;
void setup_wifi() {
for (int i = 0; i < wifi_count; i++) {
Serial.printf("Trying WiFi SSID: %s\n", wifi_ssids[i]);
WiFi.begin(wifi_ssids[i], wifi_passwords[i]);
int retries = 0;
while (WiFi.status() != WL_CONNECTED && retries < 10) {
delay(500);
Serial.print(".");
retries++;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.printf("Connected to WiFi SSID: %s\n", wifi_ssids[i]);
Serial.printf("IP address: %s\n", WiFi.localIP().toString().c_str());
return;
} else {
Serial.printf("Failed to connect to %s\n", wifi_ssids[i]);
}
}
Serial.println("All WiFi connection attempts failed. Restarting...");
delay(5000);
ESP.restart();
}
void setup() {
auto cfg = M5.config();
cfg.external_speaker.module_display = true;
M5.begin(cfg);
M5.Speaker.begin();
auto spk = M5.Speaker.config();
spk.dma_buf_len = 256;
spk.dma_buf_count = 8;
M5.Speaker.config(spk);
M5.Speaker.setVolume(32);
setup_wifi();
M5.Speaker.tone(6000, 50);
Serial.begin(115200);
while (!Serial);
Serial.println("Initializing...");
strip1.Begin();
strip2.Begin();
strip3.Begin();
strip4.Begin();
strip5.Begin();
strip6.Begin();
strip7.Begin();
ArduinoOTA.setHostname("SmartPBL");
ArduinoOTA.setPassword("innovativsmart");
ArduinoOTA.onStart([]() {
Serial.println("Start OTA update");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nOTA update finished");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("OTA Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Running...");
}
void loop() {
ArduinoOTA.handle();
for (uint16_t i = 0; i < numLeds; i++) {
uint16_t ledHue = (hue + (i * 360 / numLeds)) % hueMax;
HslColor color(ledHue / (float)hueMax, 1.0f, 0.5f);
strip1.SetPixelColor(i, color);
strip2.SetPixelColor(i, color);
strip3.SetPixelColor(i, color);
strip4.SetPixelColor(i, color);
strip5.SetPixelColor(i, color);
strip6.SetPixelColor(i, color);
strip7.SetPixelColor(i, color);
}
strip1.Show();
strip2.Show();
strip3.Show();
strip4.Show();
strip5.Show();
strip6.Show();
strip7.Show();
hue = (hue + hueDelta) % hueMax;
delay(20);
}
I have a M5Stack CoreS3 and want to connect the Unit QRCode to it. At first everything worked well by just using the example code from Github.
/*
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/**
* @file i2c_mode.ino
* @brief Unit QRCode I2C Mode Example
* @version 0.2
* @date 2024-06-19
*
*
* @Hardwares: M5Core + Unit QRCode
* @Platform Version: Arduino M5Stack Board Manager v2.1.0
* @Dependent Library:
* M5Unified: https://github.com/m5stack/M5Unified
* M5GFX: https://github.com/m5stack/M5GFX
* M5UnitQRCode: https://github.com/m5stack/M5Unit-QRCode
*/
#include <M5Unified.h>
#include <M5GFX.h>
#include "M5UnitQRCode.h"
M5Canvas canvas(&M5.Display);
M5UnitQRCodeI2C qrcode;
#define I2C_AUTO_SCAN_MODE
void setup() {
M5.begin();
canvas.setColorDepth(1); // mono color
canvas.createSprite(M5.Display.width(), M5.Display.height());
canvas.setTextSize((float)canvas.width() / 160);
canvas.setTextScroll(true);
Wire.begin(9,8); // Port B
while (!qrcode.begin(&Wire, UNIT_QRCODE_ADDR, 21, 22, 100000U)) {
canvas.println("Unit QRCode I2C Init Fail");
Serial.println("Unit QRCode I2C Init Fail");
canvas.pushSprite(0, 0);
delay(1000);
}
canvas.println("Unit QRCode I2C Init Success");
Serial.println("Unit QRCode I2C Init Success");
#ifdef I2C_AUTO_SCAN_MODE
canvas.println("Auto Scan Mode");
canvas.pushSprite(0, 0);
qrcode.setTriggerMode(AUTO_SCAN_MODE);
#else
canvas.println("Manual Scan Mode");
canvas.pushSprite(0, 0);
qrcode.setTriggerMode(MANUAL_SCAN_MODE);
#endif
}
void loop() {
if (qrcode.getDecodeReadyStatus() == 1) {
uint8_t buffer[512] = {0};
uint16_t length = qrcode.getDecodeLength();
Serial.printf("len:%d\r\n", length);
qrcode.getDecodeData(buffer, length);
Serial.printf("decode data:");
for (int i = 0; i < length; i++) {
Serial.printf("%c", buffer[i]);
canvas.printf("%c", buffer[i]);
}
Serial.println();
canvas.println();
canvas.pushSprite(0, 0);
}
#ifndef I2C_AUTO_SCAN_MODE
M5.update();
if (M5.BtnA.wasPressed()) {
// start scan
qrcode.setDecodeTrigger(1);
}
if (M5.BtnB.wasPressed()) {
// stop scan
qrcode.setDecodeTrigger(0);
}
#endif
}
just had to add the Wire.begin(9,8) line.
When I first plugged the scanner in, it was automatically in Auto Scan Mode and it worked fine, but all of a sudden (I can't remember if I did anything to cause this, sry) the unit only scans when I hit the trigger button and I can't read the codes anymore.
Maybe I just need to do a factory reset of the scanner, but I wasn't able to find information on that.
Would really appreciate your help!