#1 13-11-2022 20:34:35

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

NTP часы с VGA монитором и голосом Google TTS.

Убрал прогноз погоды, не стабильно это работает. В часы добавил время включения/выключения часов, чтоб спать не мешали.

#include "fabgl.h"
#include "Arduino.h"
#define FABGL_FONT_INCLUDE_DEFINITION
#include "segment140.h"
#include <WiFi.h>
#include "time.h"
const char* ssid       = "**********";
const char* password   = "********";
const char* ntpServer = "pool.ntp.org";
#define TIME_OFFSET 0UL * 3600UL // UTC + 6 hour
//const long  gmtOffset_sec = 21600; // GMT+6 летнее время
const long  gmtOffset_sec = 25200; // GMT+7 зимнее время
const int   daylightOffset_sec = 3600;
fabgl::VGAController DisplayController;
fabgl::Canvas canvas(&DisplayController);
//////////////////////////////////////
tm timeinfo;
time_t now;
int aa=1;
float i=0;
unsigned long timer1; 
char DATopW[30]="";
char date_buf[80];
 char dayweek[2];
 char MES[5];
 char DAY[5];
char CHAS[5];
 char MIN[5];
byte noch=0;
long unsigned lastNTPtime;
byte DayOfWeek;
/////////////////////////
void printDisplay(){
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;  }
  strftime(date_buf,80,"%A,%B%d %Y", &timeinfo);
  canvas.setPenColor(Color::BrightGreen);
  canvas.setGlyphOptions(GlyphOptions().FillBackground(true).DoubleWidth(0));
  canvas.selectFont(&fabgl::FONT_Seven_Segment140);
  canvas.drawTextFmt(20, -20, "%02d:%02d  ", timeinfo.tm_hour, timeinfo.tm_min);
  canvas.setGlyphOptions(GlyphOptions().FillBackground(false).DoubleWidth(0));
  canvas.setPenColor(Color::BrightYellow);
  canvas.drawTextFmt(185, 80, "%s", DAY);  
  canvas.selectFont(&fabgl::FONT_8x8); 
  canvas.setGlyphOptions(GlyphOptions().FillBackground(true).DoubleWidth(1));
  
  if (String(dayweek)=="1") canvas.drawTextFmt(20, 102,"%s",ru("Понедельник"));
  if (String(dayweek)=="2") canvas.drawTextFmt(20, 102,"%s",ru("Вторник"));
  if (String(dayweek)=="3") canvas.drawTextFmt(20, 102,"%s",ru("Среда"));
  if (String(dayweek)=="4") canvas.drawTextFmt(20, 102,"%s",ru("Четверг"));
  if (String(dayweek)=="5") canvas.drawTextFmt(20, 102,"%s",ru("Пятница"));
  if (String(dayweek)=="6") canvas.drawTextFmt(20, 102,"%s",ru("Суббота"));
  if (String(dayweek)=="0") canvas.drawTextFmt(20, 102,"%s",ru("Воскресенье"));
  
  if (String(MES)=="1") canvas.drawTextFmt(20, 110,"%s",ru("Январь"));
  if (String(MES)=="2") canvas.drawTextFmt(20, 110,"%s",ru("Февраль"));
  if (String(MES)=="3") canvas.drawTextFmt(20, 110,"%s",ru("Март"));
  if (String(MES)=="4") canvas.drawTextFmt(20, 110,"%s",ru("Апрель"));
  if (String(MES)=="5") canvas.drawTextFmt(20, 110,"%s",ru("Май"));
  if (String(MES)=="6") canvas.drawTextFmt(20, 110,"%s",ru("Июнь"));
  if (String(MES)=="7") canvas.drawTextFmt(20, 110,"%s",ru("Июль"));
  if (String(MES)=="8") canvas.drawTextFmt(20, 110,"%s",ru("Август"));
  if (String(MES)=="09") canvas.drawTextFmt(20, 110,"%s",ru("Сентябрь "));
  if (String(MES)=="10") canvas.drawTextFmt(20, 110,"%s",ru("Октябрь"));
  if (String(MES)=="11") canvas.drawTextFmt(20, 110,"%s",ru("Ноябрь"));
  if (String(MES)=="12") canvas.drawTextFmt(20, 110,"%s",ru("Декабрь"));
}
void printLocalTime()
{ struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");  
  strftime(date_buf,80,"%A,%B%d %Y", &timeinfo);
  strftime(dayweek,2,"%w", &timeinfo);
  strftime(MES,5,"%m", &timeinfo);
  strftime(DAY,5,"%d", &timeinfo);
  strftime(CHAS,2,"%H", &timeinfo);
  strftime(MIN,2,"%M", &timeinfo);
 if(String(timeinfo.tm_hour)=="0" and noch==0){noch=1;}//время выключения монитора
 if (String(timeinfo.tm_hour)=="7" and noch!=0){noch=0;}//время включения монитора
 if (String(timeinfo.tm_sec)=="0" and noch==0){printDisplay();}
 if (noch==1){ canvas.clear(); noch=2;}
}
//////////////////////////////////////
// Начало функции обработки кириллических символов
#define maxString 40
char target[maxString + 1] = "";
char *ru(char *source)
{ int i,j,k;
  unsigned char n;
  char m[2] = { '0', '\0' };
  strcpy(target, ""); k = strlen(source); i = j = 0;
  while (i < k) {
    n = source[i]; i++;
    if (n >= 0xC0) {
      switch (n) {
        case 0xD0: {
          n = source[i]; i++;
          if (n == 0x81) { n = 0xA8; break; }
          if (n >= 0x90 && n <= 0xBF) n = n + 0x30;
          break;
        }
        case 0xD1: {
          n = source[i]; i++;
          if (n == 0x91) { n = 0xB8; break; }
          if (n >= 0x80 && n <= 0x8F) n = n + 0x70;
          break;
        }
      }
    }
    m[0] = n; strcat(target, m);
    j++; if (j >= maxString) break;
  }
  return target;
}
// Конец функции обработки кириллических символов.
void setup()
{    
  Serial.begin(115200);
  DisplayController.begin();
  DisplayController.setResolution(VGA_320x200_75Hz);
  canvas.setBrushColor(RGB888(0, 0, 0));
  canvas.setGlyphOptions(GlyphOptions().FillBackground(true).DoubleWidth(0));
  canvas.setPenColor(Color::BrightGreen);
  canvas.clear();
  canvas.selectFont(&fabgl::FONT_8x8); 
 Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
   canvas.drawTextFmt(10, 10,"%s","WiFi - ");
      canvas.drawTextFmt(50+10*aa, 10,"%s",".");
      aa++;
      Serial.print(".");
  } Serial.println(" CONNECTED");
  canvas.drawTextFmt(10, 10,"%s","WiFi - CONNECTED");
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  delay(1000);
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
canvas.clear();
printLocalTime();
//printDisplay();
}
void loop()
{
 if (millis() - lastNTPtime >= 1000)
  {
 lastNTPtime= millis();
  printLocalTime(); 
  }
}

Не в сети

#2 13-11-2022 20:35:50

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

Шрифты семисегментных часов, стырил тут.
https://github.com/maksimKorzh/esp32-fullscreen-clock

Не в сети

#3 13-11-2022 20:37:53

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

16683466416365778255484271512789.jpg

Не в сети

#4 08-12-2022 22:10:23

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

К часам добавил ЦАП  PCM5102 и речевой процесс от Google TTS.
Часы сообщают время каждый час голосом, кроме времени ночи/молчания.

#include "Audio.h"
// Digital I/O used
#define I2S_DOUT      12
#define I2S_BCLK      25
#define I2S_LRC       2
Audio audio;
#include "fabgl.h"
#include "Arduino.h"
#define FABGL_FONT_INCLUDE_DEFINITION
#include "segment140.h"
#include <WiFi.h>
#include "time.h"
const char* ssid       = "*****";
const char* password   = "*****";
const char* ntpServer = "pool.ntp.org";
#define TIME_OFFSET 0UL * 3600UL // UTC + 6 hour
//const long  gmtOffset_sec = 21600; // GMT+6 летнее время
const long  gmtOffset_sec = 25200; // GMT+7 зимнее время
const int   daylightOffset_sec = 3600;
fabgl::VGAController DisplayController;
fabgl::Canvas canvas(&DisplayController);
//////////////////////////////////////
tm timeinfo;
time_t now;
int aa=1;
float i=0;
unsigned long timer1; 
char DATopW[30]="";
char date_buf[80];
 char dayweek[2];
 char MES[5];
 char DAY[5];
char CHAS[5];
 char MIN[5];
byte noch=0;
long unsigned lastNTPtime;
byte DayOfWeek;
/////////////////////////
void printDisplay(){
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;  }
  strftime(date_buf,80,"%A,%B%d %Y", &timeinfo);
  canvas.setPenColor(Color::BrightGreen);
  canvas.setGlyphOptions(GlyphOptions().FillBackground(true).DoubleWidth(0));
  canvas.selectFont(&fabgl::FONT_Seven_Segment140);
  canvas.drawTextFmt(20, -20, "%02d:%02d  ", timeinfo.tm_hour, timeinfo.tm_min);
  canvas.setGlyphOptions(GlyphOptions().FillBackground(false).DoubleWidth(0));
  canvas.setPenColor(Color::BrightYellow);
  canvas.drawTextFmt(185, 80, "%s", DAY);  
  canvas.selectFont(&fabgl::FONT_8x8); 
  canvas.setGlyphOptions(GlyphOptions().FillBackground(true).DoubleWidth(1));
  
  if (String(dayweek)=="1") canvas.drawTextFmt(20, 102,"%s",ru("Понедельник"));
  if (String(dayweek)=="2") canvas.drawTextFmt(20, 102,"%s",ru("Вторник"));
  if (String(dayweek)=="3") canvas.drawTextFmt(20, 102,"%s",ru("Среда"));
  if (String(dayweek)=="4") canvas.drawTextFmt(20, 102,"%s",ru("Четверг"));
  if (String(dayweek)=="5") canvas.drawTextFmt(20, 102,"%s",ru("Пятница"));
  if (String(dayweek)=="6") canvas.drawTextFmt(20, 102,"%s",ru("Суббота"));
  if (String(dayweek)=="0") canvas.drawTextFmt(20, 102,"%s",ru("Воскресенье"));
  
  if (String(MES)=="1") canvas.drawTextFmt(20, 110,"%s",ru("Январь"));
  if (String(MES)=="2") canvas.drawTextFmt(20, 110,"%s",ru("Февраль"));
  if (String(MES)=="3") canvas.drawTextFmt(20, 110,"%s",ru("Март"));
  if (String(MES)=="4") canvas.drawTextFmt(20, 110,"%s",ru("Апрель"));
  if (String(MES)=="5") canvas.drawTextFmt(20, 110,"%s",ru("Май"));
  if (String(MES)=="6") canvas.drawTextFmt(20, 110,"%s",ru("Июнь"));
  if (String(MES)=="7") canvas.drawTextFmt(20, 110,"%s",ru("Июль"));
  if (String(MES)=="8") canvas.drawTextFmt(20, 110,"%s",ru("Август"));
  if (String(MES)=="09") canvas.drawTextFmt(20, 110,"%s",ru("Сентябрь "));
  if (String(MES)=="10") canvas.drawTextFmt(20, 110,"%s",ru("Октябрь"));
  if (String(MES)=="11") canvas.drawTextFmt(20, 110,"%s",ru("Ноябрь"));
  if (String(MES)=="12") canvas.drawTextFmt(20, 110,"%s",ru("Декабрь"));
}
void printLocalTime()
{ struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");  
  strftime(date_buf,80,"%A,%B%d %Y", &timeinfo);
  strftime(dayweek,2,"%w", &timeinfo);
  strftime(MES,5,"%m", &timeinfo);
  strftime(DAY,5,"%d", &timeinfo);
  strftime(CHAS,2,"%H", &timeinfo);
  strftime(MIN,2,"%M", &timeinfo);
 if(String(timeinfo.tm_hour)=="0" and noch==0){noch=1;}//время выключения монитора
 if (String(timeinfo.tm_hour)=="7" and noch!=0){noch=0;}//время включения монитора
 if (String(timeinfo.tm_sec)=="0" and noch==0){printDisplay();
 }
if (String(timeinfo.tm_sec)=="1" and String(timeinfo.tm_min)=="0" and noch==0){
  if (String(timeinfo.tm_hour)=="0") audio.connecttospeech("Время Ноль часов.", "ru"); 
  if (String(timeinfo.tm_hour)=="1") audio.connecttospeech("Время Один час.", "ru"); 
  if (String(timeinfo.tm_hour)=="2") audio.connecttospeech("Время Два часа.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="3") audio.connecttospeech("Время Три часа.", "ru"); 
  if (String(timeinfo.tm_hour)=="4") audio.connecttospeech("Время Четыре часа.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="5") audio.connecttospeech("Время Пять часаов.", "ru"); 
  if (String(timeinfo.tm_hour)=="6") audio.connecttospeech("Время Шесть часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="7") audio.connecttospeech("Время Семь часов.", "ru"); 
  if (String(timeinfo.tm_hour)=="8") audio.connecttospeech("Время Восемь часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="9") audio.connecttospeech("Время Девять часов.", "ru"); 
  if (String(timeinfo.tm_hour)=="10") audio.connecttospeech("Время Десять часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="11") audio.connecttospeech("Время Одинадцать часов.", "ru"); 
  if (String(timeinfo.tm_hour)=="12") audio.connecttospeech("Время Двенадцать часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="13") audio.connecttospeech("Время Тринадцать часов.", "ru"); 
  if (String(timeinfo.tm_hour)=="14") audio.connecttospeech("Время Четырнадцать часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="15") audio.connecttospeech("Время Пятнадцать часаов.", "ru"); 
  if (String(timeinfo.tm_hour)=="16") audio.connecttospeech("Время Шестнадцать часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="17") audio.connecttospeech("Время Семнадцать часов.", "ru"); 
  if (String(timeinfo.tm_hour)=="18") audio.connecttospeech("Время Восемьнадцать часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="19") audio.connecttospeech("Время Девятнадцать.", "ru"); 
  if (String(timeinfo.tm_hour)=="20") audio.connecttospeech("Время Двадцать часов.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="21") audio.connecttospeech("Время Двадцать один час.", "ru"); 
  if (String(timeinfo.tm_hour)=="22") audio.connecttospeech("Время Двадцать два часа.", "ru"); // Google TTS 
  if (String(timeinfo.tm_hour)=="23") audio.connecttospeech("Время Двадцать три часа.", "ru"); 
 }
 if (String(timeinfo.tm_sec)=="0" and  String(timeinfo.tm_sec)=="1" and String(timeinfo.tm_sec)=="2" and  String(timeinfo.tm_sec)=="3" and noch==0){//printDisplay();
 
 audio.loop();
 }
 if (noch==1){ canvas.clear(); noch=2;}
}
//////////////////////////////////////
// Начало функции обработки кириллических символов
#define maxString 40
char target[maxString + 1] = "";
char *ru(char *source)
{ int i,j,k;
  unsigned char n;
  char m[2] = { '0', '\0' };
  strcpy(target, ""); k = strlen(source); i = j = 0;
  while (i < k) {
    n = source[i]; i++;
    if (n >= 0xC0) {
      switch (n) {
        case 0xD0: {
          n = source[i]; i++;
          if (n == 0x81) { n = 0xA8; break; }
          if (n >= 0x90 && n <= 0xBF) n = n + 0x30;
          break;
        }
        case 0xD1: {
          n = source[i]; i++;
          if (n == 0x91) { n = 0xB8; break; }
          if (n >= 0x80 && n <= 0x8F) n = n + 0x70;
          break;
        }
      }
    }
    m[0] = n; strcat(target, m);
    j++; if (j >= maxString) break;
  }
  return target;
}
// Конец функции обработки кириллических символов.
void setup()
{    
  Serial.begin(115200);
  DisplayController.begin();
 //DisplayController.setResolution(QVGA_320x240_60Hz);
 DisplayController.setResolution(VGA_320x200_75Hz);
// DisplayController.setResolution(VGA_400x300_60Hz);
  canvas.setBrushColor(RGB888(0, 0, 0));
  canvas.setGlyphOptions(GlyphOptions().FillBackground(true).DoubleWidth(0));
  canvas.setPenColor(Color::BrightGreen);
  canvas.clear();
  canvas.selectFont(&fabgl::FONT_8x8); 
 Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
   canvas.drawTextFmt(10, 10,"%s","WiFi - ");
      canvas.drawTextFmt(50+10*aa, 10,"%s",".");
      aa++;
      Serial.print(".");
  } Serial.println(" CONNECTED");
  canvas.drawTextFmt(10, 10,"%s","WiFi - CONNECTED");
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  delay(1000);
 // WiFi.disconnect(true);
 // WiFi.mode(WIFI_OFF);
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
    audio.setVolume(21); // 0...21
    audio.connecttospeech("Соединение с сетью , установленно.", "ru"); // Google TTS 
   //if (WiFi.status() == WL_CONNECTED) audio.loop();
canvas.clear();
printLocalTime();
//printDisplay();
}
void loop()
{
audio.loop();
 if (millis() - lastNTPtime >= 1000)
  {
 lastNTPtime= millis();
  printLocalTime(); 
  }
}
///////////////////////////////////////////////////////
void audio_info(const char *info){
    Serial.print("info        "); Serial.println(info);
}
void audio_id3data(const char *info){  //id3 metadata
    Serial.print("id3data     ");Serial.println(info);
}
void audio_eof_mp3(const char *info){  //end of file
    Serial.print("eof_mp3     ");Serial.println(info);
}
void audio_showstation(const char *info){
    Serial.print("station     ");Serial.println(info);
}
void audio_showstreamtitle(const char *info){
    Serial.print("streamtitle ");Serial.println(info);
}
void audio_bitrate(const char *info){
    Serial.print("bitrate     ");Serial.println(info);
}
void audio_commercial(const char *info){  //duration in sec
    Serial.print("commercial  ");Serial.println(info);
}
void audio_icyurl(const char *info){  //homepage
    Serial.print("icyurl      ");Serial.println(info);
}
void audio_lasthost(const char *info){  //stream URL played
    Serial.print("lasthost    ");Serial.println(info);
}
void audio_eof_speech(const char *info){
    Serial.print("eof_speech  ");Serial.println(info);
}

Не в сети

#5 08-12-2022 23:12:02

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

Схема электрическая принципиальная.

VGA-big-Clock-tts1.gif

Не в сети

#6 08-12-2022 23:17:51

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

Код из поста 4, подразумевает графику 64 бит. На схеме из поста 5, видео работает на 8 бит. Работать будет одинаково. Но, если упростить графику до 8 бит, свободной памяти будет больше.

Не в сети

#7 08-12-2022 23:26:47

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

При настройках видео 64 бит.

fabgl::VGAController DisplayController;
fabgl::Canvas canvas(&DisplayController);

Используем 49% памяти. И 17% динамической памяти.

1670516746623354925915008618301.jpg

Не в сети

#8 08-12-2022 23:41:02

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

Видео 8 бит.
Странно! Памяти свободной не стало больше. Только всё зелёным стало, но это понятно.
16705177205143563576133702495958.jpg

Не в сети

#9 08-12-2022 23:43:28

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: NTP часы с VGA монитором и голосом Google TTS.

16705177813157600650413913154983.jpg

Не в сети

Подвал раздела

Работает на FluxBB (перевод Laravel.ru)