0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

怎样把PyPortal变成一个能够选择和设置多个光源的智能照明控制器

454398 来源:网络整理 作者:网络整理 2019-12-03 11:30 次阅读

概述

想为您的房间添加独特的照明吗?

一个简单的解决方案是添加几个具有WiFi功能的LED智能灯泡 》。这些灯泡具有高能效,并具有各种形状,大小和颜色,以适合您的空间。较小的灯泡可用于重点照明或照明,而较大的灯泡则更强大,可照亮整个房间!

这些类型的灯泡非常受欢迎-并且

在本指南中,您将把PyPortal变成一个能够选择和设置多个光源的智能照明控制器

LIFX系列智能-bulbs(src:https://www.lifx.com/pages/about)

与流行的Phillips Hue等更复杂的智能照明系统不同,LIFX灯是设置非常简单。每盏灯都有自己的wifi无线电(可能是基于ESP32ESP8266的东西?我们从拆解后的照片中看不到)并连接到您的WiFi网络

最值得注意的是LIFX指示灯的亮点在于它们提供了完善的HTTP API,类似于Adafruit IO HTTP API。这意味着您可以使用PyPortal轻松地与它进行交互。

如果您正在寻找一种方法来使用PyPortal交互式地控制房间的照明,请遵循!

CircuitPython代码

CircuitPython非常适合构建物联网项目。该项目使用ESP32SPI CircuitPython库,该库可以将ESP32用作WiFi协处理器,以将Web请求发送到LIFX HTTP远程控制API。

我们还为CircuitPython构建了一个LIFX帮助器模块,以便与这些指示灯非常容易。

您可以快速更新代码,而无需在设备上编译和存储WiFi和API密钥。这意味着每当您将PyPortal移至另一个网络时,都无需编辑代码和重新上传-只需更新文件并进行设置即可。

PyPortal

向PyPortal问好!使用触摸屏显示构建物联网项目的最简单方法!确保阅读PyPortal入门指南并浏览页面。它可以帮助您使用CircuitPython和一些演示代码进行设置!

先决条件指南

如果您不熟悉CircuitPython,请花点时间浏览以下指南以获取您已开始学习并加快速度:

欢迎使用CircuitPython

零件

本指南只需要一个PyPortal-不需要其他传感器或外部电路!

Adafruit PyPortal-CircuitPython支持的Internet显示

产品ID:4116

PyPortal,我们易于使用的物联网设备,可让您在数分钟内为“物联网”创建所有东西。制作自定义触摸屏界面。..

$ 54.95

进货

添加到购物车

1 x USB电缆

USB电缆-USB A到Micro-B-3英尺长

添加到购物车

这两个和PyPortal都在AdaBox 011中站立:

AdaBox011-PyPortal

产品ID:4061

借助PyPortal,您可以走到办公桌外-到达星星和更远的地方!该ADABOX具有易于使用的新型IoT设备,可让您自定义和创建。..

缺货

缺货

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代码

LIFX访问令牌

所有对LIFX灯泡的请求都需要一个访问令牌。

导航 到 LIFX帐户设置页上,命名访问令牌,并进行独特的设置,然后点击生成。

然后,将此令牌复制到文件或安全的地方-当您离开此页面时,您将不能再次查看它。

CircuitPython库安装

首先请确保您正在运行最新版本的

下一步,您需要安装必要的库才能使用硬件-仔细按照以下步骤从Adafruit的CircuitPython库中查找并安装这些库与您的CircuitPython版本匹配。 PyPortal至少需要CircuitPython版本4.0.0。

在继续之前,请确保您开发板的 lib 文件夹已复制了以下文件和文件夹 。

p》

adafruit_lifx

adastrong_bitmap_font

adafruit_bus_device

adafruit_button

adafruit_display_shapes

adafruit_display_text

》 adafruit_esp32spi

adafruit_touchscreen

neopixel

秘密文件设置

如果尚未设置 CIRCUITPY 驱动器中的 secrets.py 文件并使用该文件连接到Internet,请按照本指南进行操作,并在成功连接到Internet后返回此页面。/p》

添加您生成的LIFX访问令牌到 secrets.py 文件:

下载:文件

复制代码

secrets = {

‘ssid’ : ‘_your_wifi_ssid_’,

‘password : ’_your_wifi_password_‘,

’lifx_token‘ : ’_your_really_long_lifx_token_‘

} secrets = {

’ssid‘ : ’_your_wifi_ssid_‘,

’password : ‘_your_wifi_password_’,

‘lifx_token’ : ‘_your_really_long_lifx_token_’

}

添加CircuitPython代码和项目资产

在下面的嵌入式代码元素中,单击下载:Project Zip 链接,然后保存。压缩文件。

然后,解压缩.zip文件,它将解压缩到名为 pyportal_lifx_controller 的文件夹中。

将 pyportal_lifx_controller 目录的内容复制到PyPortal的 CIRCUITPY 驱动器。

下载:Project Zip 或 code.py | 查看Github

复制代码

“”“

PyPortal Smart Lighting Controller

-------------------------------------------------------------

https://learn.adafruit.com/pyportal-smart-lighting-controller

Brent Rubell for Adafruit Industries, 2019

”“”

import board

import displayio

from adafruit_bitmap_font import bitmap_font

from adafruit_button import Button

import adafruit_touchscreen

from digitalio import DigitalInOut

import busio

import neopixel

from adafruit_esp32spi import adafruit_esp32spi

from adafruit_esp32spi import adafruit_esp32spi_wifimanager

# import lifx library

import adafruit_lifx

# 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

# ESP32 SPI

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)

status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

# These pins are used as both analog and digital! XL, XR and YU must be analog

# and digital capable. YD just need to be digital

ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,

board.TOUCH_YD, board.TOUCH_YU,

calibration=((5200, 59000), (5800, 57000)),

size=(320, 240))

# Set this to your LIFX personal access token in secrets.py

# (to obtain a token, visit: https://cloud.lifx.com/settings)

lifx_token = secrets[‘lifx_token’]

# Initialize the LIFX API Helper

lifx = adafruit_lifx.LIFX(wifi, lifx_token)

# Set these to your LIFX light selector (https://api.developer.lifx.com/docs/selectors)

lifx_lights = [‘label:Lamp’, ‘label:Bedroom’]

# set default light properties

current_light = lifx_lights[0]

light_brightness = 1.0

# Make the display context

button_group = displayio.Group(max_size=20)

board.DISPLAY.show(button_group)

# preload the font

print(‘loading font.。.’)

font = bitmap_font.load_font(“/fonts/Arial-12.bdf”)

glyphs = b‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,。: ’

font.load_glyphs(glyphs)

# button properties

BUTTON_WIDTH = 60

BUTTON_HEIGHT = 60

buttons = []

# button fill colors (from https://api.developer.lifx.com/docs/colors)

button_colors = {‘red’:0xFF0000, ‘white’:0xFFFFFF,

‘orange’:0xFF9900, ‘yellow’:0xFFFF00,

‘green’:0x00FF00, ‘blue’:0x0000FF,

‘purple’:0x9900FF, ‘pink’: 0xFF00FF}

print(‘loading buttons.。.’)

# list of color buttons and their properties

color_btn = [

{‘name’:‘red’, ‘pos’:(15, 80), ‘color’:button_colors[‘red’]},

{‘name’:‘white’, ‘pos’:(85, 80), ‘color’:button_colors[‘white’]},

{‘name’:‘orange’, ‘pos’:(155, 80), ‘color’:button_colors[‘orange’]},

{‘name’:‘yellow’, ‘pos’:(225, 80), ‘color’:button_colors[‘yellow’]},

{‘name’:‘pink’, ‘pos’:(15, 155), ‘color’:button_colors[‘pink’]},

{‘name’:‘green’, ‘pos’:(85, 155), ‘color’:button_colors[‘green’]},

{‘name’:‘blue’, ‘pos’:(155, 155), ‘color’:button_colors[‘blue’]},

{‘name’:‘purple’, ‘pos’:(225, 155), ‘color’:button_colors[‘purple’]}

# generate color buttons from color_btn list

for i in color_btn:

button = Button(x=i[‘pos’][0], y=i[‘pos’][1],

width=BUTTON_WIDTH, height=BUTTON_HEIGHT, name=i[‘name’],

fill_color=i[‘color’], style=Button.ROUNDRECT)

buttons.append(button)

# light property buttons and their properties

prop_btn = [

{‘name’:‘onoff’, ‘pos’:(15, 15), ‘label’:‘on/off’},

{‘name’:‘up’, ‘pos’:(75, 15), ‘label’:‘+’},

{‘name’:‘down’, ‘pos’:(135, 15), ‘label’:‘-’},

{‘name’:‘lamp’, ‘pos’:(195, 15), ‘label’:‘lamp’},

{‘name’:‘room’, ‘pos’:(245, 15), ‘label’:‘room’}

# generate property buttons from prop_btn list

for i in prop_btn:

button = Button(name=i[‘name’], x=i[‘pos’][0], y=i[‘pos’][1],

width=40, height=40, label=i[‘label’],

label_font=font, style=Button.SHADOWROUNDRECT)

buttons.append(button)

# add buttons to the group

for b in buttons:

button_group.append(b.group)

while True:

touch = ts.touch_point

if touch:

for i, button in enumerate(buttons):

if button.contains(touch):

button.selected = True

if button.name == ‘lamp’:

current_light = lifx_lights[0]

print(‘Switching to ’, current_light)

elif button.name == ‘room’:

current_light = lifx_lights[1]

print(‘Switching to ’, current_light)

elif button.name == ‘onoff’:

print(‘Toggling {0}。..’.format(current_light))

lifx.toggle_light(current_light)

elif button.name == ‘up’:

light_brightness += 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

elif button.name == ‘down’:

light_brightness -= 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

else:

print(‘Setting {0} color to {1}’.format(current_light, button.name))

lifx.set_color(current_light, ‘on’, button.name, light_brightness)

button.selected = False

else:

button.selected = False

“”“

PyPortal Smart Lighting Controller

-------------------------------------------------------------

https://learn.adafruit.com/pyportal-smart-lighting-controller

Brent Rubell for Adafruit Industries, 2019

”“”

import board

import displayio

from adafruit_bitmap_font import bitmap_font

from adafruit_button import Button

import adafruit_touchscreen

from digitalio import DigitalInOut

import busio

import neopixel

from adafruit_esp32spi import adafruit_esp32spi

from adafruit_esp32spi import adafruit_esp32spi_wifimanager

# import lifx library

import adafruit_lifx

# 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

# ESP32 SPI

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)

status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

# These pins are used as both analog and digital! XL, XR and YU must be analog

# and digital capable. YD just need to be digital

ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,

board.TOUCH_YD, board.TOUCH_YU,

calibration=((5200, 59000), (5800, 57000)),

size=(320, 240))

# Set this to your LIFX personal access token in secrets.py

# (to obtain a token, visit: https://cloud.lifx.com/settings)

lifx_token = secrets[‘lifx_token’]

# Initialize the LIFX API Helper

lifx = adafruit_lifx.LIFX(wifi, lifx_token)

# Set these to your LIFX light selector (https://api.developer.lifx.com/docs/selectors)

lifx_lights = [‘label:Lamp’, ‘label:Bedroom’]

# set default light properties

current_light = lifx_lights[0]

light_brightness = 1.0

# Make the display context

button_group = displayio.Group(max_size=20)

board.DISPLAY.show(button_group)

# preload the font

print(‘loading font.。.’)

font = bitmap_font.load_font(“/fonts/Arial-12.bdf”)

glyphs = b‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,。: ’

font.load_glyphs(glyphs)

# button properties

BUTTON_WIDTH = 60

BUTTON_HEIGHT = 60

buttons = []

# button fill colors (from https://api.developer.lifx.com/docs/colors)

button_colors = {‘red’:0xFF0000, ‘white’:0xFFFFFF,

‘orange’:0xFF9900, ‘yellow’:0xFFFF00,

‘green’:0x00FF00, ‘blue’:0x0000FF,

‘purple’:0x9900FF, ‘pink’: 0xFF00FF}

print(‘loading buttons.。.’)

# list of color buttons and their properties

color_btn = [

{‘name’:‘red’, ‘pos’:(15, 80), ‘color’:button_colors[‘red’]},

{‘name’:‘white’, ‘pos’:(85, 80), ‘color’:button_colors[‘white’]},

{‘name’:‘orange’, ‘pos’:(155, 80), ‘color’:button_colors[‘orange’]},

{‘name’:‘yellow’, ‘pos’:(225, 80), ‘color’:button_colors[‘yellow’]},

{‘name’:‘pink’, ‘pos’:(15, 155), ‘color’:button_colors[‘pink’]},

{‘name’:‘green’, ‘pos’:(85, 155), ‘color’:button_colors[‘green’]},

{‘name’:‘blue’, ‘pos’:(155, 155), ‘color’:button_colors[‘blue’]},

{‘name’:‘purple’, ‘pos’:(225, 155), ‘color’:button_colors[‘purple’]}

# generate color buttons from color_btn list

for i in color_btn:

button = Button(x=i[‘pos’][0], y=i[‘pos’][1],

width=BUTTON_WIDTH, height=BUTTON_HEIGHT, name=i[‘name’],

fill_color=i[‘color’], style=Button.ROUNDRECT)

buttons.append(button)

# light property buttons and their properties

prop_btn = [

{‘name’:‘onoff’, ‘pos’:(15, 15), ‘label’:‘on/off’},

{‘name’:‘up’, ‘pos’:(75, 15), ‘label’:‘+’},

{‘name’:‘down’, ‘pos’:(135, 15), ‘label’:‘-’},

{‘name’:‘lamp’, ‘pos’:(195, 15), ‘label’:‘lamp’},

{‘name’:‘room’, ‘pos’:(245, 15), ‘label’:‘room’}

# generate property buttons from prop_btn list

for i in prop_btn:

button = Button(name=i[‘name’], x=i[‘pos’][0], y=i[‘pos’][1],

width=40, height=40, label=i[‘label’],

label_font=font, style=Button.SHADOWROUNDRECT)

buttons.append(button)

# add buttons to the group

for b in buttons:

button_group.append(b.group)

while True:

touch = ts.touch_point

if touch:

for i, button in enumerate(buttons):

if button.contains(touch):

button.selected = True

if button.name == ‘lamp’:

current_light = lifx_lights[0]

print(‘Switching to ’, current_light)

elif button.name == ‘room’:

current_light = lifx_lights[1]

print(‘Switching to ’, current_light)

elif button.name == ‘onoff’:

print(‘Toggling {0}。..’.format(current_light))

lifx.toggle_light(current_light)

elif button.name == ‘up’:

light_brightness += 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

elif button.name == ‘down’:

light_brightness -= 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

else:

print(‘Setting {0} color to {1}’.format(current_light, button.name))

lifx.set_color(current_light, ‘on’, button.name, light_brightness)

button.selected = False

else:

button.selected = False

这是 CIRCUITPY 的最终内容驱动器将如下所示:

设置代码

使用代码之前,您需要将 code.py 文件修改为添加一个标签来指定您要控制的灯。

LIFX使用称为选择器的标识符来识别与您的帐户关联的灯。通过选择器,您可以使用灯光的唯一标识符,位置(卧室,工作台,客厅)或照明组。为简单起见,本指南假定您将标签用作选择器。

查找灯泡的标签:

导航至LIFX应用,然后选择要控制的灯光。

点击齿轮图标以显示灯光的详细设置。

灯光的名称是灯光的标签。

下一步,修改 code.py 中的lifx_lights变量,以包含来自应用程序的标签。

例如,如果要添加一个名为 workbench 的新LIFX灯泡,则将代码 from

lifx_lights = [‘label:lamp’, ‘label:Main Room’]更改为

lifx_lights = [‘label:lamp’, ‘label:workbench’]

请确保包含label: 之前

有关使用LIFX灯光选择器的更多信息,请在此处查看有关此主题的API文档。

代码用法

从Mu编辑器中,单击“串行”按钮以打开REPL。您应该在加载界面时看到REPL显示代码的状态。

通过点击要控制的灯光的名称来选择灯光。如果未选择任何灯光,则代码将默认为列表。

点击/off按钮以切换所选灯的电源。请记住,LIFX灯会保存状态-如果您之前将灯设置为红色并关闭,则它会以相同的颜色打开。

按钮在向LIFX API发出请求时会反转颜色。 请求完成后,按钮将变回其原始颜色。

如果您遇到灯光不响应的问题:向下滚动到下面的诊断错误部分。

点击颜色按钮会将灯光设置为按钮的填充颜色,其亮度由 + 或-按钮指定。

注意:我们在本指南中使用了颜色名称来设置不同的颜色。 LIFX HTTP远程控制API允许您超越基本颜色-您可以通过指定色相,饱和度,亮度,开尔文或十六进制值来设置灯泡的颜色。

接下来,我们来看看加载到PyPortal上的代码

代码演练

导入库

下载:文件

复制代码

import board

import displayio

from adafruit_bitmap_font import bitmap_font

from adafruit_button import Button

import adafruit_touchscreen

from digitalio import DigitalInOut

import busio

import neopixel

from adafruit_esp32spi import adafruit_esp32spi

from adafruit_esp32spi import adafruit_esp32spi_wifimanager

# import lifx library

import adafruit_lifx import board

import displayio

from adafruit_bitmap_font import bitmap_font

from adafruit_button import Button

import adafruit_touchscreen

from digitalio import DigitalInOut

import busio

import neopixel

from adafruit_esp32spi import adafruit_esp32spi

from adafruit_esp32spi import adafruit_esp32spi_wifimanager

# import lifx library

import adafruit_lifx

代码首先导入运行智能照明控制器所需的所有库。

注意一个特殊的adafruit_lifx库。为了与LIFX API进行通信,我们编写了一个名为CircuitPython_LIFX的CircuitPython帮助器模块。该模块向LIFX API服务器发出HTTP请求(或“对话”),以便与灯泡进行交互。

有关HTTP工作原理的更多信息,请查看我们的All Internet of有关此主题的内容指南。

配置PyPortal

下载:文件

复制代码

# ESP32 SPI

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)

status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

# These pins are used as both analog and digital! XL, XR and YU must be analog

# and digital capable. YD just need to be digital

ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,

board.TOUCH_YD, board.TOUCH_YU,

calibration=((5200, 59000), (5800, 57000)),

size=(320, 240)) # ESP32 SPI

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)

status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

# These pins are used as both analog and digital! XL, XR and YU must be analog

# and digital capable. YD just need to be digital

ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,

board.TOUCH_YD, board.TOUCH_YU,

calibration=((5200, 59000), (5800, 57000)),

size=(320, 240))

下一部分代码从 secrets.py 文件中获取信息,包括wifi配置和LIFX Access令牌。然后,它建立ESP32的SPI连接,以与PyPortal一起使用。 wifi对象也在此处设置-稍后在代码中用于与LIFX API通信。

配置LIFX帮助器模块

下载:文件

复制代码

# Set this to your LIFX personal access token in secrets.py

# (to obtain a token, visit: https://cloud.lifx.com/settings)

lifx_token = secrets[‘lifx_token’]

# Initialize the LIFX API Helper

lifx = adafruit_lifx.LIFX(wifi, lifx_token)

# Set these to your LIFX light selector (https://api.developer.lifx.com/docs/selectors)

lifx_lights = [‘label:Lamp’, ‘label:Bedroom’]

# set default light properties

current_light = lifx_lights[0]

light_brightness = 1.0 # Set this to your LIFX personal access token in secrets.py

# (to obtain a token, visit: https://cloud.lifx.com/settings)

lifx_token = secrets[‘lifx_token’]

# Initialize the LIFX API Helper

lifx = adafruit_lifx.LIFX(wifi, lifx_token)

# Set these to your LIFX light selector (https://api.developer.lifx.com/docs/selectors)

lifx_lights = [‘label:Lamp’, ‘label:Bedroom’]

# set default light properties

current_light = lifx_lights[0]

light_brightness = 1.0

秘密中的lifx_token条目是设置为新变量lifx_token,并与之前创建的wifi对象一起传递到LIFX帮助器中。

然后,代码设置了两个灯的列表(由其选择器标识) 。在此代码的后面,这些灯链接到按钮,以便该代码可以识别正在切换的灯。

此外,还设置了默认的灯亮度100%,以及一个current_light变量。

按钮设置

下载:文件

复制代码

# Make the display context

button_group = displayio.Group(max_size=20)

board.DISPLAY.show(button_group)

# preload the font

print(‘loading font.。.’)

font = bitmap_font.load_font(“/fonts/Arial-12.bdf”)

glyphs = b‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,。: ’

font.load_glyphs(glyphs)

# button properties

BUTTON_WIDTH = 60

BUTTON_HEIGHT = 60

buttons = [] # Make the display context

button_group = displayio.Group(max_size=20)

board.DISPLAY.show(button_group)

# preload the font

print(‘loading font.。.’)

font = bitmap_font.load_font(“/fonts/Arial-12.bdf”)

glyphs = b‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,。: ’

font.load_glyphs(glyphs)

# button properties

BUTTON_WIDTH = 60

BUTTON_HEIGHT = 60

buttons = []

在代码可以创建按钮之前,它需要创建一个displayio组来容纳它们。在这里-代码选择一种字体,预加载了字形,并为BUTTON_WIDTH和BUTTON_HEIGHT设置按钮属性。

按钮生成

下载:文件

复制代码

# list of color buttons and their properties

color_btn = [

{‘name’:‘red’, ‘pos’:(15, 80), ‘color’:button_colors[‘red’]},

{‘name’:‘white’, ‘pos’:(85, 80), ‘color’:button_colors[‘white’]},

{‘name’:‘orange’, ‘pos’:(155, 80), ‘color’:button_colors[‘orange’]},

{‘name’:‘yellow’, ‘pos’:(225, 80), ‘color’:button_colors[‘yellow’]},

{‘name’:‘pink’, ‘pos’:(15, 155), ‘color’:button_colors[‘pink’]},

{‘name’:‘green’, ‘pos’:(85, 155), ‘color’:button_colors[‘green’]},

{‘name’:‘blue’, ‘pos’:(155, 155), ‘color’:button_colors[‘blue’]},

{‘name’:‘purple’, ‘pos’:(225, 155), ‘color’:button_colors[‘purple’]}

# generate color buttons from color_btn list

for i in color_btn:

button = Button(x=i[‘pos’][0], y=i[‘pos’][1],

width=BUTTON_WIDTH, height=BUTTON_HEIGHT, name=i[‘name’],

fill_color=i[‘color’], style=Button.ROUNDRECT)

buttons.append(button)

# light property buttons and their properties

prop_btn = [

{‘name’:‘onoff’, ‘pos’:(15, 15), ‘label’:‘on/off’},

{‘name’:‘up’, ‘pos’:(75, 15), ‘label’:‘+’},

{‘name’:‘down’, ‘pos’:(135, 15), ‘label’:‘-’},

{‘name’:‘lamp’, ‘pos’:(195, 15), ‘label’:‘lamp’},

{‘name’:‘room’, ‘pos’:(245, 15), ‘label’:‘room’}

# generate property buttons from prop_btn list

for i in prop_btn:

button = Button(name=i[‘name’], x=i[‘pos’][0], y=i[‘pos’][1],

width=40, height=40, label=i[‘label’],

label_font=font, style=Button.SHADOWROUNDRECT)

buttons.append(button)

# add buttons to the group

for b in buttons:

button_group.append(b.group) # list of color buttons and their properties

color_btn = [

{‘name’:‘red’, ‘pos’:(15, 80), ‘color’:button_colors[‘red’]},

{‘name’:‘white’, ‘pos’:(85, 80), ‘color’:button_colors[‘white’]},

{‘name’:‘orange’, ‘pos’:(155, 80), ‘color’:button_colors[‘orange’]},

{‘name’:‘yellow’, ‘pos’:(225, 80), ‘color’:button_colors[‘yellow’]},

{‘name’:‘pink’, ‘pos’:(15, 155), ‘color’:button_colors[‘pink’]},

{‘name’:‘green’, ‘pos’:(85, 155), ‘color’:button_colors[‘green’]},

{‘name’:‘blue’, ‘pos’:(155, 155), ‘color’:button_colors[‘blue’]},

{‘name’:‘purple’, ‘pos’:(225, 155), ‘color’:button_colors[‘purple’]}

# generate color buttons from color_btn list

for i in color_btn:

button = Button(x=i[‘pos’][0], y=i[‘pos’][1],

width=BUTTON_WIDTH, height=BUTTON_HEIGHT, name=i[‘name’],

fill_color=i[‘color’], style=Button.ROUNDRECT)

buttons.append(button)

# light property buttons and their properties

prop_btn = [

{‘name’:‘onoff’, ‘pos’:(15, 15), ‘label’:‘on/off’},

{‘name’:‘up’, ‘pos’:(75, 15), ‘label’:‘+’},

{‘name’:‘down’, ‘pos’:(135, 15), ‘label’:‘-’},

{‘name’:‘lamp’, ‘pos’:(195, 15), ‘label’:‘lamp’},

{‘name’:‘room’, ‘pos’:(245, 15), ‘label’:‘room’}

# generate property buttons from prop_btn list

for i in prop_btn:

button = Button(name=i[‘name’], x=i[‘pos’][0], y=i[‘pos’][1],

width=40, height=40, label=i[‘label’],

label_font=font, style=Button.SHADOWROUNDRECT)

buttons.append(button)

# add buttons to the group

for b in buttons:

button_group.append(b.group)

下一段代码将为浅色和属性。

首先,创建与按钮属性相对应的词典项目列表。 color_btn列表包含按钮的信息,例如按钮的名称,在显示器上的位置以及十六进制颜色值。 prop_btn列表包含按钮的名称,位置和文本标签。

然后,按钮从列表中生成,并附加到button列表中。将所有按钮都添加到button列表后,它们将被一对一地附加到displayio button_group。

主循环

下载:文件

复制代码

while True:

touch = ts.touch_point

if touch:

for i, button in enumerate(buttons):

if button.contains(touch):

button.selected = True while True:

touch = ts.touch_point

if touch:

for i, button in enumerate(buttons):

if button.contains(touch):

button.selected = True

主循环检查是否屏幕被触摸。如果是,它将搜索button列表中的哪个按钮被触摸。

确定按钮后,将切换按钮的selected属性-反转按钮的颜色,直到操作已执行。这样,您正在创建视觉状态指示器。

下载:文件

复制代码

if button.name == ‘lamp’:

current_light = lifx_lights[0]

print(‘Switching to ’, current_light)

elif button.name == ‘room’:

current_light = lifx_lights[1]

print(‘Switching to ’, current_light) if button.name == ‘lamp’:

current_light = lifx_lights[0]

print(‘Switching to ’, current_light)

elif button.name == ‘room’:

current_light = lifx_lights[1]

print(‘Switching to ’, current_light)

然后,代码根据其功能检查按钮的名称(它的作用)。如果按钮的名称是灯或房间,则将current_light切换为按钮的值。

每当主循环中的代码向LIFX API发送数据以对灯执行操作时, ,它使用current_light变量选择灯光。

下载:文件

复制代码

elif button.name == ‘onoff’:

print(‘Toggling {0}。..’.format(current_light))

lifx.toggle_light(current_light)

elif button.name == ‘up’:

light_brightness += 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

elif button.name == ‘down’:

light_brightness -= 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

else:

print(‘Setting {0} color to {1}’.format(current_light, button.name))

lifx.set_color(current_light, ‘on’, button.name, light_brightness)

button.selected = False elif button.name == ‘onoff’:

print(‘Toggling {0}。..’.format(current_light))

lifx.toggle_light(current_light)

elif button.name == ‘up’:

light_brightness += 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

elif button.name == ‘down’:

light_brightness -= 0.25

print(‘Setting {0} brightness to {1}’.format(current_light, light_brightness))

lifx.set_brightness(current_light, light_brightness)

else:

print(‘Setting {0} color to {1}’.format(current_light, button.name))

lifx.set_color(current_light, ‘on’, button.name, light_brightness)

button.selected = False

其余代码使用根据按钮的名称执行操作= 1》帮助程序模块。

按下开/关按钮-代码调用adafruit_lifx并传入lifx.toggle_light。

此按钮对应于LIFX远程API中定义的“切换电源”端点。

按下亮度按钮(+或-)时,代码将通过current_light和current_light转换为light_brightness。此外,每次按下按钮lifx.set_brightness时,递增或递减1/4。

此按钮对应于LIFX远程API中定义的“设置状态”端点。

如果按钮的名称与预定义的名称不对应,我们将使用按钮的名称作为传递给light_brightness的颜色来设置颜色。

此按钮对应于LIFX远程API中定义的“设置状态”端点。

您不受button_colors列表中定义的颜色的限制-您可以调整/混合颜色并将这些值发送到LIFX灯,请查看其网站上的颜色文档。

最后,代码将其selected属性设置为false,将其恢复为原始颜色以表示已执行操作。

进一步!

本指南仅刮擦了LIFX Light Remote HTTP API的表面。还有更多的端点,选项和效果可以使用。如果您有兴趣了解它的工作原理(更深层次),请查看帮助器库的存储库中的lifx.set_color文件。保持LIFX API网站在另一个选项卡中打开(作为参考)可能会有所帮助。

如果最终向库中添加了功能-感谢GitHub存储库上的拉取请求!

责任编辑:wv

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
收藏 人收藏

    评论

    相关推荐

    电源定时开关控制器怎么设置

    定时开关控制器成为了节能和自动化管理的重要工具。通过精确控制家庭电器的开关时间,我们不仅能够节省能源,还能提高生活的便利性。本文将详细介绍如何设置电源定时开关
    的头像 发表于 10-17 14:05 234次阅读

    LED照明和DC-DC转换控制集成在C2000微控制器

    电子发烧友网站提供《LED照明和DC-DC转换控制集成在C2000微控制器上.pdf》资料免费下载
    发表于 10-12 11:07 0次下载
    LED<b class='flag-5'>照明</b>和DC-DC转换<b class='flag-5'>控制</b>集成在<b class='flag-5'>一</b><b class='flag-5'>个</b>C2000微<b class='flag-5'>控制器</b>上

    路灯集中控制器与智慧照明:塑造未来城市的智能光影

    城市发展,照明需求激增传统路灯系统面临高能耗与管理难题突显什么样的解决方案能够确保照明质量的同时提升能效和降低成本成为城市管理和照明行业面临的紧迫挑战↓↓↓路灯集中
    的头像 发表于 09-09 11:12 279次阅读
    路灯集中<b class='flag-5'>控制器</b>与智慧<b class='flag-5'>照明</b>:塑造未来城市的<b class='flag-5'>智能</b>光影

    机器视觉光源控制器的作用有哪些

    机器视觉光源控制器是机器视觉系统中的重要组成部分,它的作用主要包括以下几个方面: 提供稳定的光源 机器视觉系统需要在各种不同的环境条件下工作,包括不同的光照条件、不同的物体表面特性等。为了确保图像
    的头像 发表于 07-04 10:33 576次阅读

    机器视觉光源控制器的工作原理

    机器视觉光源控制器种用于控制机器视觉系统中光源的设备,其主要作用是为机器视觉系统提供稳定、均匀、可调节的
    的头像 发表于 07-04 10:05 722次阅读

    PID控制器与开关控制器的区别

    在工业自动化控制系统中,PID控制器和开关控制器是两种常见的控制策略。它们各自具有独特的工作原理、应用场景和优缺点。本文旨在详细探讨PID控制器
    的头像 发表于 06-05 15:50 647次阅读

    应用智能照明控制系统的优势

    控制终端、远程控制器智能硬件,对城市照明、园区楼宇、运动场/体育馆、户外庆典等场合的照明系统进行升级改造,达到
    的头像 发表于 05-16 16:53 323次阅读

    如何发挥应急照明控制器的最大效能?

    如何发挥应急照明控制器的最大效能? 应急照明控制器,作为现代建筑安全系统的重要组成部分,承担着在紧急情况下提供必要照明的关键任务。然而,仅仅
    的头像 发表于 03-27 10:32 295次阅读

    如何选择适合的应急照明控制器?

    您详细介绍如何选择适合的应急照明控制器,帮助您在设计和选用时做出明智的决策。 、了解需求与场景 首先,明确应急照明
    的头像 发表于 03-21 16:51 424次阅读

    揭秘应急照明控制器选择要素与应用技巧

    控制器厂家将为您揭秘应急照明控制器选择要素与应用技巧,帮助您在设计和选用应急照明控制器时做出明
    的头像 发表于 03-20 15:51 470次阅读

    应急照明控制器:设计理念与用户体验

    应急照明控制器:设计理念与用户体验 在当今社会,应急照明控制器在保障人们安全方面发挥着越来越重要的作用。当遭遇突发情况时,
    的头像 发表于 02-28 15:27 449次阅读

    应急照明控制器:安装与调试技巧

    应急照明控制器的安装与调试技巧,以确保其正常工作。 、安装技巧 1、选址规划:在安装应急照明控制器之前,需要对其安装位置进行合理规划。应
    的头像 发表于 02-28 15:20 1935次阅读

    如何选择合适的集中电源控制器

    选择合适的集中电源控制器需要考虑以下几个方面: 电源需求:根据设备或系统的电源需求,选择能够提供相应电压和电流的集中电源控制器
    的头像 发表于 01-30 15:25 522次阅读
    如何<b class='flag-5'>选择</b>合适的集中电源<b class='flag-5'>控制器</b>?

    室内照明系统的光源选择

     室内照明系统是人们日常生活中不可缺少的部分,而光源选择是室内照明系统中至关重要的环节之
    发表于 01-23 10:27 542次阅读

    智能控制器功能介绍

    以简单的智能车为例,般会存在两控制器一个是运行ROS的主控,另一个是运行电机
    的头像 发表于 11-17 17:54 695次阅读
    <b class='flag-5'>智能</b>车<b class='flag-5'>控制器</b>功能介绍