[作品提交] 【得捷电子Follow me第2期】任务汇总

TL-LED   2023-10-7 10:13 楼主

一、帖子汇总

【得捷电子Follow me第2期】任务1:控制屏幕显示中文

【得捷电子Follow me第2期】任务2:网络功能测试

【得捷电子Follow me第2期】任务3:按键控制ws2812B

【得捷电子Follow me第2期】任务4:分任务1:日历&时钟

 

二、任务1:控制屏幕显示中文

2.1、下载CircuitPython Libraries

下载地址:https://circuitpython.org/libraries

003.jpg

2.2、复制文件到开发板

2.2.1、复制lib下这两个文件夹到开发板盘符下lib

004.jpg

 

 

2.2.2、复制字库到开发板盘符下fonts文件下

 wenquanyi_10pt.pcf (2.18 MB, 下载次数: 3)

 

2.3、程序

修改code.py

import board
import terminalio
from adafruit_display_text import bitmap_label
from adafruit_bitmap_font import bitmap_font

font = bitmap_font.load_font("fonts\wenquanyi_10pt.pcf")
color = 0x00ff00

text2 = "你好!电子工程世界"
scale = 2

text_area2 = bitmap_label.Label(font,text=text2,scale=scale)
text_area2.x = 10
text_area2.y = 60
board.DISPLAY.show(text_area2)

while True:
 pass

2.4、运行

005.jpg

 

三、任务2:网络功能测试

 

3.1、连接WIFI测试

测试连接WIFI,显示屏上显示出设备IP地址

 

3.1.1、测试代码:

copy.py

import board, os, wifi
import terminalio
from adafruit_display_text import bitmap_label
from adafruit_bitmap_font import bitmap_font

font = bitmap_font.load_font("fonts\wenquanyi_10pt.pcf")
color = 0x00FF00


wifi.radio.connect('TP-LINK', '66668888')
print("ipaddr: {wifi.radio.ipv4_address}")

text2 = "IP: " + str(wifi.radio.ipv4_address)
scale = 2

text_area2 = bitmap_label.Label(font, text=text2, scale=scale)
text_area2.x = 0
text_area2.y = 30
board.DISPLAY.show(text_area2)

while True:
    pass

3.1.2、显示屏显示

006.jpg

 

3.1.3、ping 网络

007.jpg

 

3.2、WIFI热点测试

3.2.1、测试代码

copy.py

import board, os, wifi

print("test esp32_wifi_ap")
wifi.radio.start_ap('esp32_wifi', '11223344')


while True:
    pass

 

3.2.2、手机连接

008.jpg

 

四、任务3:按键控制ws2812B

4.1、复制文件到开发板盘符下的lib文件夹下

009.jpg

 

4.2、测试代码

copy.py

import time
import board
import neopixel
import digitalio
from adafruit_display_text import bitmap_label
import terminalio
from adafruit_bitmap_font import bitmap_font

font = bitmap_font.load_font("fonts\wenquanyi_10pt.pcf")
color = 0x00FF00

text2 = "W2812B 关闭 "
scale = 2

text_area2 = bitmap_label.Label(font, text=text2, scale=scale)
text_area2.x = 10
text_area2.y = 30
text_area2.color = color
board.DISPLAY.show(text_area2)

pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.brightness = 0.5
white = (255, 255, 255)
red = (255, 0, 0)
green = (0, 255, 0)
blue= (0, 0, 255)
black = (0, 0, 0)

button = digitalio.DigitalInOut(board.BUTTON)
button.switch_to_input(pull=digitalio.Pull.UP)

pixel.fill(black)

but=0;
while True:
    if not button.value:
        but=but+1
        while (not button.value):
            pass
    
    if but==0:
        pixel.fill(black)
        
        text2 = "W2812B 关闭 "
        text_area2 = bitmap_label.Label(font, ext=text2, scale=scale )
        text_area2.x = 10
        text_area2.y = 30
        text_area2.color = 0x000000
        board.DISPLAY.show(text_area2)
    elif but==1:
        pixel.fill(red)
        
        text2 = "W2812B 红色 "
        text_area2 = bitmap_label.Label(font, text=text2, scale=scale)
        text_area2.x = 10
        text_area2.y = 30
        text_area2.color = 0xff0000
        board.DISPLAY.show(text_area2)
        
    elif but==2:
        pixel.fill(green)
        
        text2 = "W2812B 绿色 "
        text_area2 = bitmap_label.Label(font, text=text2, scale=scale)
        text_area2.x = 10
        text_area2.y = 30
        text_area2.color = 0x00ff00
        board.DISPLAY.show(text_area2)
    elif but==3:
        pixel.fill(blue)
        
        text2 = "W2812B 蓝色 "
        text_area2 = bitmap_label.Label(font, text=text2, scale=scale)
        text_area2.x = 10
        text_area2.y = 30
        text_area2.color = 0x0000ff
        board.DISPLAY.show(text_area2)
    elif but==4:
        pixel.fill(white)
        
        text2 = "W2812B 白色 "
        text_area2 = bitmap_label.Label(font, text=text2, scale=scale)
        text_area2.x = 10
        text_area2.y = 30
        text_area2.color = 0xffffff
        board.DISPLAY.show(text_area2)
    
    #a=a+1
    if but>4:
        but=0
    time.sleep(0.1)



 

4.3、运行效果

通过按键切换WS2812B显示的颜色,同时在LCD上显示相应状态颜色的汉字

1002.png

1003.png

 

五、任务4:分任务1:日历&时钟

 

5.1、复制文件到开发板盘符/lib文件下

010.jpg

 

5.2、测试代码

copy.py

import board, os, wifi
import time
import ssl
import socketpool
import adafruit_requests

from adafruit_display_text import label, wrap_text_to_lines
from adafruit_bitmap_font import bitmap_font

color = 0xFFFFFF
font = bitmap_font.load_font("fonts\wenquanyi_10pt.pcf")

display = board.DISPLAY
display.brightness = 1 
display.rotation = 0 

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

def refresh_screen(print_text):
    text_area = label.Label(font, text=print_text, scale=1)
    text_area.x = 5
    text_area.y = 15
    text_area.scale = 1
    text_area.color = color
    display.show(text_area)

def get_data():
    try:
        response = requests.get(JSON_TIME_URL)
    except ConnectionError as e:
        print("Connection Error:", e)
        print("Retrying in 60 seconds")
    time_data = response.json()['sysTime2'][:-3]

    try:
        city_code = "101180101"
        url = JSON_weather_URL.format(city_code)
        response = requests.get(url)
    except ConnectionError as e:
        print("connect error:{},retry in 60s".format(e))
    weather_data = response.json()
    cityInfo = weather_data['cityInfo']
    city_weather = weather_data['data']
    forecast = city_weather['forecast']
    dis_str = cityInfo['city'] + ' ' + forecast[0]['week']
    dis_str += "\n时间:"+time_data
    dis_str += "\n温度:"+city_weather['wendu']+"℃"
    dis_str += "\n湿度:" + city_weather['shidu']
    dis_str += '\n空气质量:' + city_weather['quality']
    return dis_str

while not wifi.radio.ipv4_address:
    try:
        wifi.radio.connect('TP-LINK', '66668888')
    except ConnectionError as e:
        print("connecti error:{},retry in 2s".format(e))
    time.sleep(2)
    
print("get ip:", wifi.radio.ipv4_address)

while True:
    info = get_data()
    refresh_screen(info)
    time.sleep(60)

 

5.3、运行

 

获取的天气信息显示在LCD上

002.jpg

 

六、心得

此次活动让我学习了Adafruit ESP32-S3 TFT Feather开发板使用CircuitPython编程,原来编程可以这样做,使用很方便。通过几个任务的测试,学习到了LCD的显示,按键控制W2812B多彩灯的颜色切换,网络通信功能的测试。希望后续有机会继续参与到此活动。

 

演示视频:>> 点击查看   
 
任务代码:>> 点击下载
 
 

回复评论 (1)

赞~全称认真跟学下来啦~

玩板看这里: https://bbs.eeworld.com.cn/elecplay.html EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!
点赞  2023-10-7 10:41
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复