目标:将http://api.open-notify.org/astros.json提供的ISS人员信息通过LCD1602 展示出来
设备:
树莓派3B ×1
LCD1602 ×1
杜邦线 ×16
电位器 ×1
这里编程语言就选Python3了
驱动LCD1602就用我自己编写的库(话说昨天折腾4位总线模式还没有搞好)
LCD1602_Driver_For_Raspberry_Pi_Python <–驱动程序+接线方法都在这里
接好线后如图所示
接下来观察一下这个API返回的JSON数据
接下来就是对照着这个写一个小程序即可
import requests
import json
import time
from lcd1602 import LCD1602
lcd = LCD1602()
lcd.Write_String(1,1,"LCD1602 Init OK!")
time.sleep(3)
while(True):
url = "http://api.open-notify.org/astros.json"
res = requests.get(url)
if(res.status_code != 200):
lcd.Clear();
lcd.Write_String(1,1,"ERRORCODE:" + str(res.status_code))
exit(0)
j = res.json()
if(j['message'] == 'success'):
lcd.Clear();
lcd.Write_String(1,1,'message:'+str(j['message']))
lcd.Write_String(1,2,'number:'+str(j['number']))
time.sleep(3)
for eachone in range(0, j['number']):
lcd.Clear()
lcd.Write_String(1, 1, j['people'][eachone]['craft'])
lcd.Write_String(1, 2, j['people'][eachone]['name'])
time.sleep(3)
这个LCD1602不兹磁中文,也不能能直接上串口,所以过几日整个LCD12864玩一玩.