LORA DX-LR03测试 micropython

from machine import I2C,Pin,UART
import time
from ssd1306 import SSD1306_I2C#I2C的oled选该方法
i2c=I2C(0,sda=Pin(3), scl=Pin(2), freq=400000) 
oled = SSD1306_I2C(128, 64, i2c) #你的OLED分辨率,使用I2C
oled.fill(1) #清空屏幕
oled.show()


t=15
while t>0:
    oled.fill(0)
    oled.text("INIT LORA "+str(t)+"S",0,9,1)
    t=t-1
    oled.show()
    time.sleep(1)

u=UART(1,9600,tx=Pin(0),rx=Pin(1))

def lora(i):
    time.sleep(3)
    c=u.read()
    print(c)
    if type(c) is bytes:
        i=i+1
        oled.fill(0)
        oled.text(c.decode(),0,9,1)
        e=time.localtime()
        timestr=str(e[0])+"-"+str(e[1])+"-"+str(e[2])+" "+str(e[3])+":"+str(e[4])
        oled.text(timestr,0,20,1)
        oled.text(str(i),0,30,1)
        oled.show()
    return i

i=0
while 1:
    i=lora(i)

城市大概3KM以内,保险起见2KM,电梯内无信号,使用LEVEL0 最低速度

发表回复