Hi Guys,
I have the problem on board ESP8266 WEMOS D1 R1 with module P10 LED.
after upload completed and run about one minutes, the found error CUT HERE FOR EXCEPTION DECODER see below picture. you can copy paste my code on below.
could you help me? i'm appreciate who is help me. Thanks
#include "NTPClient.h"
#include "ESP8266WiFi.h"
#include "WiFiUdp.h"
#include "HJS589.h"
#include <ESP8266WebServer.h>
#include "fonts/Mono5x7.h"
#include "fonts/bmz15x32.h"
#include "fonts/bmz10x16.h"
#include "fonts/angka6x13.h"
#include "fonts/TimesNewRoman12.h"
#include "fonts/ElektronMart6x8.h"
// SETUP DMD HJS589
#define DispS_WIDE 2
#define DispS_HIGH 1
HJS589 Disp(DispS_WIDE, DispS_HIGH); // Jumlah Panel P10 yang digunakan (KOLOM,BARIS)
// SETUP region sd card
#include <SPI.h>
#include <SD.h>
File root;
const int chipSelect = 2; // change ss spi to D9 wemos d1 R1
// end region
// SETUP RTC
#include <RTClib.h>
#include <Wire.h>
#include <Time.h>
#include <TimeLib.h>
RTC_DS3231 rtc;
// end region RTC
// SETUP JSON
#include <ArduinoJson.h>
File myFile;
// end JSON
ESP8266WebServer server(80);
static char *nama[] = { "Test" };
uint8_t tampilanjam;
// HJS589 P10 FUNGSI TAMBAHAN UNTUK NODEMCU ESP8266
void ICACHE_RAM_ATTR refresh() {
Disp.refresh();
timer0_write(ESP.getCycleCount() + 80000);
}
void Disp_init() {
Disp.start();
noInterrupts();
timer0_isr_init();
timer0_attachInterrupt(refresh);
interrupts();
Disp.clear();
}
// Global variable
const char *MESSAGE = "A";
int hh, mm, ss;
long nowMillis;
const char *ssid = "AR Project";
const char *password = "987987987987";
const long utcOffsetInSeconds = 25200;
char daysOfTheWeeks[7][12] = { "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" };
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "asia.pool.ntp.org", utcOffsetInSeconds);
void setup() {
server.begin();
Serial.begin(115200);
SetupSdCard();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
timeClient.begin();
// DMD
Disp_init();
Disp.setBrightness(50);
Disp.setFont(Mono5x7);
Disp.drawText(0, 0, "Connecting.");
delay(500);
Disp.drawText(0, 0, "Connecting..");
delay(500);
Disp.drawText(0, 0, "Connecting...");
delay(500);
Disp.drawText(0, 0, "Connecting....!");
delay(500);
Disp.clear();
SetupRTC();
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) {
server.handleClient();
// TeksJalanNama();
// delay(10000);
RunningTextLeftoRight(0, 10);
time_t TimeRTC = LoopRTC();
Serial.println(1);
}
}
void RunningTextLeftoRight(long from, long to) {
for (int i = from; i <= to; i++) {
Disp.setFont(Mono5x7);
Disp.drawText(0, 0, MESSAGE);
Disp.drawText(i, 8, "B");
delayInLoop(200);
Disp.clear();
TampilanJamP10();
}
}
void TampilanJamP10() {
timeClient.update();
hh = timeClient.getHours();
mm = timeClient.getMinutes();
ss = timeClient.getSeconds();
// Serial.print(daysOfTheWeek[timeClient.getDay()]);
// Serial.print(", ");
// Serial.print(hh);
// Serial.print(":");
// Serial.print(mm);
// Serial.print(":");
// Serial.println(ss);
char BuffH1[20];
char BuffH2[20];
char BuffM1[20];
char BuffM2[20];
char BuffD1[20];
char BuffD2[20];
int s1, s2, m1, m2, h1, h2;
s1 = ss % 10 / 1;
s2 = ss % 100 / 10;
m1 = mm % 10 / 1;
m2 = mm % 100 / 10;
h1 = hh % 10 / 1;
h2 = hh % 100 / 10;
sprintf(BuffD1, "%.1d", s1);
sprintf(BuffD2, "%.1d", s2);
sprintf(BuffM1, "%.1d", m1);
sprintf(BuffM2, "%.1d", m2);
sprintf(BuffH1, "%.1d", h1);
sprintf(BuffH2, "%.1d", h2);
Disp.setFont(TimesNewRoman12);
Disp.drawText(93, 0, BuffH2);
Disp.drawText(100, 0, BuffH1);
Disp.drawText(109, 0, ":");
Disp.drawText(112, 0, BuffM2);
Disp.drawText(120, 0, BuffM1);
// Disp.drawText(86, 0, BuffD2);
// Disp.drawText(98, 0, BuffD1);
// Disp.drawCircle(47, 3, 2);
// Disp.drawCircle(47, 12, 2);
// Disp.drawCircle(80, 3, 2);
// Disp.drawCircle(80, 12, 2);
// Disp.drawCircle(47, 3, 1);
// Disp.drawCircle(47, 12, 1);
// Disp.drawCircle(80, 3, 1);
// Disp.drawCircle(80, 12, 1);
// Disp.drawCircle(47, 3, 0);
// Disp.drawCircle(47, 12, 0);
// Disp.drawCircle(80, 3, 0);
// Disp.drawCircle(80, 12, 0);
// Disp.drawLine(0, 0, 0, 15, 1);
// Disp.drawLine(15, 0, 15, 15, 1);
// Disp.drawLine(0, 0, 15, 0, 1);
// Disp.drawLine(0, 15, 15, 15, 1);
//
// Disp.drawLine(2, 2, 4, 4, 1);
// Disp.drawLine(4, 2, 2, 4, 1);
//
// Disp.drawLine(11, 2, 13, 4, 1);
// Disp.drawLine(13, 2, 11, 4, 1);
//
// Disp.drawLine(2, 11, 4, 13, 1);
// Disp.drawLine(4, 11, 2, 13, 1);
//
// Disp.drawLine(11, 11, 13, 13, 1);
// Disp.drawLine(13, 11, 11, 13, 1);
//
// Disp.drawLine(6, 6, 9, 9, 1);
// Disp.drawLine(6, 9, 9, 6, 1);
//
// Disp.drawLine(112, 0, 112, 15, 1);
// Disp.drawLine(127, 0, 127, 15, 1);
// Disp.drawLine(112, 0, 127, 0, 1);
// Disp.drawLine(112, 15, 127, 15, 1);
//
// Disp.drawLine(114, 2, 116, 4, 1);
// Disp.drawLine(116, 2, 114, 4, 1);
//
// Disp.drawLine(123, 2, 125, 4, 1);
// Disp.drawLine(125, 2, 123, 4, 1);
//
// Disp.drawLine(114, 11, 116, 13, 1);
// Disp.drawLine(116, 11, 114, 13, 1);
//
// Disp.drawLine(123, 11, 125, 13, 1);
// Disp.drawLine(125, 11, 123, 13, 1);
//
// Disp.drawLine(118, 6, 121, 9, 1);
// Disp.drawLine(118, 9, 121, 6, 1);
}
void SetupRTC() {
Wire.begin(4, 5); // Setting wire (5 untuk SDA dan 4 untuk SCL)
rtc.begin();
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Setting Time
// Kalian dapat menambahkan bagian dibawah ini untuk set manual jam
// rtc.adjust(DateTime(2024, 3, 12, 17, 34, 0));
}
void SetupSdCard() {
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
loadDataSD();
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (!entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.print(entry.size(), DEC);
time_t cr = entry.getCreationTime();
time_t lw = entry.getLastWrite();
struct tm *tmstruct = localtime(&cr);
Serial.printf("\tCREATION: %d-%02d-%02d %02d:%02d:%02d", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
tmstruct = localtime(&lw);
Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
}
entry.close();
}
}
String getValue(String data, char separator, int index) {
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
void loadDataSD() {
JsonObject obj;
DynamicJsonDocument doc(8192);
File file = SD.open("Test1.txt");
if (!file) {
Serial.println(F("Failed to create file, probably not exists"));
Serial.println(F("Create an empty one!"));
obj = doc.to<JsonObject>();
} else {
// Extract each characters by one by one
// while (file.available()) {
// Serial.print((char) file.read());
// }
// Serial.println();
DeserializationError error = deserializeJson(doc, file);
if (error) {
Serial.println(F("Error parsing JSON "));
Serial.println(error.c_str());
} else {
Serial.println(F("No error "));
obj = doc["data"].as<JsonObject>();
for (JsonPair data_item : obj) {
const char *data_item_key = data_item.key().c_str(); // "2024-03-01", "2024-03-02", "2024-03-03", ...
const char *data_item_value_tanggal = data_item.value()["tanggal"]; // "Jumat, 01/03/2024", "Sabtu, ...
const char *data_item_value_imsak = data_item.value()["imsak"]; // "04:34", "04:34", "04:34", "04:34", ...
const char *data_item_value_subuh = data_item.value()["subuh"]; // "04:44", "04:44", "04:44", "04:44", ...
const char *data_item_value_terbit = data_item.value()["terbit"]; // "05:56", "05:56", "05:56", "05:56", ...
const char *data_item_value_dhuha = data_item.value()["dhuha"]; // "06:24", "06:24", "06:24", "06:24", ...
const char *data_item_value_dzuhur = data_item.value()["dzuhur"]; // "12:10", "12:10", "12:09", "12:09", ...
const char *data_item_value_ashar = data_item.value()["ashar"]; // "15:12", "15:11", "15:10", "15:09", ...
const char *data_item_value_maghrib = data_item.value()["maghrib"]; // "18:16", "18:16", "18:15", ...
const char *data_item_value_isya = data_item.value()["isya"];
// Serial.println(data_item_key);
// Serial.println(data_item_value_tanggal);
// Serial.println(data_item_value_imsak);
// Serial.println(data_item_value_subuh);
// Serial.println(data_item_value_terbit);
// Serial.println(data_item_value_dhuha);
// Serial.println(data_item_value_dzuhur);
// Serial.println(data_item_value_ashar);
// Serial.println(data_item_value_maghrib);
// Serial.println(data_item_value_isya);
}
}
}
// Close the file
file.close();
// String Tahun = getValue(data_item_key, '-', 1);
// String Bln = getValue(data_item_key, '-', 2);
// String Tanggal = getValue(data_item_key, '-', 3);
// Serial.println(Tahun);
// Serial.println(Bln);
// Serial.println(Tanggal);
}
time_t tmConvert_t(int YYYY, byte MM, byte DD, byte hh, byte mm, byte ss) {
tmElements_t tmSet;
tmSet.Year = YYYY - 1970;
tmSet.Month = MM;
tmSet.Day = DD;
tmSet.Hour = hh;
tmSet.Minute = mm;
tmSet.Second = ss;
return makeTime(tmSet);
}
time_t LoopRTC() {
DateTime now = rtc.now();
// Serial.print("Hari : ");
// Serial.println(daysOfTheWeeks[now.dayOfTheWeek()]);
// Serial.print("Tanggal : ");
// String Date = String(now.year()) + "-" + String(now.month()) + "-" + String(now.day());
// Serial.print(Date);
// Serial.print("Jam : ");
// Serial.print(now.hour()); //Menampilkan Jam
// Serial.print(":");
// Serial.print(now.minute()); //Menampilkan Menit
// Serial.print(":");
// Serial.print(now.second()); //Menampilkan Detik
// Serial.println();
time_t timeRTC = tmConvert_t(now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second());
return timeRTC;
}
void delayInLoop(long seconds) {
unsigned long start = millis();
while (millis() - start < seconds) {
yield();
}
}
void textCenter(int y, String Msg) {
int center = int((Disp.width() - Disp.textWidth(Msg)) / 2);
Disp.drawText(center, y, Msg);
}
void TeksJalanNama() {
static uint32_t pM;
static uint32_t x;
static uint32_t Speed = 50;
int width = Disp.width();
Disp.setFont(ElektronMart6x8);
textCenter(0, "#");
Disp.drawRect(0, 6, Disp.width(), 6, 1, 1);
int fullScroll = Disp.textWidth(nama[0]) + width;
if ((millis() - pM) > Speed) {
pM = millis();
if (x < fullScroll) {
++x;
} else {
x = 0;
Disp.clear();
tampilanjam = 3;
}
Disp.drawText(width - x, 8, nama[0]);
}
}