ตัวอย่าง OLED + DHT22

Sittipong Jansorn
Jul 22, 2017 · 1 min read

ในหัวข้อนี้เราจะมาทดสอบเอาข้อมูลจาก sensor dht22 มาแสดงค่าด้วยจอ OLED

import module

from machine import I2C

import module Pin

from machine import Pin

import module dht22

from dht import DHT22

import module SSD1306_I2C ที่อยู่ใน package ssd1306

from ssd1306 import SSD1306_I2C

import module time

import time

กำหนดขาที่ใช้เชื่อมต่อกับระบบบัส I2C โดยให้ SCL = GPIO2, SDA = GPIO0

scl = Pin(2)
sda = Pin(0)

สร้าง object I2C โดยใช้ชื่อตัวแปรเป็น i2c

i2c = I2C(scl=scl, sda=sda, freq=100000)

สราง object SSD1306_I2C โดยใช้ชื่อตัวแปรเป็น oled

oled = SSD1306_I2C(128, 64, i2c)

สร้าง object dht22 โดยเชื่อมต่อกับ GPIO5

d = DHT22(Pin(5))

code ตัวอย่าง oled_dht.py

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade