diff --git a/TOF200F/code/MQTT.py b/TOF200F/code/MQTT.py new file mode 100644 index 0000000000000000000000000000000000000000..c8539dc9a80ed119839d58f47c65b22c5d2da330 --- /dev/null +++ b/TOF200F/code/MQTT.py @@ -0,0 +1,243 @@ +try: + import usocket as socket +except: + import socket +import ustruct as struct +from ubinascii import hexlify + +class MQTTException(Exception): + pass + +class MQTTClient: + + def __init__(self, client_id, server, port=0, user=None, password=None, keepalive=0, + ssl=False, ssl_params={}): + if port == 0: + port = 8883 if ssl else 1883 + self.client_id = client_id + self.sock = None + self.server = server + self.port = port + self.ssl = ssl + self.ssl_params = ssl_params + self.pid = 0 + self.cb = None + self.user = user + self.pswd = password + self.keepalive = keepalive + self.lw_topic = None + self.lw_msg = None + self.lw_qos = 0 + self.lw_retain = False + + def _send_str(self, s): + self.sock.write(struct.pack("!H", len(s))) + self.sock.write(s) + + def _recv_len(self): + n = 0 + sh = 0 + while 1: + b = self.sock.read(1)[0] + n |= (b & 0x7f) << sh + if not b & 0x80: + return n + sh += 7 + + def set_callback(self, f): + self.cb = f + + def set_last_will(self, topic, msg, retain=False, qos=0): + assert 0 <= qos <= 2 + assert topic + self.lw_topic = topic + self.lw_msg = msg + self.lw_qos = qos + self.lw_retain = retain + + def connect(self, clean_session=True): + self.sock = socket.socket() + addr = socket.getaddrinfo(self.server, self.port)[0][-1] + self.sock.connect(addr) + if self.ssl: + import ussl + self.sock = ussl.wrap_socket(self.sock, **self.ssl_params) + premsg = bytearray(b"\x10\0\0\0\0\0") + msg = bytearray(b"\x04MQTT\x04\x02\0\0") + + sz = 10 + 2 + len(self.client_id) + msg[6] = clean_session << 1 + if self.user is not None: + sz += 2 + len(self.user) + 2 + len(self.pswd) + msg[6] |= 0xC0 + if self.keepalive: + assert self.keepalive < 65536 + msg[7] |= self.keepalive >> 8 + msg[8] |= self.keepalive & 0x00FF + if self.lw_topic: + sz += 2 + len(self.lw_topic) + 2 + len(self.lw_msg) + msg[6] |= 0x4 | (self.lw_qos & 0x1) << 3 | (self.lw_qos & 0x2) << 3 + msg[6] |= self.lw_retain << 5 + + i = 1 + while sz > 0x7f: + premsg[i] = (sz & 0x7f) | 0x80 + sz >>= 7 + i += 1 + premsg[i] = sz + + self.sock.write(premsg, i + 2) + self.sock.write(msg) + #print(hex(len(msg)), hexlify(msg, ":")) + self._send_str(self.client_id) + if self.lw_topic: + self._send_str(self.lw_topic) + self._send_str(self.lw_msg) + if self.user is not None: + self._send_str(self.user) + self._send_str(self.pswd) + resp = self.sock.read(4) + assert resp[0] == 0x20 and resp[1] == 0x02 + if resp[3] != 0: + raise MQTTException(resp[3]) + return resp[2] & 1 + + def disconnect(self): + self.sock.write(b"\xe0\0") + self.sock.close() + + def ping(self): + self.sock.write(b"\xc0\0") + + def publish(self, topic, msg, retain=False, qos=0): + pkt = bytearray(b"\x30\0\0\0") + pkt[0] |= qos << 1 | retain + sz = 2 + len(topic) + len(msg) + if qos > 0: + sz += 2 + assert sz < 2097152 + i = 1 + while sz > 0x7f: + pkt[i] = (sz & 0x7f) | 0x80 + sz >>= 7 + i += 1 + pkt[i] = sz + #print(hex(len(pkt)), hexlify(pkt, ":")) + self.sock.write(pkt, i + 1) + self._send_str(topic) + if qos > 0: + self.pid += 1 + pid = self.pid + struct.pack_into("!H", pkt, 0, pid) + self.sock.write(pkt, 2) + self.sock.write(msg) + if qos == 1: + while 1: + op = self.wait_msg() + if op == 0x40: + sz = self.sock.read(1) + assert sz == b"\x02" + rcv_pid = self.sock.read(2) + rcv_pid = rcv_pid[0] << 8 | rcv_pid[1] + if pid == rcv_pid: + return + elif qos == 2: + assert 0 + + def subscribe(self, topic, qos=0): + assert self.cb is not None, "Subscribe callback is not set" + pkt = bytearray(b"\x82\0\0\0") + self.pid += 1 + struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid) + #print(hex(len(pkt)), hexlify(pkt, ":")) + self.sock.write(pkt) + self._send_str(topic) + self.sock.write(qos.to_bytes(1, "little")) + while 1: + op = self.wait_msg() + if op == 0x90: + resp = self.sock.read(4) + #print(resp) + assert resp[1] == pkt[2] and resp[2] == pkt[3] + if resp[3] == 0x80: + raise MQTTException(resp[3]) + return + + # Wait for a single incoming MQTT message and process it. + # Subscribed messages are delivered to a callback previously + # set by .set_callback() method. Other (internal) MQTT + # messages processed internally. + def wait_msg(self): + res = self.sock.read(1) + self.sock.setblocking(True) + if res is None: + return None + if res == b"": + raise OSError(-1) + if res == b"\xd0": # PINGRESP + sz = self.sock.read(1)[0] + assert sz == 0 + return None + op = res[0] + if op & 0xf0 != 0x30: + return op + sz = self._recv_len() + topic_len = self.sock.read(2) + topic_len = (topic_len[0] << 8) | topic_len[1] + topic = self.sock.read(topic_len) + sz -= topic_len + 2 + if op & 6: + pid = self.sock.read(2) + pid = pid[0] << 8 | pid[1] + sz -= 2 + msg = self.sock.read(sz) + self.cb(topic, msg) + if op & 6 == 2: + pkt = bytearray(b"\x40\x02\0\0") + struct.pack_into("!H", pkt, 2, pid) + self.sock.write(pkt) + elif op & 6 == 4: + assert 0 + + # Checks whether a pending message from server is available. + # If not, returns immediately with None. Otherwise, does + # the same processing as wait_msg. + def check_msg(self): + self.sock.setblocking(False) + return self.wait_msg() + + +import utime, machine, network + +def Connect_Wifi(Username,Password): + wl = network.WLAN() + wl.active(1) + wl.connect(Username,Password,security=network.AUTH_PSK) + +class a (): + def __init__(self,client_id,mqtt_server,Topic,mqtt_user,mqtt_password,msg=None,client=False): + self.client_id = client_id #任意设置id + self.mqtt_server = mqtt_server #测试用可改变 + self.port=1883 + self.Topic = Topic + self.mqtt_user = mqtt_user + self.mqtt_password = mqtt_password + self.msg=None + self.client = MQTTClient(self.client_id, self.mqtt_server, user=self.mqtt_user, password=self.mqtt_password,port=self.port) + + + def sub_cb(self,msg): + self.client.publish(self.Topic, msg) + + def connect_and_subscribe(self): + self.client.set_callback(self.sub_cb) + self.client.connect() + self.client.subscribe(self.Topic) + print('Connected to %s MQTT broker, subscribed to %s topic' % (self.mqtt_server, self.Topic)) + return self.client + + def restart_and_reconnect(self): + print('Failed to connect to MQTT broker. Reconnecting...') + utime.sleep(10) + machine.reset() + diff --git a/TOF200F/code/TOF200F.py b/TOF200F/code/TOF200F.py new file mode 100644 index 0000000000000000000000000000000000000000..d6aed2dfc46be5e6da07ae2536694e9345474289 --- /dev/null +++ b/TOF200F/code/TOF200F.py @@ -0,0 +1,9 @@ +from machine import UART, Pin +import ubinascii, utime + +def measure(): + uart = UART(1, tx = Pin(0), rx = Pin(5)) #uart初始化,可自定义 + uart.write('01 06 00 04 00 01 09 CB') #传输测量距离 + uart.write('01 06 00 01 10 00 D5 F9') #传输重启 + + return uart \ No newline at end of file diff --git a/TOF200F/code/main.py b/TOF200F/code/main.py new file mode 100644 index 0000000000000000000000000000000000000000..532a3f54f2cedec8a57170152aaafc573156040c --- /dev/null +++ b/TOF200F/code/main.py @@ -0,0 +1,118 @@ +########################################################################################################################### +#TOF200F激光传感器测距 + +import utime, ubinascii, st7789, math, icm20948, MQTT +from machine import SPI, Pin +from machine import I2C +from TOF200F import measure +client_id = "3463027" +mqtt_server = "thingworx.zucc.edu.cn" +port=1883 +Topic = "666"#可自定义 +MQTT.Connect_Wifi("mzc", "12345678")#调整为自己的热点名称和密码 +mqtt_user='' +mqtt_password='' +spi = SPI(0, baudrate=40000000, polarity=1, phase=0, bits=8, endia=0, sck=Pin(6), mosi=Pin(8)) +imu = icm20948.ICM20948(I2C(0), accel_scale=icm20948.GPM_8) +display = st7789.ST7789(spi, 240, 240, reset=Pin(11,func=Pin.GPIO, dir=Pin.OUT), dc=Pin(7,func=Pin.GPIO, dir=Pin.OUT)) +mqtt = MQTT.a(client_id,mqtt_server,Topic,mqtt_user,mqtt_password) + +############################################################################################################################ +#屏幕初始化 + +display.init() +display.draw_string(50, 230, "Powered by BlackWalnut Labs.") + +############################################################################################################################ +#连接网络 + +try: + client = mqtt.connect_and_subscribe() +except OSError as e: + mqtt.restart_and_reconnect() + +############################################################################################################################ +#绘制屏幕 + +i = 0 +while i != 256: + display.fill(st7789.color565(i, i, i)) + i = i + 2 + +i = i - 1 +while i != 1: + display.draw_string(10, 10, 'Welcome to use!', size=3, color=st7789.color565(i, i, i)) + i = i - 1 + +display.fill(st7789.color565(87, 182, 177)) +display.circle(120, 120, 90, st7789.color565(255, 255, 255)) +display.circle(120, 120, 89, st7789.color565(255, 255, 255)) +display.circle(120, 120, 88, st7789.color565(255, 255, 255)) +display.hline(100, 120, 40, st7789.color565(255, 255, 255)) +display.vline(120, 100, 40, st7789.color565(255, 255, 255)) + +########################################################################################################################### +#主函数 + +def mymain(): + count = 0 + n = 979.363#重力加速度 + uart = measure() + utime.sleep_ms(500) + while True: + flag = 0 + num = uart.read(7)#读取长度为7 + + if count: + display.draw_string(10, 10, l, size=2, color=st7789.color565(87, 182, 177), bg = st7789.color565(87, 182, 177))#补全屏幕底色缺失 + + #测量x,y方向加速度 + imu.dataupdate() + g = imu.acc_z() + print("z =", g) + x = imu.acc_x() / n + if x > 1: + x = 1 + elif x < -1: + x = -1 + x = x * 90 + + y = imu.acc_y() / n + if y > 1: + y = 1 + elif y < -1: + y = -1 + y = y * 90 + + display.fill_circle(int(120 + x), int(120 - y), 5, st7789.color565(255, 255, 255))#绘制小球 + + #如果z方向加速度在此范围内可以显示距离,否则提示保持水平 + if g > 955 and g < 975: + flag = 1 + else: + l = "Please keep balance" + display.draw_string(10, 10, l, size=2, color=st7789.color565(255, 0, 0), bg = st7789.color565(87, 182, 177)) + + print(num) + if num[0] == 1 and num[1] == 3 and num[2] == 2 and flag:#前三位校验 + l = (num[3] * 10 + num[4]) / 10 + + if l < 2:#如果距离小于2,向手机发送警报 + client.publish("666", "warn") + + l = str(l) + display.draw_string(10, 10, l, size=2, color=st7789.color565(255, 255, 255))#在屏幕显示 + count = 1 + + num = uart.readline()#清除多余的数据,降低延迟 + utime.sleep_ms(500)#休眠500ms + + #补全可能被小球遮盖的部分 + display.fill_circle(int(120 + x), int(120 - y), 5, st7789.color565(87, 182, 177)) + display.circle(120, 120, 90, st7789.color565(255, 255, 255)) + display.circle(120, 120, 89, st7789.color565(255, 255, 255)) + display.circle(120, 120, 88, st7789.color565(255, 255, 255)) + display.hline(100, 120, 40, st7789.color565(255, 255, 255)) + display.vline(120, 100, 40, st7789.color565(255, 255, 255)) + +mymain() \ No newline at end of file diff --git "a/TOF200F/image/\344\274\240\346\204\237\345\231\250\346\240\267\345\274\217.jpg" "b/TOF200F/image/\344\274\240\346\204\237\345\231\250\346\240\267\345\274\217.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..997213039fb91dfdd336d2880de6bdcbe3eb28a0 Binary files /dev/null and "b/TOF200F/image/\344\274\240\346\204\237\345\231\250\346\240\267\345\274\217.jpg" differ diff --git "a/TOF200F/image/\345\217\221\351\200\201\350\255\246\346\212\245.jpg" "b/TOF200F/image/\345\217\221\351\200\201\350\255\246\346\212\245.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..5ab2a783ba36612820353346ddf71c16964bc809 Binary files /dev/null and "b/TOF200F/image/\345\217\221\351\200\201\350\255\246\346\212\245.jpg" differ diff --git "a/TOF200F/image/\345\274\225\350\204\232\346\217\217\350\277\260.jpg" "b/TOF200F/image/\345\274\225\350\204\232\346\217\217\350\277\260.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..e765176231332580e58a0e4bf246952d466ac5fd Binary files /dev/null and "b/TOF200F/image/\345\274\225\350\204\232\346\217\217\350\277\260.jpg" differ diff --git "a/TOF200F/image/\345\274\225\350\204\232\350\277\236\347\272\277.jpg" "b/TOF200F/image/\345\274\225\350\204\232\350\277\236\347\272\277.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..a8732e47e4384e1a17b9a0f28c2996762a860fce Binary files /dev/null and "b/TOF200F/image/\345\274\225\350\204\232\350\277\236\347\272\277.jpg" differ diff --git "a/TOF200F/image/\346\265\213\351\207\217\346\225\260\346\215\256.jpg" "b/TOF200F/image/\346\265\213\351\207\217\346\225\260\346\215\256.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..af3c7d0523dd6b1e6b6424619a79989af5b3f482 Binary files /dev/null and "b/TOF200F/image/\346\265\213\351\207\217\346\225\260\346\215\256.jpg" differ diff --git "a/TOF200F/image/\351\235\236\346\260\264\345\271\263\347\212\266\346\200\201.jpg" "b/TOF200F/image/\351\235\236\346\260\264\345\271\263\347\212\266\346\200\201.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..b8dab80c9908e24f141dbf1667259210abc4943a Binary files /dev/null and "b/TOF200F/image/\351\235\236\346\260\264\345\271\263\347\212\266\346\200\201.jpg" differ diff --git a/TOF200F/readme.md b/TOF200F/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..4c8e331730c28b1a223e8a0456c2d52b4a993c69 --- /dev/null +++ b/TOF200F/readme.md @@ -0,0 +1,61 @@ +# **TOF200F激光测距传感器** + +## **物理连接** + +### **传感器选择** + +>本文所选择的传感器为TOF200F,如下图所示 +>![传感器样式](image/传感器样式.jpg) + + +### **传感器接线** + +>传感器引脚描述如下 +> +>![引脚描述](image/引脚描述.jpg) +> +> +> +>传感器与Waffle Nano的连接图如下 +> +>![引脚连线](image/引脚连线.jpg) + + + +## **传感器库使用** + +>在Waffle Nano调用该库的代码在[TOF200F.py](code/TOF200F.py)中,利用Waffle Maker中的上传文件导入Waffle Nano后,方可引用 +> +>引用该库的方法为 +> +>```python +>from TOF200F import measure +>``` +> +>库中默认连接的引脚为 TX为0号引脚,RX为5号引脚。 + + + +## **案例复现** + +>本案例是一个利用激光传感器测距离(最大测量距离室内可达2米精度在5%以内)。 +> +>![测量数据](image/测量数据.jpg) +> +> +> +>屏幕中间的圆为一个水平仪,当测距未保持水平时,屏幕上会出现“Please keep balance”的提示。 +> +>![非水平状态](image\非水平状态.jpg) +> +> +> +>当距离小于2cm时,Waffle Nano会通过MQTT向手机发出“warn”的警报。 +> +>![发送警报](image\发送警报.jpg) + + + +## **案例代码复现** + +>将[MQTT.py](code/MQTT.py)利用Waffle Maker中的上传文件导入Waffle Nano,在将[main.py](code/main.py)复制到Waffle Maker烧入后,即可完成案例代码复现。 \ No newline at end of file diff --git "a/\357\200\233`" "b/\357\200\233`" new file mode 100644 index 0000000000000000000000000000000000000000..7703340c364d5463bb13e40c163ad0e2a1b9adca --- /dev/null +++ "b/\357\200\233`" @@ -0,0 +1,180 @@ +diff --git a/AHT20/README.md b/AHT20/README.md +index fafb8de..d804aea 100644 +--- a/AHT20/README.md ++++ b/AHT20/README.md +@@ -1,44 +1,71 @@ +-# AHT20温度计 ++# AHT20 +  +-用于AHT20温度和湿度传感器的MicroPython驱动程序。(AHT10也适用) +-# 案例展示 ++用于AHT20和AHT10温度和湿度传感器的MicroPython驱动程序。 +  +- +  +-可以实时输出温湿度,已经温度计条显示当前温度 +-# 传感器选择 +  +- ++## 案例展示 +  +- ++  读取温湿度数据, 并判断温度与湿度的高低情况,将其输出在屏幕上 +  ++![1.jpg](/aht20/img/1.jpg) +  ++## 物理连接 +  +- +- +-# 物理连线 + SCL --> G01 + SDA --> G00 + VCC --> 3V3 + GND --> GND +  ++### 传感器选择 ++ ++   传感器选择如下图所示的型号为aht20的温湿度传感器模块 ++ ++![2.jpg](/aht20/img/2.jpg) ++ ++###  ++ + ## 传感器库使用 ++ ++  可以获取[ahtx0.py](https://gitee.com/blackwalnutlabs/waffle-nano-v1-sensor-lib/blob/master//aht20/code/ahtx0.py),将此库通过[Waffle Maker](https://wafflenano.blackwalnut.tech/ide/index.html#/editor) 的文件上传功能将此库上传到`Waffle Nano` ++ ++  我们在可以在主函数中使用以下代码导入此库 ++ + ```python + import ahtx0 + ``` +  +-可以获取[ahtx0.py](https://gitee.com/blackwalnutlabs/waffle-nano-v1-sensor-lib/blob/master/AHT20/code/ahtx0.py),将此库通过[Waffle Maker](https://wafflenano.lwb2892844157.tech/ide/index.html#/editor)的文件上传到`Waffle Nano`上。 +- +-关于此库相关细节说明详见代码注释。 +-## 样例代码 ++  在对象构造函数中,我们需要传入三个引脚数字,分别是ADC引脚,以及两个可设置模式为输入的引脚 +  + ```python ++heartSensor = AD8232(analogPin = 5, LO1Pin = 2, LO2Pin = 14) #构造心电传感器对象 ++``` ++ ++  使用心电传感器对象的`read()`方法读取出整型数据 ++ ++``` ++x=int(sensor.temperature*100) x=int(sensor.relative_humidity*100) #从心电传感器中获取数据 ++``` ++ ++​ 关于此库相关细节说明详见代码注释 ++ ++# 样例代码 ++ + import utime + from machine import Pin, I2C +  + import ahtx0 + i2c = I2C(1, sda=Pin(0), scl=Pin(1), freq=100000) +  ++#使用I2C创建传感器对象 ++ ++sensor = ahtx0.AHT20(i2c) ++ ++while True: ++ print("\nTemperature: %0.2f C" % sensor.temperature) ++ print("Humidity: %0.2f %%" % sensor.relative_humidity) ++ utime.sleep(5) ++ + # 使用I2C创建传感器对象 + sensor = ahtx0.AHT20(i2c) +  +@@ -46,9 +73,10 @@ while True: + print("\nTemperature: %0.2f C" % sensor.temperature) + print("Humidity: %0.2f %%" % sensor.relative_humidity) + utime.sleep(5) +-``` ++ + ## 案例代码复现 +  +-可以获取[main.py](https://gitee.com/black-pwq/waffle-nano-v1-sensor-lib/blob/master/AHT20/code/main.py)将此库通过[Waffle Maker](https://wafflenano.lwb2892844157.tech/ide/index.html#/editor)的文件上传到`Waffle Nano`上。 ++  可以获取[main.py](https://gitee.com/blackwalnutlabs/waffle-nano-v1-sensor-lib/blob/master/aht20/code/main.py)函数,将其内容复制到[Waffle Maker](https://wafflenano.blackwalnut.tech/ide/index.html#/editor) 编辑器上传输给`Waffle Nano`,以复现此案例。 ++ ++  案例相关细节说明详见代码注释 +  +-案例相关细节说明详见代码注释。 +diff --git a/AHT20/code/ahtx0.py b/AHT20/code/ahtx0.py +index d3bdca4..7361d36 100644 +--- a/AHT20/code/ahtx0.py ++++ b/AHT20/code/ahtx0.py +@@ -1,9 +1,39 @@ ++# The MIT License (MIT) ++# ++# Copyright (c) 2020 Kattni Rembor for Adafruit Industries ++# Copyright (c) 2020 Andreas Bühl ++# ++# Permission is hereby granted, free of charge, to any person obtaining a copy ++# of this software and associated documentation files (the "Software"), to deal ++# in the Software without restriction, including without limitation the rights ++# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++# copies of the Software, and to permit persons to whom the Software is ++# furnished to do so, subject to the following conditions: ++# ++# The above copyright notice and this permission notice shall be included in ++# all copies or substantial portions of the Software. ++# ++# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ++# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ++# THE SOFTWARE. ++""" ++ ++MicroPython driver for the AHT10 and AHT20 Humidity and Temperature Sensor ++ ++Author(s): Andreas Bühl, Kattni Rembor ++ ++""" ++ + import utime + from micropython import const +  +  + class AHT20: +-  ++ """Interface library for AHT10/AHT20 temperature+humidity sensors""" +  + AHTX0_I2CADDR_DEFAULT = const(0x38) # Default I2C address + AHTX0_CMD_INITIALIZE = 0xBE # Initialization command +diff --git a/AHT20/code/main.py b/AHT20/code/main.py +index 96a3c4a..d676143 100644 +--- a/AHT20/code/main.py ++++ b/AHT20/code/main.py +@@ -2,77 +2,81 @@ from machine import I2C, Pin, SPI + import utime + import ahtx0 + import st7789 +-from turtle_nano import Turtle +-i2c = I2C(1, sda=Pin(0), scl=Pin(1), freq=100000) +-print(i2c.scan()) +-sensor = ahtx0.AHT20(i2c) +-spi = SPI(0, baudrate=40000000, polarity=1, phase=0, bits=8, endia=0, sck=Pin(6), mosi=Pin(8)) ++import ujson  ++import urandom  +  ++spi = SPI(0, baudrate=40000000, polarity=1, phase=0, bits=8, endia=0, sck=Pin(6), mosi=Pin(8))  + display = st7789.ST7789(spi, 240, 240, reset=Pin(11,func=Pin.GPIO, dir=Pin.OUT), dc=Pin(7,func=Pin.GPIO, dir=Pin.OUT)) ++  + display.init() +-display.fill(st7789.color565(0, 0, 0)) +-pic = Turtle(display,200, 150,st7789.color565(0, 0, 0)) +-while (1): +- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~绘制温度计 ++utime.sleep(4)  ++display.fill(st7789.color565(255, 255, 255))  ++display.pixel(5, 5, st7789.color565(255, 0, 0))  ++display.draw_string(15, 55, "Welcome to use ",size=3,color=st7789.color565(0, 0, 0))  ++display.draw_string(5, 85, "the temperature",size=3,color=st7789.color565(0, 0, 0))  ++display.draw_string(30, 1 \ No newline at end of file