micropython lcd_micropython支持中文啦!

[Python] 纯文本查看 复制代码import urequests as requests

from machine import Pin,I2C,SPI

import time

import network

import ujson

import ssd1306

import HZK

i2c = I2C(scl=Pin(22), sda=Pin(21), freq=100000)

spi = SPI(baudrate=100000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))

cs = Pin(25,Pin.OUT)

HZK.init(spi,cs)

lcd=ssd1306.SSD1306_I2C(128,64,i2c)

API_KEY = 'mggxhv8zbogqbmqj'

UID = "UF239A86CE"

LOCATION = 'chengdu'

URL = 'https://api.seniverse.com/v3/weather/now.json'

UNIT = 'c'

LANGUAGE = 'zh-Hans'

SSID="YOURSSID"

PASSWORD="YOURPASSWORD"

wlan=None

s=None

def connectWifi(ssid,passwd):

global wlan

wlan=network.WLAN(network.STA_IF)

wlan.active(True)

wlan.disconnect()

wlan.connect(ssid,passwd)

while(wlan.ifconfig()[0]=='0.0.0.0'):

time.sleep(1)

return True

def fetchWeather(location):

result = requests.get(URL, params={

'key': API_KEY,

'location': location,

'language': LANGUAGE,

'unit': UNIT

})

return result.text

if __name__ == '__main__':

connectWifi(SSID,PASSWORD)

result = fetchWeather(LOCATION)

print(result)

j=ujson.loads(result)

print("\r\n\r\n")

print(j['results'][0]['location']['name'])

print(j['results'][0]['now']['text'])

print(j['results'][0]['now']['temperature'])

addr=j['results'][0]['location']['name']

weather=j['results'][0]['now']['text']

temperature=j['results'][0]['now']['temperature']

lcd.text("地点:%s"%addr,5,0)

lcd.text("天气:%s"%weather,5,16)

lcd.text("温度:%s"%temperature,5,32)

lcd.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值