惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Cyberwarzone
Cyberwarzone
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX
博客园_首页
博客园 - 聂微东
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
T
Tenable Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
A
About on SuperTechFans
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
D
Docker
P
Proofpoint News Feed

莫拉维克猫屋

4D Radar - A Novel Sensing Paradigm for 3D Object Detection 粗略的cs231n学习笔记 simulink仿真数字通信系统 基于开源的livego搭建直播服务器 EDA实验二 功能可调综合计时器 EDA实验一 指令运算单元设计——第一次用FPGA开发板 SSM框架:导出数据库内容到Excel表格 Java网络编程-TCP通信 我要这差分放大电路有何用? Hello World
NodeMCU-ESP8266联网获取实时天气并使用lcd1602显示
liuzengyun · 2020-09-13 · via 莫拉维克猫屋

实现效果

image

硬件准备

  • NodeMCU-ESP8266开发板
  • lcd1602显示屏(使用I2C总线)
  • 杜邦线若干
  • 可以联网的WiFi信号

软件环境

  • Arduino IDE
  • 心知天气API(免费版够用)

连线:NodeMCU——I2C

  • GPIO4——SDA
  • GPIO5——SCL
  • VIN——VCC
  • GND——GND

这里这个连线还是很坑的。

供电之所以使用VIN而不使用3.3V,是因为VIN的供电是5V的,3.3V供电也不是不行,但是显示效果不太行,几乎看不清。

另外,之前网上看别人做lcd1602显示,都是连D3、D4两个脚,然后一直不管用,直到忍无可忍查了NodeMCU-ESP8266的管脚功能表,如下:(来源: https://tttapa.github.io/

GPIO Function State Restrictions
0 Boot mode select 3.3V No Hi-Z
1 TX0 - Not usable during Serial transmission
2 Boot mode select TX1 3.3V (boot only) Don’t connect to ground at boot time Sends debug data at boot time
3 RX0 - Not usable during Serial transmission
4 SDA (I²C) - -
5 SCL (I²C) - -
6 - 11 Flash connection x Not usable, and not broken out
12 MISO (SPI) - -
13 MOSI (SPI) - -
14 SCK (SPI) - -
15 SS (SPI) 0V Pull-up resistor not usable
16 Wake up from sleep - No pull-up resistor, but pull-down instead Should be connected to RST to wake up

开发过程

开发之前先去心知天气注册一个账户 ,申请一个免费的API,用来获取实时天气。

引入最基本的ESP8266WiFi库,先连接一个能上网的WiFi,使用ESP8266通过http请求获取信息,几秒钟请求一次,更新信息。返回的是一个JSON字符串,使用ArduinoJson库函数解析JSON,得到需要的具体数据。最后通过LiquidCrystal_I2C库将天气情况显示在LCD1602上。

代码与库

本项目: https://github.com/liuzengyun/esp8266_Weather

ArduinoJSON库: https://github.com/bblanchon/ArduinoJson

LiquidCrystal_I2C库:Arduino IDE中库管理中下载即可。