[ Raspberry Pi ] 透過 Python 顯示溫溼度資訊到 Grove LCD

本文描述如何透過 Python 將 Grove – Temperature and Humidity Sensor 的資訊顯示於 GROVE - LCD RGB BACKLIGHT

執行步驟


前置準備作業

1.準備 Raspberry Pi 3 Model B 開發板

2.準備 Micro SD (已安裝 Raspbian) - 【 透過 MacOS 安裝 Raspbian 教學 】

3.將 Micro SD 裝入到 Raspberry Pi 中

4.已設定網路

5.安裝 GrovePi+

6.安裝 Grove – Temperature and Humidity Sensor (D4)

7.安裝 GROVE - LCD RGB BACKLIGHT (I2C-2)


Sensor 、 LCD 、 GrovePi+ 與 Raspberry Pi 連接圖


Raspbian 端

Step 1. 下載前置安裝 Script

https://github.com/ArcherHuang/RaspberryPi/blob/master/Script/install.sh  

Step 2. 執行 install.sh

sudo ./install.sh  

Step 3. 下載要 Import 的兩個檔案

  • 於 Raspbian 端建立 Package 資料夾並將兩個檔案放到裡面
https://github.com/ArcherHuang/RaspberryPi/tree/master/Package  

Step 4. 撰寫 Python Code

import sys  
sys.path.append('/home/pi/rpi/code/Package')  
import grovepi  
from grove_rgb_lcd import *

sensor = 4  
blue = 0    # The Blue colored sensor.  
white = 1   # The White colored sensor.

while True:  
    [temp,humidity] = grovepi.dht(sensor,blue)  
    print("temp = %.02f C humidity =%.02f%%"%(temp, humidity))
    setText("temp = %.02f C \nhumidity =%.02f%%"%(temp, humidity))


Step 5. 執行剛寫好的 Python Code

python Python 的檔案名稱  

Step 6. 執行畫面

  • Console

  • Raspberry Pi


List of blogs

Archer

Having being a full stack engineer. Experience with C, Python, Go, Swift, JavaScript, Node.js, LinkIt 7697, LinkIt Smart 7688, Raspberry Pi, ARM mbed, IoT solutions. Contact us : [email protected]

ALL RIGHTS RESERVED. COPYRIGHT © 2016. Designed and Coded by Makee.io