這篇文章將為大家詳細講解有關樹莓派4B加微雪2.13寸墨水屏怎樣監測pm2.5信息,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
成都創新互聯公司是專業的孟村網站建設公司,孟村接單;提供成都網站制作、成都網站建設,網頁設計,網站設計,建網站,PHP網站建設等專業做網站服務;采用PHP框架,可快速的進行孟村網站開發網頁制作和功能擴展;專業做搜索引擎喜愛的網站,專業的做網站團隊,希望更多企業前來合作!
title : 樹莓派4B加微雪2.13寸墨水屏,監測pm2.5信息
打開spi
vim /boot/config.txt
添加
dtparam=spi=on
pip鏡像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pacman -S gcc python-numpy make wiringpi freetype2
pip install spidev RPi.GPIO requests
pip install wiringpi
pip install --no-cache-dir pillow
pip install --upgrade pip
載樣例包https://github.com/waveshare/e-Paper
下面的python文件要放在e-paper/RaspberryPi&JetsonNano/python/examples/里面
代中的url參照第一個網址的getData.php,格式如下{"pm":"(23,32,35,23,32,35,3669,1042,136,13,1,1,10.0,19.9,64.4)","date":"2020-02-24 13:40:01"},我代碼中另一個樹莓派的地址,你也可以在同一個樹莓派中使用
python代碼如下:
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
import datetime
import requests
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath( __file__ ))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath( __file__ ))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
from waveshare_epd import epd2in13_V2
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
logging.basicConfig(level=logging.DEBUG)
try:
logging.info("epd2in13_V2 Demo")
epd = epd2in13_V2.EPD()
logging.info("init and Clear")
epd.init(epd.FULL_UPDATE)
#epd.Clear(0xFF)
# Drawing on the image
font15 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15)
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
logging.info("1.Drawing on the image...")
image = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
draw = ImageDraw.Draw(image)
#GetTime
#time = (datetime.datetime.now() + datetime.timedelta(hours=8)).strftime('%Y.%m.%d %H:%M:%S')
#PrintWord
#draw.text((20, 40), '呵呵', font = font15, fill = 0)
#PrintTime
#draw.text((20, 80), time, font = font15, fill = 0)
#Your PM2.5 data url
#Content for example:
#{"pm":"(25,37,46,25,37,46,3519,982,166,30,5,3,10.0,19.8,64.8)","date":"2020-02-24 13:30:03"}
url = "http://192.168.1.196/pm25/getData.php"
#Format pm2.5 data
alldata = requests.get(url)
pmdata = alldata.json() [ "pm" ]
pmdata = pmdata [ 1:-1 ]
pmdata = pmdata.split(",")
#Get time
time = alldata.json() [ "date" ]
#Get pm2.5,temperature,humidity
pm25 = pmdata [ 4 ]
temperature = pmdata [ 13 ]
humidity = pmdata [ 14 ]
#Draw all data
draw.text((20, 10), '空氣質量:' + pm25 + 'μg/m3', font = font15, fill = 0)
draw.text((20, 30), '溫度:' + temperature + '°C', font = font15, fill = 0)
draw.text((20, 50), '濕度:' + humidity + '%', font = font15, fill = 0)
draw.text((20, 70), time, font = font15, fill = 0)
draw.text((20, 90), 'By Andy', font = font15, fill = 0)
#ScreenRotate180
image = image.transpose(Image.ROTATE_180)
epd.display(epd.getbuffer(image))
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd2in13_V2.epdconfig.module_exit()
exit()
效果如下:
關于樹莓派4B加微雪2.13寸墨水屏怎樣監測pm2.5信息就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
當前文章:樹莓派4B加微雪2.13寸墨水屏怎樣監測pm2.5信息
當前地址:http://m.kartarina.com/article12/jedcdc.html
成都網站建設公司_創新互聯,為您提供自適應網站、標簽優化、網站制作、面包屑導航、網站設計、微信公眾號
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯