概述
使用PyPortal IoT设备在您自己有吸引力的PyPortal报价书上动态显示Adafruit报价!
借助CircuitPython和板载WiFi,PyPortal Adafruit报价书从Adafruit报价页面动态加载JSON格式的数据,并自动显示文本和作者姓名,以使您整日(整夜)受到启发!
将PyPortal安装在一个小书本中(或挖空)
零件
Adafruit PyPortal-CircuitPython支持的Internet显示
产品ID:4116
PyPortal是我们易于使用的IoT设备,可让您在几分钟内为“物联网”创建所有东西。制作自定义触摸屏界面。..
$ 54.95
进货
添加到购物车
USB电缆-USB A至Micro-B
产品ID:592
这是您用于USB 1.1或USB 2.0的标准A到Micro-B USB电缆。非常适合将PC连接到Metro,Feather,Raspberry Pi或其他开发板或。..
$ 2.95
IN STOCK
添加到购物车
材料和工具
要安装PyPortal,您需要:
小装饰“书盒”或“可以用纸板或木材制成的书保险箱,大约5-1/2“ x 3-3/4” x 1-1/4“-您可以在业余爱好/家庭商店或在线购买
四M3 x 10mm螺钉和螺母
直边
爱好刀
可选的小凿子
》安装CircuitPython
CircuitPython是MicroPython的派生版,旨在简化低成本微控制器上的实验和教学。它不需要任何前期桌面软件下载,因此比以往任何时候都更容易获得原型。只需复制并编辑 CIRCUITPY “闪存”驱动器上的文件即可进行迭代。
以下说明将向您展示如何安装CircuitPython。如果您已经安装了CircuitPython,但希望对其进行更新或重新安装,则同样的步骤也适用!
设置CircuitPython快速入门!
请遵循以下快速逐步操作以获取超快速的Python功能:)
通过CircuitPython.org为该板下载最新版本的CircuitPython
点击上面的链接,为PyPortal下载最新版本的CircuitPython。
下载并将其保存到您的桌面(或方便的任何地方)。
使用已知良好的USB电缆将PyPortal插入计算机。
A很多人最终使用仅可充电的USB电缆,这非常令人沮丧!因此,请确保您拥有知道对数据同步有用的USB电缆。
双击中间顶部顶部的重置按钮(洋红色箭头)在板上,您将看到NeoPixel RGB LED(绿色箭头)变为绿色。如果它变成红色,请检查USB电缆,尝试使用另一个USB端口,等等。注意:USB接口旁边的红色小LED指示灯将呈红色闪烁。没关系!
如果第一次双击不起作用,请重试。有时可能需要一些尝试才能使节奏正确!
您将看到一个名为 PORTALBOOT 。
将 adafruit-circuitpython-pyportal- .uf2 文件拖到 PORTALBOOT。
LED将闪烁。然后, PORTALBOOT 驱动器将消失,并且将出现一个名为 CIRCUITPY 的新磁盘驱动器。
如果未在板上添加任何代码,唯一存在的文件是 boot_out.txt 。这是绝对正常的!是时候添加您的 code.py 并开始使用它了!
就这样,您完成了! :)
PyPortal默认文件
单击下面的按钮,下载PyPortal附带的文件的zip。
PyPortal默认文件
PyPortal CircuitPython设置
要在CircuitPython中使用PyPortal的所有出色功能,必须首先安装许多库。本页涵盖了该过程。
Adafruit CircuitPython捆绑包
下载Adafruit CircuitPython库捆绑包。您可以在此处找到最新版本:
最新的Adafruit CircuitPython库包
下载 adafruit-circuitpython-bundle-4。 x-mpy-*。zip 捆绑zip文件,然后解压缩同名文件夹。在内部,您会找到一个 lib 文件夹。您有两个选择:
您可以将 lib 文件夹添加到您的 CIRCUITPY 驱动器中。这将确保您拥有所有驱动程序。但是这将占用8 MB磁盘上的一堆空间
根据需要添加每个库,这将减少空间使用量,但您需要
至少,我们推荐以下库,实际上我们比推荐的要多。基本上是必需的。因此,立即抓住它们并将它们安装到 CIRCUITPY/lib !
adafruit_esp32spi -这是一个库,可通过ESP32进行互联网访问使用(您猜对了!)SPI传输。 Internet所需的任何东西都需要使用它
adafruit_requests -该库使我们能够执行HTTP请求并从服务器获取响应。 GET/POST/PUT/PATCH-它们都在这里!
adafruit_pyportal -这是我们友好的包装器库,可处理很多项目,显示图形和文本,从互联网上获取数据。
adafruit_touchscreen -一个用于从电阻式触摸屏读取触摸的库。
adafruit_cursorcontrol -用于读取PyGamer和PyBadge游戏杆和按钮的库。为您处理所有图形,按钮阅读和操纵杆移动。
adafruit_io -该库有助于将PyPortal连接到我们的免费数据记录和查看服务
adafruit_imageload -任何图形所需的图像显示助手!
adafruit_display_text -毫不奇怪,它在屏幕上显示文本
adafruit_bitmap_font -我们拥有精美的字体支持,并且易于制作新字体。该库读取并解析字体文件。
adafruit_slideshow -用于制作图像幻灯片-方便快速显示图形和声音
neopixel -用于控制板载新像素
adafruit_adt7410 -用于从板载Analog Devices ADT7410精密温度传感器读取温度的库
adafruit_sdcard -支持从板载SD卡插槽中读取/写入数据。
adafruit_bus_device -对I2C/SPI的低级支持
Internet连接!
一旦您安装了CircuitPython安装程序和库,我们就可以将您的电路板连接到Internet。请注意,目前不支持访问企业级安全的WiFi网络,仅支持需要SSID和密码的WiFi网络。
要建立连接,您需要先创建一个秘密文件。
什么是机密文件?
我们希望人们在构建CircuitPython WiFi小部件时共享大量项目。我们要避免的是人们不小心共享了他们的密码或秘密令牌和API密钥。因此,我们设计了所有示例,以使用 CIRCUITPY 驱动器中的secrets.py文件来保存秘密/私有/自定义数据。这样,您就可以共享您的主项目,而不必担心意外共享私有内容。
您的 secrets.py 文件应如下所示:
下载:文件
复制代码
# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it
secrets = {
‘ssid’ : ‘home ssid’,
‘password’ : ‘my password’,
‘timezone’ : “America/New_York”, # http://worldtimeapi.org/timezones
‘github_token’ : ‘fawfj23rakjnfawiefa’,
‘hackaday_token’ : ‘h4xx0rs3kret’,
}
# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it
secrets = {
‘ssid’ : ‘home ssid’,
‘password’ : ‘my password’,
‘timezone’ : “America/New_York”, # http://worldtimeapi.org/timezones
‘github_token’ : ‘fawfj23rakjnfawiefa’,
‘hackaday_token’ : ‘h4xx0rs3kret’,
}
Inside是一个名为secrets的python字典,每个条目都有一行。每个条目都有一个条目名称(例如‘ssid’),然后是一个冒号以将其与条目键‘home ssid’分开,最后是一个逗号,
至少您需要ssid和password用于您的本地WiFi设置。在创建项目时,您可能需要更多的令牌和密钥,只需一次添加一行即可。例如,请参见其他令牌,例如用于访问github或hackaday API的令牌。其他非机密数据(例如您的时区)也可以在此处,仅因为其称为机密的信息并不意味着您不能在其中包含常规的自定义数据!
有关正确的时区字符串,请查看http://worldtimeapi.org/timezones,请记住,如果未列出您的城市,请在同一时区中查找城市,例如,波士顿,纽约,费城,华盛顿特区和迈阿密都与纽约位于同一时间。
当然,不要共享您的 secrets.py -将其保存在GitHub,Discord或其他项目共享站点之外。
连接到WiFi
好,现在您已设置好机密-您可以连接到Internet。让我们使用ESP32SPI和Requests库-您需要访问CircuitPython捆绑包并安装:
adafruit_bus_device
adafruit_esp32spi
adafruit_requests
neopixel
进入您的lib文件夹。完成后,使用Mu或您喜欢的编辑器加载以下示例:
下载:项目邮编或 esp32spi_simpletest.py | 在Github上查看
复制代码
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
print(“ESP32 SPI webclient test”)
TEXT_URL = “http://wifitest.adafruit.com/testwifi/index.html”
JSON_URL = “http://api.coindesk.com/v1/bpi/currentprice/USD.json”
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print(“ESP32 found and in idle mode”)
print(“Firmware vers.”, esp.firmware_version)
print(“MAC addr:”, [hex(i) for i in esp.MAC_address])
for ap in esp.scan_networks():
print(“ %s RSSI: %d” % (str(ap[‘ssid’], ‘utf-8’), ap[‘rssi’]))
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
print(“My IP address is”, esp.pretty_ip(esp.ip_address))
print(“IP lookup adafruit.com: %s” % esp.pretty_ip(esp.get_host_by_name(“adafruit.com”)))
print(“Ping google.com: %d ms” % esp.ping(“google.com”))
#esp._debug = True
print(“Fetching text from”, TEXT_URL)
r = requests.get(TEXT_URL)
print(‘-’*40)
print(r.text)
print(‘-’*40)
r.close()
print()
print(“Fetching json from”, JSON_URL)
r = requests.get(JSON_URL)
print(‘-’*40)
print(r.json())
print(‘-’*40)
r.close()
print(“Done!”)
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
print(“ESP32 SPI webclient test”)
TEXT_URL = “http://wifitest.adafruit.com/testwifi/index.html”
JSON_URL = “http://api.coindesk.com/v1/bpi/currentprice/USD.json”
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print(“ESP32 found and in idle mode”)
print(“Firmware vers.”, esp.firmware_version)
print(“MAC addr:”, [hex(i) for i in esp.MAC_address])
for ap in esp.scan_networks():
print(“ %s RSSI: %d” % (str(ap[‘ssid’], ‘utf-8’), ap[‘rssi’]))
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
print(“My IP address is”, esp.pretty_ip(esp.ip_address))
print(“IP lookup adafruit.com: %s” % esp.pretty_ip(esp.get_host_by_name(“adafruit.com”)))
print(“Ping google.com: %d ms” % esp.ping(“google.com”))
#esp._debug = True
print(“Fetching text from”, TEXT_URL)
r = requests.get(TEXT_URL)
print(‘-’*40)
print(r.text)
print(‘-’*40)
r.close()
print()
print(“Fetching json from”, JSON_URL)
r = requests.get(JSON_URL)
print(‘-’*40)
print(r.json())
print(‘-’*40)
r.close()
print(“Done!”)
,并将其保存到您的板上,名称为code.py。
第一个连接示例不使用机密文件-您将首先输入SSID/密码来验证连接性!
然后转到此行
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
并更改MY_SSID_NAME和 MY_SSID_PASSWORD 设置为您的访问点名称和密码,并将其保留在‘’引号内。 (此示例不使用机密文件,但它也非常独立,因此,如果其他事情似乎不起作用,则可以始终重新加载该文件。您应该获得如下内容:
示例代码。..
使用SPI端口和3个控制引脚通过SPI初始化ESP32:
下载:文件
复制代码
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
告诉我们的requests库我们正在使用的套接字的类型(套接字类型随连接类型而变化-在此示例中,我们将使用adafruit_esp32spi_socket)。还将接口设置为
下载:文件
复制代码
esp requests
验证找到ESP32,检查固件和MAC地址
下载:文件
复制代码
requests.set_socket(socket, esp) requests.set_socket(socket, esp)
扫描它可以看到的所有访问点,并打印出名称和信号强度:
下载:文件
复制代码
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print(“ESP32 found and in idle mode”)
print(“Firmware vers.”, esp.firmware_version)
print(“MAC addr:”, [hex(i) for i in esp.MAC_address]) if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print(“ESP32 found and in idle mode”)
print(“Firmware vers.”, esp.firmware_version)
print(“MAC addr:”, [hex(i) for i in esp.MAC_address])
连接到我们在此处定义的AP,然后打印出来本地IP地址,尝试进行域名查找并ping google.com以检查网络连接(请注意,有时ping失败或需要一段时间,这没什么大不了的)
下载:文件
复制代码
for ap in esp.scan_networks():
print(“ %s RSSI: %d” % (str(ap[‘ssid’], ‘utf-8’), ap[‘rssi’])) for ap in esp.scan_networks():
print(“ %s RSSI: %d” % (str(ap[‘ssid’], ‘utf-8’), ap[‘rssi’]))
好的,现在我们进入真正有趣的部分。使用SAMD51或其他大容量RAM(超过32 KB)设备,我们可以做很多巧妙的事情。例如,我们可以像请求一样实现一个接口,这使得获取数据非常简单
从Web URL调用 print(“Connecting to AP.。.”)
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
print(“My IP address is”, esp.pretty_ip(esp.ip_address))
print(“IP lookup adafruit.com: %s” % esp.pretty_ip(esp.get_host_by_name(“adafruit.com”)))
print(“Ping google.com: %d ms” % esp.ping(“google.com”))
中读取所有文本-您可以传入 print(“Connecting to AP.。.”)
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
print(“My IP address is”, esp.pretty_ip(esp.ip_address))
print(“IP lookup adafruit.com: %s” % esp.pretty_ip(esp.get_host_by_name(“adafruit.com”)))
print(“Ping google.com: %d ms” % esp.ping(“google.com”))
用于SSL连接的URL
下载:文件
复制代码
requests.get https
或者,如果数据使用结构化JSON,则可以获取json pre -解析为可以轻松查询或遍历的Python字典。 (同样,仅适用于nRF52840,M4和其他高RAM板)
下载:文件
复制代码
TEXT_URL = “http://wifitest.adafruit.com/testwifi/index.html”
print(“Fetching text from”, TEXT_URL)
r = requests.get(TEXT_URL)
print(‘-’*40)
print(r.text)
print(‘-’*40)
r.close() TEXT_URL = “http://wifitest.adafruit.com/testwifi/index.html”
print(“Fetching text from”, TEXT_URL)
r = requests.get(TEXT_URL)
print(‘-’*40)
print(r.text)
print(‘-’*40)
r.close()
Requests
我们已经为Web接口编写了一个类似请求的库,名为Adafruit_CircuitPython_Requests。该库允许您发送HTTP/1.1请求,而无需“设计”它们,并提供了有用的方法来解析服务器的响应。
下载:Project Zip 或 requests_simpletest.py | 在Github上查看
复制代码
JSON_URL = “http://api.coindesk.com/v1/bpi/currentprice/USD.json”
print(“Fetching json from”, JSON_URL)
r = requests.get(JSON_URL)
print(‘-’*40)
print(r.json())
print(‘-’*40)
r.close() JSON_URL = “http://api.coindesk.com/v1/bpi/currentprice/USD.json”
print(“Fetching json from”, JSON_URL)
r = requests.get(JSON_URL)
print(‘-’*40)
print(r.json())
print(‘-’*40)
r.close()
代码首先设置ESP32SPI接口。然后,它使用ESP32 # adafruit_requests usage with an esp32spi_socket
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
# Initialize a requests object with a socket and esp32spi interface
requests.set_socket(socket, esp)
TEXT_URL = “http://wifitest.adafruit.com/testwifi/index.html”
JSON_GET_URL = “http://httpbin.org/get”
JSON_POST_URL = “http://httpbin.org/post”
print(“Fetching text from %s”%TEXT_URL)
response = requests.get(TEXT_URL)
print(‘-’*40)
print(“Text Response: ”, response.text)
print(‘-’*40)
response.close()
print(“Fetching JSON data from %s”%JSON_GET_URL)
response = requests.get(JSON_GET_URL)
print(‘-’*40)
print(“JSON Response: ”, response.json())
print(‘-’*40)
response.close()
data = ‘31F’
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, data))
response = requests.post(JSON_POST_URL, data=data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘data’ key from json_resp dict.
print(“Data received from server:”, json_resp[‘data’])
print(‘-’*40)
response.close()
json_data = {“Date” : “July 25, 2019”}
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, json_data))
response = requests.post(JSON_POST_URL, json=json_data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘json’ key from json_resp dict.
print(“JSON Data received from server:”, json_resp[‘json’])
print(‘-’*40)
response.close()
和# adafruit_requests usage with an esp32spi_socket
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
# Initialize a requests object with a socket and esp32spi interface
requests.set_socket(socket, esp)
TEXT_URL = “http://wifitest.adafruit.com/testwifi/index.html”
JSON_GET_URL = “http://httpbin.org/get”
JSON_POST_URL = “http://httpbin.org/post”
print(“Fetching text from %s”%TEXT_URL)
response = requests.get(TEXT_URL)
print(‘-’*40)
print(“Text Response: ”, response.text)
print(‘-’*40)
response.close()
print(“Fetching JSON data from %s”%JSON_GET_URL)
response = requests.get(JSON_GET_URL)
print(‘-’*40)
print(“JSON Response: ”, response.json())
print(‘-’*40)
response.close()
data = ‘31F’
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, data))
response = requests.post(JSON_POST_URL, data=data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘data’ key from json_resp dict.
print(“Data received from server:”, json_resp[‘data’])
print(‘-’*40)
response.close()
json_data = {“Date” : “July 25, 2019”}
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, json_data))
response = requests.post(JSON_POST_URL, json=json_data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘json’ key from json_resp dict.
print(“JSON Data received from server:”, json_resp[‘json’])
print(‘-’*40)
response.close()
对象初始化request对象。
下载:文件
复制代码
socket esp
带有请求的HTTP GET
代码向Adafruit的WiFi测试网站-http:/发出HTTP GET请求/wifitest.adafruit.com/testwifi/index.html。
为此,我们会将URL传递到import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
# Initialize a requests object with a socket and esp32spi interface
requests.set_socket(socket, esp)。我们还将将来自服务器的响应保存到名为import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
# Initialize a requests object with a socket and esp32spi interface
requests.set_socket(socket, esp)的变量。
尽管我们从服务器请求数据,但我们还是希望服务器回应。由于我们已经保存了服务器的requests.get(),因此可以将其读回。对我们来说幸运的是,请求将服务器的响应自动解码为人类可读的文本,您可以通过调用response将其读回。
最后,我们将执行一些操作通过调用response进行清理。这样会关闭,删除和收集响应的数据。
下载:文件
复制代码
response.text response.close()
一些服务器使用文本响应,而某些服务器则使用由属性-值对组成的json格式的数据进行响应。/p》
CircuitPython_Requests可以将来自服务器的JSON格式的响应转换为CPython print(“Fetching text from %s”%TEXT_URL)
response = requests.get(TEXT_URL)
print(‘-’*40)
print(“Text Response: ”, response.text)
print(‘-’*40)
response.close()对象。
我们还可以获取和解析 json 数据。我们将发送HTTP Get到一个我们知道的URL,该URL返回一个json格式的响应(而不是文本数据)。
然后,代码调用print(“Fetching text from %s”%TEXT_URL)
response = requests.get(TEXT_URL)
print(‘-’*40)
print(“Text Response: ”, response.text)
print(‘-’*40)
response.close()将响应转换为一个CPython dict.。
下载:文件
复制代码
response.json() dict
带有请求的HTTP POST
请求还可以通过调用print(“Fetching JSON data from %s”%JSON_GET_URL)
response = requests.get(JSON_GET_URL)
print(‘-’*40)
print(“JSON Response: ”, response.json())
print(‘-’*40)
response.close()方法(向其传递一个print(“Fetching JSON data from %s”%JSON_GET_URL)
response = requests.get(JSON_GET_URL)
print(‘-’*40)
print(“JSON Response: ”, response.json())
print(‘-’*40)
response.close()值)将数据发布到服务器。
下载:文件
复制代码
requests.post data
您还可以通过将data = ‘31F’
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, data))
response = requests.post(JSON_POST_URL, data=data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘data’ key from json_resp dict.
print(“Data received from server:”, json_resp[‘data’])
print(‘-’*40)
response.close()传递到data = ‘31F’
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, data))
response = requests.post(JSON_POST_URL, data=data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘data’ key from json_resp dict.
print(“Data received from server:”, json_resp[‘data’])
print(‘-’*40)
response.close()方法中,将json格式的数据发布到服务器。
下载:文件
复制代码
json_data requests.post
高级请求使用情况
要发送自定义HTTP, aders,将响应解析为原始字节,还是在CircuitPython代码中处理响应的http状态代码?
我们已经编写了一个示例来显示下面的请求模块的高级用法。
下载:项目Zip 或 requests_advanced.py | 在Github上查看
复制代码
json_data = {“Date” : “July 25, 2019”}
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, json_data))
response = requests.post(JSON_POST_URL, json=json_data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘json’ key from json_resp dict.
print(“JSON Data received from server:”, json_resp[‘json’])
print(‘-’*40)
response.close()
json_data = {“Date” : “July 25, 2019”}
print(“POSTing data to {0}: {1}”.format(JSON_POST_URL, json_data))
response = requests.post(JSON_POST_URL, json=json_data)
print(‘-’*40)
json_resp = response.json()
# Parse out the ‘json’ key from json_resp dict.
print(“JSON Data received from server:”, json_resp[‘json’])
print(‘-’*40)
response.close()
WiFi Manager
这个最简单的示例可行,但有点挑剔-您需要不断检查WiFi状态,并具有许多循环来管理连接和断开连接。对于更高级的用途,我们建议使用WiFiManager对象。它将为您包装连接/状态/请求循环-如果WiFi掉线,则重新连接,如果ESP32进入不良状态,则重置ESP32,等等。
这是一个更高级的示例,其中显示了WiFi管理器以及如何使用一些额外的标题发布数据:
下载:Project Zip 或 esp32spi_aio_post.py | 在Github上查看
复制代码
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
# Initialize a requests object with a socket and esp32spi interface
requests.set_socket(socket, esp)
JSON_GET_URL = “http://httpbin.org/get”
# Define a custom header as a dict.
headers = {“user-agent” : “blinka/1.0.0”}
print(“Fetching JSON data from %s.。.”%JSON_GET_URL)
response = requests.get(JSON_GET_URL, headers=headers)
print(‘-’*60)
json_data = response.json()
headers = json_data[‘headers’]
print(“Response‘s Custom User-Agent Header: {0}”.format(headers[’User-Agent‘]))
print(’-‘*60)
# Read Response’s HTTP status code
print(“Response HTTP Status Code: ”, response.status_code)
print(‘-’*60)
# Read Response, as raw bytes instead of pretty text
print(“Raw Response: ”, response.content)
# Close, delete and collect the response data
response.close()
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print(“Connecting to AP.。.”)
while not esp.is_connected:
try:
esp.connect_AP(b‘MY_SSID_NAME’, b‘MY_SSID_PASSWORD’)
except RuntimeError as e:
print(“could not connect to AP, retrying: ”,e)
continue
print(“Connected to”, str(esp.ssid, ‘utf-8’), “ RSSI:”, esp.rssi)
# Initialize a requests object with a socket and esp32spi interface
requests.set_socket(socket, esp)
JSON_GET_URL = “http://httpbin.org/get”
# Define a custom header as a dict.
headers = {“user-agent” : “blinka/1.0.0”}
print(“Fetching JSON data from %s.。.”%JSON_GET_URL)
response = requests.get(JSON_GET_URL, headers=headers)
print(‘-’*60)
json_data = response.json()
headers = json_data[‘headers’]
print(“Response‘s Custom User-Agent Header: {0}”.format(headers[’User-Agent‘]))
print(’-‘*60)
# Read Response’s HTTP status code
print(“Response HTTP Status Code: ”, response.status_code)
print(‘-’*60)
# Read Response, as raw bytes instead of pretty text
print(“Raw Response: ”, response.content)
# Close, delete and collect the response data
response.close()
您会在这里注意到,我们使用secrets.py文件来管理我们的SSID信息。 wifimanager被赋予了ESP32对象,密码和一个用于指示状态的新像素。
请注意,您需要在密码文件中添加一些其他信息,以便代码可以查询Adafruit IO API:
import time
import board
import busio
from digitalio import DigitalInOut
import neopixel
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
print(“ESP32 SPI webclient test”)
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print(“WiFi secrets are kept in secrets.py, please add them there!”)
raise
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
“”“Use below for Most Boards”“”
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
“”“Uncomment below for ItsyBitsy M4”“”
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
# Uncomment below for an externally defined RGB LED
# import adafruit_rgbled
# from adafruit_esp32spi import PWMOut
# RED_LED = PWMOut.PWMOut(esp, 26)
# GREEN_LED = PWMOut.PWMOut(esp, 27)
# BLUE_LED = PWMOut.PWMOut(esp, 25)
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
counter = 0
while True:
try:
print(“Posting data.。.”, end=‘’)
data = counter
feed = ‘test’
payload = {‘value’:data}
response = wifi.post(
“https://io.adafruit.com/api/v2/”+secrets[‘aio_username’]+“/feeds/”+feed+“/data”,
json=payload,
headers={“X-AIO-KEY”:secrets[‘aio_key’]})
print(response.json())
response.close()
counter = counter + 1
print(“OK”)
except (ValueError, RuntimeError) as e:
print(“Failed to get data, retrying ”, e)
wifi.reset()
continue
response = None
time.sleep(15)
import time
import board
import busio
from digitalio import DigitalInOut
import neopixel
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
print(“ESP32 SPI webclient test”)
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print(“WiFi secrets are kept in secrets.py, please add them there!”)
raise
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
“”“Use below for Most Boards”“”
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
“”“Uncomment below for ItsyBitsy M4”“”
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
# Uncomment below for an externally defined RGB LED
# import adafruit_rgbled
# from adafruit_esp32spi import PWMOut
# RED_LED = PWMOut.PWMOut(esp, 26)
# GREEN_LED = PWMOut.PWMOut(esp, 27)
# BLUE_LED = PWMOut.PWMOut(esp, 25)
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
counter = 0
while True:
try:
print(“Posting data.。.”, end=‘’)
data = counter
feed = ‘test’
payload = {‘value’:data}
response = wifi.post(
“https://io.adafruit.com/api/v2/”+secrets[‘aio_username’]+“/feeds/”+feed+“/data”,
json=payload,
headers={“X-AIO-KEY”:secrets[‘aio_key’]})
print(response.json())
response.close()
counter = counter + 1
print(“OK”)
except (ValueError, RuntimeError) as e:
print(“Failed to get data, retrying ”, e)
wifi.reset()
continue
response = None
time.sleep(15)
您可以转到adafruit.io查看AIO密钥链接获取这两个值并将它们添加到secrets文件中,该文件现在看起来像这样:
下载:文件
复制代码
aio_username aio_key
下一步,设置一个名为Adafruit IO提要# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it
secrets = {
‘ssid’ : ‘_your_ssid_’,
‘password’ : ‘_your_wifi_password_’,
‘timezone’ : “America/Los_Angeles”, # http://worldtimeapi.org/timezones
‘aio_username’ : ‘_your_aio_username_’,
‘aio_key’ : ‘_your_aio_key_’,
}
如果您不知道如何设置供稿,请遵循此页面并在设置名为。
然后,我们可以有一个简单的循环,用于将数据发布到Adafruit IO,而无需处理连接或初始化硬件!
在Adafruit.io上查看您的测试数据,每次Cir时,您都会看到该值增加cuitPython板向其发布数据!
使用CircuitPython编写PyPortal代码
项目特定库
以前,我们为PyPortal准备了所有最常用于PyPortal项目的库。如果要为此项目使用最低设置,就是这样:
adafruit_bitmap_font
adafruit_bus_device
adafruit_display_text
adafruit_esp32spi
adafruit_miniqr.mpy
》
adafruit_pyportal.mpy
adafruit_sdcard.mpy
adafruit_touchscreen.mpy
neopixel.mpy
CircuitPython代码
在下面的嵌入式代码元素中,单击下载:项目Zip 链接,然后将.zip存档文件保存到您的计算机中。
然后,解压缩.zip文件,它将解压缩到名为 PyPortal_Quotes 的文件夹。
将 PyPortal_Quotes 目录的内容复制到PyPortal的CIRC中UITPY驱动器,然后确保将quote.py文件重命名为code.py,以便在PyPortal重新启动时它将自动运行。
i》下载:Project Zip 或 quote.py | 在Github上查看
复制代码
import time
import board
from adafruit_pyportal import PyPortal
# Set up where we‘ll be fetching data from
DATA_SOURCE = “https://www.adafruit.com/api/quotes.php”
QUOTE_LOCATION = [0, ’text‘]
AUTHOR_LOCATION = [0, ’author‘]
# the current working directory (where this file is)
cwd = (“/”+__file__).rsplit(’/‘, 1)[0]
pyportal = PyPortal(url=DATA_SOURCE,
json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
status_neopixel=board.NEOPIXEL,
default_bg=cwd+“/quote_background.bmp”,
text_font=cwd+“/fonts/Arial-ItalicMT-17.bdf”,
text_position=((20, 120), # quote location
(5, 210)), # author location
text_color=(0xFFFFFF, # quote text color
0x8080FF), # author text color
text_wrap=(35, # characters to wrap for quote
0), # no wrap for author
text_maxlen=(180, 30), # max text size for quote & author
)
# speed up projects with lots of text by preloading the font!
pyportal.preload_font()
while True:
try:
value = pyportal.fetch()
print(“Response is”, value)
except (ValueError, RuntimeError) as e:
print(“Some error occured, retrying! -”, e)
time.sleep(60)
import time
import board
from adafruit_pyportal import PyPortal
# Set up where we’ll be fetching data from
DATA_SOURCE = “https://www.adafruit.com/api/quotes.php”
QUOTE_LOCATION = [0, ‘text’]
AUTHOR_LOCATION = [0, ‘author’]
# the current working directory (where this file is)
cwd = (“/”+__file__).rsplit(‘/’, 1)[0]
pyportal = PyPortal(url=DATA_SOURCE,
json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
status_neopixel=board.NEOPIXEL,
default_bg=cwd+“/quote_background.bmp”,
text_font=cwd+“/fonts/Arial-ItalicMT-17.bdf”,
text_position=((20, 120), # quote location
(5, 210)), # author location
text_color=(0xFFFFFF, # quote text color
0x8080FF), # author text color
text_wrap=(35, # characters to wrap for quote
0), # no wrap for author
text_maxlen=(180, 30), # max text size for quote & author
)
# speed up projects with lots of text by preloading the font!
pyportal.preload_font()
while True:
try:
value = pyportal.fetch()
print(“Response is”, value)
except (ValueError, RuntimeError) as e:
print(“Some error occured, retrying! -”, e)
time.sleep(60)
如果遇到任何错误,例如“ ImportError:没有名为“ adafruit_display_text.label”的模块”,请确保将您的库更新到最新的发行包!
CIRCUITPY驱动器的最终内容将如下所示:
PyPortal报价委员会正在做一些漂亮的事情,以提供令人愉悦的y报价体验!
Backgr
首先,它将位图图形显示为屏幕的背景。这是 .bmp 格式的320 x 240像素RGB 16位光栅图形。
字体
然后,它会显示引号和作者的名字,以及使用位图字体创建的文本覆盖在背景之上。这里使用的字体是由斜Arial字体制成的位图字体。您可以在本指南中了解有关转换类型的更多信息。
JSON
整洁的部分是文本不是来自设备上的文件,而是从网站上获取!
Adafruit.com在 adafruit.com/api/quotes.php 页面上有一个PHP脚本。每次被请求时,它都会从大型报价数据库返回一个新报价。
实际上,您可以运行PyPortal执行的相同查询来查看结果。复制此链接:https://www.adafruit.com/api/quotes.php
到您的浏览器,您将看到如下结果:
[
{
“text”: “Science, my lad, is made up of mistakes, but they are mistakes which it is useful to make, because they lead little by little to the truth”,
“author”: “Jules Verne”
}
]
该结果的引号格式为 JSON (JavaScript对象表示法)数组。它由具有两个键的单个元素组成:文本和作者。
文本键是Science, my lad, is made up of mistakes, but they are mistakes which it is useful to make, because they lead little by little to the truth
author 键的值是Jules Verne
,因为此JSON对象具有通过一致的方式将结果返回给我们,我们在PyPortal上运行的代码可以轻松地解析数据并显示它!
您可以在其中看到它的完成方式 code.py 的一部分:
下载:文件
复制代码
# Set up where we‘ll be fetching data from
DATA_SOURCE = “https://www.adafruit.com/api/quotes.php”
QUOTE_LOCATION = [0, ’text‘]
AUTHOR_LOCATION = [0, ’author‘] # Set up where we’ll be fetching data from
DATA_SOURCE = “https://www.adafruit.com/api/quotes.php”
QUOTE_LOCATION = [0, ‘text’]
AUTHOR_LOCATION = [0, ‘author’]
然后,在pyportal查询中,我们要求提供文本和 author 名称,然后使用text_参数设置font,position,color,wrap和显示时的文本的maxlen。
下载:文件
复制代码
pyportal = PyPortal(url=DATA_SOURCE,
json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
status_neopixel=board.NEOPIXEL,
default_bg=cwd+“quote_background.bmp”,
text_font=cwd+“fonts/Arial-ItalicMT-17.bdf”,
text_position=((20, 40), # quote location
(5, 190)), # author location
text_color=(0xFFFFFF, # quote text color
0x8080FF), # author text color
text_wrap=(35, # characters to wrap for quote
0), # no wrap for author
text_maxlen=(180, 30), # max text size for quote & author
) pyportal = PyPortal(url=DATA_SOURCE,
json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
status_neopixel=board.NEOPIXEL,
default_bg=cwd+“quote_background.bmp”,
text_font=cwd+“fonts/Arial-ItalicMT-17.bdf”,
text_position=((20, 40), # quote location
(5, 190)), # author location
text_color=(0xFFFFFF, # quote text color
0x8080FF), # author text color
text_wrap=(35, # characters to wrap for quote
0), # no wrap for author
text_maxlen=(180, 30), # max text size for quote & author
)
在while True:的主循环中,代码将查询Adafruit报价页面的JSON数据,并显示该数据,然后等待一分钟,直到重复该过程。
希望您的报价更新得更快或更慢?只需更改time.sleep()行中指定的秒数即可。
现在,您可以测试该程序,一旦该程序连接到WiFi,
下一步,我们将为PyPortal报价簿制作外壳。
构建书架
现在,我们将为PyPortal创建一个漂亮的外壳,以使用书箱显示报价。您还可以选择任何小型工艺品盒,食谱盒,雪茄盒或掏空书本。
为帮助切开窗口和孔,可以在打印机上打印此模板,然后切出内部矩形和孔。确保以1:1的比例打印并将缩放比例设置为100%。
PyPortal框架模板
然后,将框架粘贴到框上并进行跟踪用铅笔或钢笔在内部矩形和孔中进行切割,然后用爱好刀将其切出。用铰刀或钻子打孔或钻出孔。
切割模板
使用该模板传递适当的尺寸以切割屏幕窗口
您可以使用铅笔或记号笔来跟踪窗口和孔的中心。
切割
使用业余刀或方箱切割刀和直刃,进行多次切割,以逐渐切穿锅盖书箱。
要小心ul,请花点时间避免滑倒刀片。
钻探
使用锥子,手钻,铰刀或手钻在安装螺钉上打孔。这些直径应约为3mm。
螺钉
如图所示,将四颗M3 x 10毫米螺钉拧入书箱盖。
安装PyPortal
打开盖子,然后将PyPortal安装孔放在四个螺钉上,注意将屏幕对准
窗口故意比屏幕小,以便将屏幕支撑为三明治
拧紧四个螺母的手指。请勿过分用力将其拧入,否则将有可能损坏屏幕或PCB。
请确保匹配此对齐方式,以便在将书箱直立放置时,屏幕朝上,USB端口位于右下方。
这是显示报价簿的一种方法,使用略微打开的书箱并倾斜显示。
将USB电缆插入PyPortal为其供电。它将启动,显示背景图像,然后花一点时间连接到您的WiFi,然后再提供第一个报价。
如果您的显示没有开始更改引号,请仔细检查您是否加载了前面提到的所有文件,并编辑了设置文件以包含您的WiFi凭据。
电缆端口
如果您想完全合上书箱,则需要在USB电缆中放入一根剪下。
您可以标记位置,然后使用凿子或小型手锯切出一个缺口。
您好!您的PyPortal Adafruit报价书已经完成,可以准备鼓舞人心的话了!
责任编辑:wv
-
开发板
+关注
关注
25文章
4883浏览量
97010
发布评论请先 登录
相关推荐
评论