【得捷电子Follow me第2期】+项目总结报告
[复制链接]
内容一:演示视频
内容二:项目总结报告
1、项目介绍
本项目使用的主控是Adafruit ESP32-S3 TFT Feather,这是由Adafruit出品的一款富有特色的开源硬件,开发板使用乐鑫ESP32-S3芯片,支持WiFi和蓝牙能,自带高清TFT彩屏,2个按键,1个type C接口,1个电池供电接口,1颗WS2812B彩灯。
(1)Adafruit ESP32-S3 TFT Feather外观
(2)Adafruit ESP32-S3 TFT Feather引脚
(3)Adafruit ESP32-S3 TFT Feather工作模式
2、各任务功能对应的主要代码片段及说明
(1)任务1:控制屏幕显示中文
任务1完成了在Adafruit ESP32-S3 TFT Feather的TFT屏上显示中文的功能。
硬件:Adafruit ESP32-S3 TFT Feather
软件:Thonny
固件:dafruit CircuitPython 8.2.6 on 2023-09-12; Adafruit Feather ESP32-S3 TFT with ESP32S3
#【得捷电子Follow me第2期】任务1:控制屏幕显示中文
import board
import displayio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
display = board.DISPLAY
# uncommenting font files
font_file = "/font/Fontquan-XinYiGuanHeiTi-Regular.pcf"
# Set text, font, and color
text = "任务一:显示中文"
font = bitmap_font.load_font(font_file)
color = 0xFF00FF
# Create the tet label
text_area = label.Label(font, text=text, color=color, scale=2)
# Set the location
text_area.x = 10
text_area.y = 50
# Show it
display.show(text_area)
while True:
pass
(2)任务2:网络功能使用
任务2-1完成了Adafruit ESP32-S3 TFT Feather连接wifi,并在TFT屏上显示了IP地址。
硬件:Adafruit ESP32-S3 TFT Feather
软件:Thonny
固件:dafruit CircuitPython 8.2.6 on 2023-09-12; Adafruit Feather ESP32-S3 TFT with ESP32S3
#【得捷电子Follow me第2期】任务2-1:网络功能使用,连接到WiFi
import wifi
import board
import displayio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
wifi.radio.connect('xiaogui', '88888888')
print(f"IP地址: {wifi.radio.ipv4_address}")
display = board.DISPLAY
# uncommenting font files
font_file = "/font/Fontquan-XinYiGuanHeiTi-Regular.pcf"
# Set text, font, and color
text = "IP地址:" + str(wifi.radio.ipv4_address)
font = bitmap_font.load_font(font_file)
color = 0xFF00FF
# Create the tet label
text_area = label.Label(font, text=text, color=color, scale=1)
# Set the location
text_area.x = 30
text_area.y = 70
# Show it
display.show(text_area)
while True:
pass
任务2-2完成了Adafruit ESP32-S3 TFT Feather创建热点,并在TFT屏上显示了热点SSID与密码。
硬件:Adafruit ESP32-S3 TFT Feather
软件:Thonny
固件:dafruit CircuitPython 8.2.6 on 2023-09-12; Adafruit Feather ESP32-S3 TFT with ESP32S3
#【得捷电子Follow me第2期】任务2-2:网络功能使用,创建热点
import wifi
import board
import displayio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
wifi.radio.start_ap("esp32_wifi", "88888888")
print(f"SSID: esp32_wifi")
print(f"PASSWORD: 88888888")
display = board.DISPLAY
# uncommenting font files
font_file = "/font/Fontquan-XinYiGuanHeiTi-Regular.pcf"
# Set text, font, and color
text = "SSID: esp32_wifi"
text += "\nPASSWORD: 88888888"
font = bitmap_font.load_font(font_file)
color = 0xFF00FF
# Create the tet label
text_area = label.Label(font, text=text, color=color, scale=1)
# Set the location
text_area.x = 20
text_area.y = 50
# Show it
display.show(text_area)
while True:
pass
(3)任务3:控制WS2812B
任务3完成了通过Adafruit ESP32-S3 TFT Feather板载的BOOT按键实现板载WS2812B彩灯变换颜色。
硬件:Adafruit ESP32-S3 TFT Feather
软件:Thonny
固件:dafruit CircuitPython 8.2.6 on 2023-09-12; Adafruit Feather ESP32-S3 TFT with ESP32S3
#【得捷电子Follow me第2期】任务3:控制WS2812B,按键BOOT控制板载Neopixel颜色切换
import time
import board
import neopixel
import digitalio
flag = 1
# 按键配置
button = digitalio.DigitalInOut(board.BUTTON)
button.switch_to_input(pull=digitalio.Pull.UP)
# Configure the setup
PIXEL_PIN = board.D1 # pin that the NeoPixel is connected to
ORDER = neopixel.RGB # pixel color channel order
GREEN = (255, 0, 0) # color to blink
CLEAR = (0, 0, 0) # clear (or second color)
RED = (0, 255, 0) # color to blink
DELAY = 0.2 # blink rate in seconds
# Create the NeoPixel object
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, pixel_order=ORDER)
# Loop forever and blink the color
while True:
if button.value==False:
flag = flag * -1
if flag == 1:
pixel[0] = RED
time.sleep(DELAY)
pixel[0] = CLEAR
time.sleep(DELAY)
if flag == -1:
pixel[0] = GREEN
time.sleep(DELAY)
pixel[0] = CLEAR
time.sleep(DELAY)
(4)任务4:日历&时钟
任务4完成了通过Adafruit ESP32-S3 TFT Feather连接wifi,从网络获取日期、星期、天气等信息,并显示在TFT屏上。
硬件:Adafruit ESP32-S3 TFT Feather
软件:Thonny
固件:dafruit CircuitPython 8.2.6 on 2023-09-12; Adafruit Feather ESP32-S3 TFT with ESP32S3
#【得捷电子Follow me第2期】任务4:分任务1——日历&时钟
# 导入库
import wifi
import board
import displayio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
import os
import time
import ssl
import socketpool
import adafruit_requests
# 连接wifi
wifi.radio.connect('xiaogui', '88888888')
# 打印IP地址
print(f"IP地址: {wifi.radio.ipv4_address}")
# 字体文件
font_file = "/font/Fontquan-XinYiGuanHeiTi-Regular.pcf"
# JSON
JSON_TIME_URL = "http://quan.suning.com/getSysTime.do"
JSON_weather_URL = "http://t.weather.sojson.com/api/weather/city/{}"
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
# 设置字体、颜色
font = bitmap_font.load_font(font_file)
color = 0xFF00FF
# request请求
response = requests.get(JSON_TIME_URL)
time_data = response.json()['sysTime2'][:-3]
# 城市代码
city_code = "101010100"
url = JSON_weather_URL.format(city_code)
response = requests.get(url)
weather_data = response.json()
cityInfo = weather_data['cityInfo']
city_weather = weather_data['data']
forecast = city_weather['forecast']
# Set text
text = time_data + ' ' + forecast[0]['week']
text += '\n ' + cityInfo['city'] + " 天气:" + forecast[0]['type']
text += "\n 温度:"+city_weather['wendu']+"℃" + " 湿度:" + city_weather['shidu']
text += '\n 空气质量:' + city_weather['quality'] + ' PM2.5:' + str(city_weather['pm25'])
text += "\n 风力:" + forecast[0]['fl'] + " 风向:" + forecast[0]['fx']
# Create the tet label
text_area = label.Label(font, text=text, color=color, scale=1)
# Set the location
text_area.x = 15
text_area.y = 15
# Show it
display = board.DISPLAY
display.show(text_area)
while True:
pass
内容三:可编译下载的代码
心得体会
首先,感谢电子工程世界和得捷电子组织的此次【得捷电子Follow me第2期】活动,让我有幸接全面了解和测试了这块开发板。其次,Adafruit ESP32-S3 TFT Feather是一款非常棒的开发板,硬件过硬,集成度高,非常适合教学和各种项目的开发。再次,CircuitPython固件非常优秀,适配的开发板多,固件刷新方便,丰富的库和模块,大大提高了项目开发效率。
|