|
【pyboardCN V2】驱动OLED与DHT11
[复制链接]
参考了其他使用pyb大佬们的OLED和DHT11例程来改,对于我这种micropython基础不深的初学者来说还真的是挺有帮助的。代码如下:
程序代码.zip
(3 KB, 下载次数: 11)
from pyb import LED #add LED
import DHTsensor
import ssd1306
import machine
import time
from machine import Pin
from machine import I2C
from machine import SPI
# construct an SPI bus on the given pins
# polarity is the idle state of SCK
# phase=0 means sample on the first edge of SCK, phase=1 means the second
# OLED
#Pin(14)--SCK machine.Pin("B13") --D0
#Pin(13)--MOSI machine.Pin("B15") --D1
#Pin(12)--MISO machine.Pin("B14") //没用上
#Pin(16)--CS machine.Pin("B0 ") --CS
#Pin(4)--RES machine.Pin("B10") --RES
#Pin(5)--DC machine.Pin("B11") --DC
spi=SPI(
baudrate=10000000,
polarity=1,
phase=0,
sck=machine.Pin("B13"),
mosi=machine.Pin("B15"),
miso=machine.Pin("B14"))
display=ssd1306.SSD1306_SPI(
128,
64,
spi,
machine.Pin("B11"),
machine.Pin("B10"),
machine.Pin("B0"))
led_blue = LED(4)
led_blue.on()
dht = DHTsensor.DHT11(Pin("B12"))
#try:
display.poweron()
display.init_display()
display.text("pyb dht11",1,1)
display.text("donatello1996",1,16)
display.text("temp:",1,32)
display.text("humi:",1,48)
display.show()
while True:
dht.measure()
display.text(str(dht.temperature()),40,32)
display.text(str(dht.humidity()),40,48)
display.show()
|
赞赏
-
1
查看全部赞赏
-
|