@johnwasser this worked, the 10mhz shows in 4800bud rate. thanks
but i am getting this error or somthing
UP_BTN
CPU Freq = 80 MHz
XTAL Freq = 40 MHz
APB Freq = 80000000 Hz
1
E (152241) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (152241) task_wdt: - IDLE (CPU 0)
E (152241) task_wdt: Tasks currently running:
E (152241) task_wdt: CPU 0: loopTask
Here is the full code. before I just included that is related to the topic
// firmware V1.5 for mutantW v1
// Install this libs before building the firmware
#include <Adafruit_ST7789.h>
#include <SPI.h>
#include <WiFi.h>
#include <esp_now.h>
#include "time.h"
// Set the hotspot pass you will use to get the time from the internet
const char* ssid = "DESKTOP";
const char* password = "84r19+H8";
// You can change the gmtOffset_sec to set your local time
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = -14400;
const int daylightOffset_sec = 0;
// For LCD
#define TFT_CS 2
#define TFT_RST 10
#define TFT_DC 0
#define TFT_MOSI 18 // Data out
#define TFT_SCLK 19 // Clock out
// For buttons and others
const int LITE = 6;
const int UP = 1;
const int DOWN = 3;
const int VIBRATION = 7;
// For LCD
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
// For buttons and others
int touchState = 1;
static bool upState = 0;
static bool downState = 1;
static uint16_t powered_on = 10000;
// For Display turn off
unsigned long DELAY_TIME = 10000; // 10 sec
unsigned long delayStart = 0; // the time the delay started
static void notification_Vibration(void)
{
Serial.println("notification_Buzzer");
digitalWrite(VIBRATION, HIGH);
delay(1000);
digitalWrite(VIBRATION, LOW);
delay(800);
digitalWrite(VIBRATION, HIGH);
delay(1000);
digitalWrite(VIBRATION, LOW);
}
void watchFace() {
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
tft.setCursor(80, 30);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(13.5);
tft.println(&timeinfo, "%H");
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(13.5);
tft.println(&timeinfo, ":%M");
}
void secondFace() {
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
tft.setCursor(0, 30);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(2);
tft.println(&timeinfo, "%A");
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
tft.println(&timeinfo, "%B");
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(3);
tft.println(&timeinfo, "%d");
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.println(&timeinfo, "%Y");
tft.setTextSize(3);
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(5);
tft.println(&timeinfo, "%H:%M:%S");
tft.setTextColor(ST77XX_BLUE);
tft.setTextSize(4);
// tft.println("Voltage= ");
// tft.println(value);
}
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
char a[32];
char b[32];
} struct_message;
// Create a struct_message called myData
struct_message myData;
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
Serial.print("Bytes received: ");
Serial.println(len);
Serial.print("Char: ");
Serial.println(myData.a);
Serial.print("Char: ");
Serial.println(myData.b);
delayStart = millis();
turnDisplayON();
notificationFace();
// notification_Vibration();
downState =1;
}
void notificationFace() {
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
tft.setCursor(10, 30);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_BLUE);
tft.setTextSize(2);
tft.println(&timeinfo, "%H:%M:%S");
tft.setTextColor(ST77XX_RED);
tft.setTextSize(2);
tft.println( myData.a);
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
tft.println( myData.b);
}
void setupWIFITime(){
tft.setCursor(0, 30);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(1);
// Connect to Wi-Fi
Serial.print("Connecting to ");
tft.println("Connecting to ");
tft.println(ssid);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
tft.print(".");
}
Serial.println("");
tft.println("");
tft.println("WiFi connected.");
Serial.println("WiFi connected.");
// Init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
watchFace();
//disconnect WiFi as it's no longer needed
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
}
static void turnDisplayON(void)
{
if (!digitalRead(LITE)) {
digitalWrite(LITE, HIGH);
}
}
void CPUinfo(void) {
uint32_t Freq = 0;
Freq = getCpuFrequencyMhz();
Serial.print("CPU Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getXtalFrequencyMhz();
Serial.print("XTAL Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getApbFrequency();
Serial.print("APB Freq = ");
Serial.print(Freq);
Serial.println(" Hz");
}
void setup(void) {
Serial.begin(38400);
delayStart = millis();
pinMode(UP, INPUT_PULLUP);
pinMode(DOWN, INPUT_PULLUP);
pinMode(LITE, OUTPUT);
pinMode(VIBRATION, OUTPUT);
// Set Switch State
digitalWrite(LITE, HIGH);
tft.init(240, 280); // Init ST7789 240x240
tft.setTextWrap(false);
tft.fillScreen(ST77XX_BLACK);
setupWIFITime();
//----------------------------------------------------------------------------
// For reciving notification
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
/* power off the display after 6s */
if ((millis() - delayStart) >= DELAY_TIME) {
digitalWrite(LITE, LOW);
upState =1;
downState=1;
setCpuFrequencyMhz(10);
}
if (!digitalRead(UP)) {
setCpuFrequencyMhz(80);
Serial.println("UP_BTN");
CPUinfo();
delayStart = millis();
turnDisplayON();
if (upState == 1){
Serial.println("1");
upState =0;
watchFace();
delay(500);
} else{
upState =1;
digitalWrite(LITE, LOW);
Serial.println("0");
delay(500);
}
}
if (!digitalRead(DOWN)) {
setCpuFrequencyMhz(80);
Serial.println("UP_DOWN");
CPUinfo();
delayStart = millis();
turnDisplayON();
if (downState == 1){
Serial.println("1");
downState =0;
secondFace();
delay(500);
} else{
downState =1;
notificationFace();
Serial.println("0");
delay(500);
}
}
}