爱易族 - esp8266
type: channel
link: http://www.yizu.org/tag/esp8266/
items: esp8266+DS1302+LCD1602+DHT11+无源蜂鸣器制作网络时钟升级版
items: esp8266+DS1302+LCD1602制作网络时钟
items: esp8266、Arduino用LCD1602（iic接口）进行显示

esp8266+DS1302+LCD1602+DHT11+无源蜂鸣器制作网络时钟升级版
type: item
date: 2022-05-24T21:04:00+08:00
description: 零零碎碎隔段时间捣鼓一下，历时几个月，终于把网络时钟制作齐了我想要的功能。外观看图。这个闹钟功能比较全面了，采用了D1 mini开发板（esp8266）、LCD1602显示屏、DS1302时钟芯片、DHT11温湿度模块、无源蜂鸣器等配件，Arduino开发，实现的功能列表如下。显示日期、星期、时间和温湿度，外带一个Wifi小图标。可以联网自动对时。断电不影响走时（DS1302）。可设置一路闹钟，通过web页面设置，响铃为两只老虎旋律。可web页面配置wifi，没有设置wifi时自动开启wifi热点，以供手机链接时钟进行配置。两个按钮，一个重启模块，一个清楚WiFi配置信息。下面是进行WiFi设置和闹钟设置的两个网页。程序代码如下：/* ---By www.yizu.org--- Connect D1 mini I2C_LCD 5V VCC GND GND D2 SDA D1 SCL D1 mini DS1302 3V3 VCC GND GND D6 CLK D7 DAT D8 RST */ #include <ESP8266WiFi.h> #include <EEPROM.h> #include <WiFiUdp.h> #include <NTPClient.h> #include <LiquidCrystal_I2C.h> #include <TimeLib.h> #include <Arduino.h> #include <DS1302.h> #include <dht11.h> #include <ESP8266WebServer.h> #include <FS.h> LiquidCrystal_I2C lcd(0x27, 16, 2); int32_t t_xd=0; //定义web服务 ESP8266WebServer server(80); //设置NTPClient #define NTP_OFFSET 60 * 60 * 8 // 时区偏移量 #define NTP_ADDRESS "ntp1.aliyun.com" // NTP服务器 WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, NTP_ADDRESS, NTP_OFFSET); //设置时钟模块 DS1302 rtc(12,13,15); //设置校对时间间隔（单位秒） #define CALIBRATION_INTERVAL 60 unsigned long t_stamp=0; unsigned long t_stamp2=0; //设置蜂鸣器 #define BUZZER_PIN 14 //设置D5脚 #define ALARM_INTERVAL 300 //一个节拍的时间/毫秒 unsigned long b_stamp = 0; unsigned long b_stamp2 = 0; unsigned long duration = 0;//闹铃持续时间 boolean isAlarm=0;//蜂鸣器发声标记 uint8_t tonesTag=0; uint8_t tonesLength=33;//长度 //两只老虎音乐 char toneNotes[] = "cdeccdecefgefggagfecgagfecdgcdgc "; //'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' float beats[] = { 1,1,1,1,1,1,1,1,1,1,2,1,1,2,0.5,0.5,0.5,0.5,1,1,0.5,0.5,0.5,0.5,1,1,1,1,2,1,1,2,4 }; bool ringing=false; //闹钟设置 bool alarm_on=false; int alarm_hour=0; int alarm_min=0; //设置AP账号密码 const char* ssid = "myAP000"; const char* password = "12345678"; //设置温湿度传感器 #define DHT11PIN 2//定义dht11引脚 dht11 myDht; int tem=0;//温度 int hum=0;//湿度 //显示字符 #if defined(ARDUINO) && ARDUINO >= 100 #define printByte(args) write(args); #else #define printByte(args) print(args,BYTE); #endif //要显示的特殊字符 //uint8_t nian[8] = {0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02,…

esp8266+DS1302+LCD1602制作网络时钟
type: item
date: 2021-12-12T21:04:00+08:00
description: 这里的esp8266选用D1 mini开发板，DS1302加I2C转接模块。首先上效果图。接着上代码。/* ---By www.yizu.org--- Connect D1 mini I2C_LCD 5V VCC GND GND D2 SDA D1 SCL D1 mini DS1302 3V3 VCC GND GND D6 CLK D7 DAT D8 RST */ #include <ESP8266WiFi.h> #include <WiFiUdp.h> #include <NTPClient.h> #include <LiquidCrystal_I2C.h> #include <TimeLib.h> #include <Arduino.h> #include <DS1302.h> LiquidCrystal_I2C lcd(0x27, 16, 2); //设置NTPClient #define NTP_OFFSET 60 * 60 * 8 // 时区偏移量 #define NTP_ADDRESS "ntp1.aliyun.com" // NTP服务器 WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, NTP_ADDRESS, NTP_OFFSET); //设置时钟模块 DS1302 rtc(15,13,12); //设置校对时间间隔（单位秒） #define CALIBRATION_INTERVAL 60 unsigned long t_stamp=0; unsigned long t_stamp2=0; //设置WIFI账号密码 const char* ssid = "wifi"; const char* password = "123456789"; //显示字符 #if defined(ARDUINO) && ARDUINO >= 100 #define printByte(args) write(args); #else #define printByte(args) print(args,BYTE); #endif //要显示的特殊字符 //uint8_t nian[8] = {0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02,};//年 //uint8_t yue[8] = {0x0f,0x09,0x0f,0x09,0x0f,0x09,0x0b,0x11,};//月 //uint8_t ri[8] = {0x1F,0x11,0x11,0x1F,0x11,0x11,0x1F,0x00,};//日 uint8_t dian[8] = {0x02,0x05,0x02,0x00,0x00,0x00,0x00,0x00,};//点 uint8_t dianC[8] ={0x00,0x17,0x08,0x08,0x08,0x08,0x07,0x00,};//温度单位 uint8_t wificon[8] ={0x00,0x0E,0x11,0x04,0x0A,0x00,0x04,0x00,};//WIFI链接 uint8_t wificon2[8]={0x00,0x11,0x0A,0x04,0x0A,0x11,0x00,0x00,};//断网 const char * days[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"} ; //连接WIFI void connectToWiFi() { Serial.println(""); Serial.print("Connecting to "); Serial.print(ssid); WiFi.begin(ssid, password); Serial.println(""); Serial.print("Connected to WiFi at "); Serial.print(WiFi.localIP()); Serial.println(""); unsigned int count = 0; while ((count < 10 ) & (WiFi.status() != WL_CONNECTED)) { delay(500); Serial.print("."); count ++; } } //显示WIFI连接状态 void showWifiStatus() { lcd.setCursor(11, 0); if(WiFi.status() == WL_CONNECTED) { lcd.write(byte(5)); } else { lcd.write(byte(6)); } } //校对时间 void correctionTime() …

esp8266、Arduino用LCD1602（iic接口）进行显示
type: item
date: 2021-11-24T20:16:00+08:00
description: 这里用了两个esp8266设备，分别是NodeMCU和Wemos D1 mini两个模块，Arduino设备是Arduino UNO。设备如下图示。三个设备的引脚说明如图，后面连接屏幕要用到。显示设备Lcd1602，能显示两行，每行16个字，后面焊接了IIC接口转接模块(PCA8574)，如图。IIC接口有GND、VCC、SDA、SCL三个接口，分别根据上面的引脚图，找到想要的引脚连接（NodeMcu的SCL与SDA对应引脚D1 D2），由于这个屏幕是5v工作电压，VCC要接5V，NodeMCU没有标识5V引脚，要接Vin。下面是编写代码，都用Arduino IDE进行，要安装LiquidCrystal I2C库，代码如下。#include <Wire.h> #include <LiquidCrystal_I2C.h> // I2C地址, 一般为0x3F, 0x20或0x27 LiquidCrystal_I2C lcd(0x27, 16, 2); int i; char str[16]; void setup(){ lcd.init();//初始化显示屏 lcd.backlight(); // 打开背光 i = 0; strcpy (str,"#"); } void loop(){ lcd.setCursor(0, 0);//设置起始坐标 lcd.print("Hello World!"); lcd.setCursor(0, 1); if(i<16){ i++; lcd.print(str); strcat(str,"#"); }else{ strcpy(str,"#"); i=0; lcd.clear();//清屏 } delay(500); }I2C地址还可以通过写入arduino一段代码,通过串口监视器查询到。// I2C Scanner // Written by Nick Gammon // Date: 20th April 2011 #include <Wire.h> void setup() { Serial.begin (115200); // Leonardo: wait for serial port to connect while (!Serial) { } Serial.println (); Serial.println ("I2C scanner. Scanning ..."); byte count = 0; Wire.begin(); for (byte i = 8; i < 120; i++) { Wire.beginTransmission (i); if (Wire.endTransmission () == 0) { Serial.print ("Found address: "); Serial.print (i, DEC); Serial.print (" (0x"); Serial.print (i, HEX); Serial.println (")"); count++; delay (1); // maybe unneeded? } // end of good response } // end of for loop Serial.println ("Done."); Serial.print ("Found "); Serial.print (count, DEC); Serial.println (" device(s)."); } // end of setup void loop() {}效果如图。