M5Dial
M5Dial copied to clipboard
wifi not work when rfid is enabled
even a simple code like this can raise my problem
//connect to WiFi Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" CONNECTED");
with this config setting everything is ok
M5Dial.begin(cfg, false, false);
but if i enable rfid
M5Dial.begin(cfg, false, true);
m5dial can connect only once to my wifi network, i have a fritzbox router
any idea?
we have tested the RFID function with wifi, and also tested reconnecting multiple times, is problem. Hi, could you provide the full code you're using?
/**
@file rfid.ino
@author SeanKwok ([email protected])
@brief M5Dial RFID Test
@version 0.2
@date 2023-10-18
@Hardwares: M5Dial
@Platform Version: Arduino M5Stack Board Manager v2.0.7
@Dependent Library:
M5GFX: https://github.com/m5stack/M5GFX
M5Unified: https://github.com/m5stack/M5Unified
*/
#include "M5Dial.h"
#include <HTTPClient.h>
#include <ArduinoJson.h>
//Your Domain name with URL path or IP address with path
const char* serverName = "http://arduinojson.org/example.json";
const char* ssid = "XXXX";
const char* password = "YYYY";
String sensorReadings;
void setup() {
auto cfg = M5.config();
cfg.serial_baudrate = 115200;
M5Dial.begin(cfg, false, true);
M5Dial.Display.setTextColor(GREEN);
M5Dial.Display.setTextDatum(middle_center);
M5Dial.Display.setTextFont(&fonts::Orbitron_Light_32);
M5Dial.Display.setTextSize(1);
M5Dial.Display.drawString("RFID Card", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
//contrrollare il server
}
void loop() {
if (M5Dial.Rfid.PICC_IsNewCardPresent() && M5Dial.Rfid.PICC_ReadCardSerial()) {
M5Dial.Display.clear();
Serial.print(F("PICC type: "));
uint8_t piccType = M5Dial.Rfid.PICC_GetType(M5Dial.Rfid.uid.sak);
Serial.println(M5Dial.Rfid.PICC_GetTypeName(piccType));
// Check is the PICC of Classic MIFARE type
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI && piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F("Your tag is not of type MIFARE Classic."));
M5Dial.Display.drawString("not support", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2);
//return;
}
String uid = "";
for (byte i = 0; i < M5Dial.Rfid.uid.size; i++) {
Serial.printf("%02X ", M5Dial.Rfid.uid.uidByte[i]);
uid += String(M5Dial.Rfid.uid.uidByte[i], HEX);
}
sensorReadings = httpGETRequest(serverName);
Serial.println(sensorReadings);
// Parse response
//const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
DynamicJsonDocument doc(2048);
deserializeJson(doc, sensorReadings);
/*if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
//client.stop();
return;
}*/
Serial.println(doc["time"].as<long>());
//JSONVar myObject = JSON.parse(sensorReadings);
// JSON.typeof(jsonVar) can be used to get the type of the var
/*if (JSON.typeof(myObject) == "undefined") {
Serial.println("Parsing input failed!");
return;
}*/
M5Dial.Speaker.tone(8000, 20);
M5Dial.Display.drawString(M5Dial.Rfid.PICC_GetTypeName(piccType), M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 30);
M5Dial.Display.drawString("card id:", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2);
M5Dial.Display.drawString(uid, M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 30);
Serial.println();
}
}
String httpGETRequest(const char* serverName) {
HTTPClient http;
// Your IP address with path or Domain name with URL path
http.begin(serverName);
// If you need Node-RED/server authentication, insert user and password below
//http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "{}";
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
} else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
you may notice some random weirdness like wifi not connecting or empty serial output
The problem might be due to WiFi + RFID drawing too much current. WiFi draws lots of current when scanning for access points (that is when disconnected).Try connecting to WiFi with RFID off. After WiFi connected, turn on RFID. If disconnected, turn RFID off before reconnecting WiFi.
Or use a power supply capable of supplying 5V 1A or more. USB ports on computer usually can only supply 0.5A. Some powered USB hubs can supply more than 0.5A.
true. i will try thx
hello i have tried many configuration and different power supply (i used usb charger for phone), but i did not solve my issue. using this setup partially fix the problem. some time wifi not connect, some other wifi is ok but http get request failed
auto cfg = M5.config();
cfg.serial_baudrate = 115200;
M5Dial.begin(cfg, false, false);
mfrc522.PCD_Init(); // Init MFRC522. 初始化 MFRC522
i used usb charger, any ideas? i can send by email the full project if u want
Sorry, I do not have time to debug.
Turning down or off the display backlight when connecting WiFi might help. The backlight uses lots of current and I think defaults to maximum brightness. After connecting, turn the brightness up as desired.
M5Device.Display.setBrightness(M5_BRIGHTNESS);
ok will try soon. Is there any power supply that u may recommend to solve this issue? better usb or not?. i am a software developer not a electronic engineer regards
Hi, maybe I can be of some help by sharing my experiences using a M5Dial:
I created a project using Arduino IDE v2.3.3 on an MS Windows 11 Pro desktop PC. This project uses the RFID and WiFi functionalities of the M5Dial. WiFi is programmed in such a way that it re-connects when connection has been lost. The RFID TAG I hold a short time in front of the display to put the display to sleep or to awake it again. Power applied via USB or an external power supply: a Raspberry Pi, model P4421, AC adapter giving 8 Volts @ 6 Amps. I have no problems establishing WiFi connection while also using RFID to identfy an RFID TAG card. The brightness of the display I reduced to 50. My eyes appreciate the dimmed brightness, lol. I do experience now and then several types of problems with the display of the M5Dial:
a) The display turns black at unpredictable times;
b) display background changed to white.
The default text color orange had changed into blue;
c) strange artifacts in the display;
d) Text on the display fading out.
For b) note that this happened when the last data sent to the spreadsheet had an f_heap value of 250728 bytes. For c) see: image and short video.
I am investigating a memory leak. In every loop inside loop() the available heap size shrinks about 240 bytes. The contrary also happens: a gain of heap memory size. I seeked help from MS Copilot. That helped. I have set a minimum level. When the available heap memory amount gets below 200000 bytes, the sketch initiates a software reset.
My project is quite heavy on the memory resources. The sketch now has 1122 lines of code and text annotations. It #include's 22 libraries. It updates time from an SNTP server at predefined intervals (in this moment 5 minutes. In future once in an hour). At the SNTP time sync moments the M5Dial sends a "beep command", a digital impulse, to a M5Stack AtomEcho device (because, I think, it has a better speaker than the M5Dial). The beep command is only send when the display is in state "awake". So, during night hours, I put the display to sleep and I have no "noise" from beeps, lol. At the time sync moments the sketch sends predefined data to a Google Sheets spreadsheet. Reason: I wanted to get certain data to investigate the memory leak(s). To preserve memory my project uses the possibility to declare variables static; put variables in PROGMEM. Other methods with character strings is the use of re-using predefined buffers that only are declared once. Further using const when declaring certain variables and using the F-macro in Serial.print() statements.
I published my project as a repo here in Github. See: repo.