当前位置:   article > 正文

microbit python中文_micropython可以支持中文咯

microbit串口发送汉字

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()

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号