新闻中心

EEPW首页>嵌入式系统>设计应用> 采用ESP8266的创意时钟摆件

采用ESP8266的创意时钟摆件

作者: 时间:2024-01-29 来源:趣味硬件 收藏

这个模块在近两年来芯片大幅度涨价的趋势下依然能够保持十几块钱一片,简直是DIY的利器,其基本功能基本能够满足小型DIY应用,速度也是杠杠的,就是对于我来说开发有点小麻烦了点,不太习惯Arduino IDE、Lua脚本等方式写代码,所以我选择的是SDK方式,可能是习惯了的方式吧。

本文引用地址://m.amcfsurvey.com/article/202401/455179.htm

一、硬件部分

1.核心部分模块使用,其基本的最小系统如下所示。


2.USB转串口部分,这里采用的电路可以实现自动下载,我们知道,平时我们下载的固件的时候都是需要将GPIO0引脚拉低后再上电,才能进入下载模式,这个一键下载电路就完美解决了这个问题,非常方便。


3.电源部分使用5V转3.3V的芯片1117-3.3芯片,使用两片,和LED灯分开供电,因为LED灯比较多,怕电流太大了会导致wifi连接不稳定。



4.LED驱动,这里使用TM1637数码管专用驱动芯片来驱动LED灯,它使用IIC通信,非常方便。再加上MOS管增强驱动,使LED灯亮度更好。




5.LED矩阵组成4个8段数码管和两个点



6.画好的PCB如下:



二、软件部分

软件使用RTOS的SDK方式,其实这个也很简单,历程非常多。下面附上最主要的几个函数

1.WiFi连接

/*wifi参数设置*/user_set_station_config(void) { wifi_set_opmode(STATION_MODE); //设置为STATION MODE strcpy(station_cfg.ssid, ssid); //ssid名称 strcpy(station_cfg.password, password); //密码 wifi_station_set_config(&station_cfg); //设置WIFI帐号和密码}

2.网络时间获取

LOCAL unsigned char time_buf[8]; //空年月日时分秒周LOCAL void ICACHE_FLASH_ATTR SyncNetTimeCallBack(void) { //获取时间戳 uint32 ts = sntp_get_current_timestamp(); unsigned char i, tmp; if (ts != 0) { os_timer_disarm(&getNetSyncTimer); os_delay_us(60000); //延时等待稳定 os_delay_us(60000); //延时等待稳定 //处理时间戳,返回具体的时间 char *pDate = (void *) sntp_get_real_time(ts); data = sntp_get_time_change(pDate); os_printf("20%x_%x_%x_%x:%x:%x_%xn",data.year,data.month,data.day,data.hour,data.minute,data.second,data.week); time_buf1[1] = data.year; time_buf1[2] = data.month; time_buf1[3] = data.day; time_buf1[4] = data.hour; time_buf1[5] = data.minute; time_buf1[6] = data.second; //time_buf1[4]/16*10+time_buf1[4]%16; os_printf("%d:%d:%d rn", time_buf1[4]/16*10+time_buf1[4]%16, time_buf1[5]/16*10+time_buf1[5]%16, time_buf1[6]/16*10+time_buf1[6]%16); sec=time_buf1[6]/16*10+time_buf1[6]%16; min=time_buf1[5]/16*10+time_buf1[5]%16; hour=time_buf1[4]/16*10+time_buf1[4]%16; os_timer_arm(&second_timer, 1000, 1); //使能毫秒定时器 } } void ICACHE_FLASH_ATTR wifi_event_handler_cb(System_Event_t *event) { //开始网络授时 sntp_setservername(0, "time1.aliyun.com"); sntp_setservername(1, "time2.aliyun.com"); sntp_setservername(2, "time3.aliyun.com"); // set sntp server after got ip address sntp_init(); os_timer_disarm(&getNetSyncTimer); os_timer_setfn(&getNetSyncTimer, (os_timer_func_t *) SyncNetTimeCallBack,NULL); os_timer_arm(&getNetSyncTimer, 1000, 1); }

3.两个任务,一个走时,一个检测光敏电阻,晚上的时候就熄灭掉,白天的时候亮起。具体的任务主体就是设一个1秒的定时器来走时,然后间隔5分钟重新从网络获取时间,这样即使是1秒的定时器不准影响也很小,因为每五分钟会修正一次。

xTaskCreate(time_update, "time_update", 1024, NULL, 11, NULL); xTaskCreate(time_update1, "time_update1", 1024, NULL, 10, NULL);

三、实物如下




放桌子上拍摄看着效果不太好。




评论


相关推荐

技术专区

关闭