546 views|1 replies

1

Posts

1

Resources
The OP
 

【Digi-Key Follow me Issue 2】Project Summary [Copy link]

 

I am very happy to participate in the Follow me 2nd Development Board Challenge. This project was completed using the Adafruit ESP32-S3 TFT Feather development board. This development board uses Espressif's ESP32-S3 chip, and has a built-in IPS TFT display and colorful LED lights. The built-in modules are very easy for novices like me to learn and debug. Combined with the ease of use of Circuit Python, development becomes very easy to get started.

Code upload

任务代码汇总.rar (3.08 KB, downloads: 3)
Code link
https://download.eeworld.com.cn/detail/ahfood/629837

Video upload


Task Selection

The following tasks were selected for this project:

Task 1: Control the screen to display Chinese

Task 2: Network Function Usage

Task 3: Controlling the WS2812B

Task 4 Task 1: Calendar & Clock

Preparations before starting the mission:

All you need is an Adafruit ESP32-S3 TFT Feather, a Type C cable and a computer.

Enter DFU mode:

Connect the development board to the computer via a Type C data cable. After the screen displays information, press the Rst button twice to enter DFU mode.

Burn Circuit Python:

Copy the Circuit Python firmware directly to the USB flash drive in DFU mode, and complete the burning process when the progress is completed.

Libraries required for copying jobs:

Just copy the library required for the job to the lib folder in the root directory of the USB flash drive in DFU mode.

Complete the wifi configuration:

Just fill in the necessary information in settings.toml (the ssid and password are masked in the screenshot here).

So far, the preparations before the assignment have been completed. The following is a detailed introduction and key codes for each task:

Task 1: Control the screen to display Chinese

Task requirements: Complete screen control and display Chinese

Design idea: The biggest challenge for displaying Chinese is to solve the font problem. After selecting a suitable font to import, create an image group, add the text to be displayed to the image group, use the onboard screen to display it, and create an infinite loop to maintain the display.

Design process and code:

Here we use Font Forge software. After loading the selected TTF format font, click Bitmap Strikes Available under the Element menu and select the required format and parameters.

The font size is set to 25 here, and other parameters are automatically generated.

After clicking OK, click Regenerate Bitmap Glyphs in the Element menu and click OK.

Finally, click Generate Fonts in the File menu and set the format as shown in the figure to generate the BDF font library.

Finally, open https://adafruit.github.io/web-bdftopcf/ to generate PCF format fonts through the web page.

After changing the name, place it in the font folder of the development board to complete the font setting.

Edit code.py in the development version directly and import the required modules:

import board
import displayio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font

Use the device's own screen device

screen = board.DISPLAY

Create a displayed image group

contents = displayio.Group()

Setting the font

font = bitmap_font.load_font("/font/font.pcf")

Set each line of text line by line, set the font, color to white, magnification to 1, and add it to the image group

text_1 = "人是万物的尺度,"
content_1 = label.Label(font, text=text_1, color=0xffffff, scale=1)
content_1.x = 10
content_1.y = 15
contents.append(content_1)

text_2 = "是存在的事物存在"
content_2 = label.Label(font, text=text_2, color=0xffffff, scale=1)
content_2.x = 10
content_2.y = 40
contents.append(content_2)

text_3 = "的尺度,也是不存"
content_3 = label.Label(font, text=text_3, color=0xffffff, scale=1)
content_3.x = 10
content_3.y = 65
contents.append(content_3)

text_4 = "在的事物不存在的"
content_4 = label.Label(font, text=text_4, color=0xffffff, scale=1)
content_4.x = 10
content_4.y = 90
contents.append(content_4)

text_5 = "尺度。"
content_5 = label.Label(font, text=text_5, color=0xffffff, scale=1)
content_5.x = 10
content_5.y = 115
contents.append(content_5)

Display the content

screen.show(contents)

Create an infinite loop to keep the content displayed continuously

while True:
 pass

This completes homework 1, and the effect is as shown below:

Task 2: Network Function Usage

Task requirements: Complete the use of network functions, be able to create a hotspot and connect to WiFi

Design ideas - creating hot spots:

Use the WiFi module to create a hotspot, and use the text display function in Task 1 to display the SSID and password of the hotspot on the screen.

Design idea - connect to wifi:

Use the WiFi module to complete the WiFi connection, and use the branch structure to determine whether the connection is successful. If the connection is successful, the SSID of the connected WiFi and the obtained IP address will be displayed on the screen.

To create a hotspot:

Import the required modules

import board
import displayio
import wifi
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font

Create a hotspot directly through the wifi module

wifi.radio.start_ap("Rica's wifi", "12345678")

Display the hotspot's SSID and password on the screen in text form:

screen = board.DISPLAY
contents = displayio.Group()
font = bitmap_font.load_font("/font/font.pcf")

text_1 = "wifi信息:"
content_1 = label.Label(font, text=text_1, color=0xffffff, scale=1)
content_1.x = 10
content_1.y = 40
contents.append(content_1)

text_2 = "SSID:Rica's wifi"
content_2 = label.Label(font, text=text_2, color=0xffffff, scale=1)
content_2.x = 10
content_2.y = 65
contents.append(content_2)

text_3 = "密码:12345678"
content_3 = label.Label(font, text=text_3, color=0xffffff, scale=1)
content_3.x = 10
content_3.y = 90
contents.append(content_3)

screen.show(contents)
while True:
 pass

The effect is as shown below:

Connect to wifi:

Import the required modules:

import os
import board
import displayio
import wifi
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font

The network connection is completed through the wifi module. The SSID and password set in the configuration file are obtained here.

wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))

Setting the Display

screen = board.DISPLAY
contents = displayio.Group()
font = bitmap_font.load_font("/font/font.pcf")

Determine whether the connection is successful and set different text output content. If the connection is successful, the SSID and IP address of the wifi can be displayed

if wifi.radio.connected:
 text_1 = f"wifi:{os.getenv('CIRCUITPY_WIFI_SSID')}"
 text_2 = "您的IP地址为:"
 text_3 = str(wifi.radio.ipv4_address)
else:
 text_2 = "wifi连接失败!"
 text_3 = "请检查设置!"

Output the results

content_1 = label.Label(font, text=text_1, color=0xffffff, scale=1)
content_1.x = 10
content_1.y = 40
contents.append(content_1)

content_2 = label.Label(font, text=text_2, color=0xffffff, scale=1)
content_2.x = 10
content_2.y = 65
contents.append(content_2)

content_3 = label.Label(font, text=text_3, color=0xffffff, scale=1)
content_3.x = 10
content_3.y = 90
contents.append(content_3)

screen.show(contents)
while True:
 pass

The effect is as shown below:

Task 3: Controlling the WS2812B

Task requirements: Use buttons to control the display and color switching of the onboard Neopixel LED

Design idea: Set the number and brightness of the lamp beads. After initializing the lamp beads and buttons, obtain random values as RGB values by setting the button function, and use this RGB value as the color display of the lamp beads.

Import the required libraries

import board
import time
import neopixel
import digitalio
import random
from adafruit_led_animation.animation.blink import Blink

Set WS2812B, number of lamp beads, brightness

led = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1, auto_write=False, pixel_order=neopixel.GRB)

Initialize display mode

display = Blink(led, speed=0.5, color=(0, 0, 0))

Initialize button function

button = digitalio.DigitalInOut(board.BOOT0)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

Initialize RGB random numbers

g_num = r_num = b_num = 0

When the button is pressed, a random color is selected and flashes

while True:
 if not button.value:
 g_num = random.randrange(0, 256)
 r_num = random.randrange(0, 256)
 b_num = random.randrange(0, 256)
 display = Blink(led, speed=0.5, color=(g_num, r_num, b_num))
 else:
 pass
 time.sleep(0.2)
 display.animate()

The effect is as shown below:

Task 4 Task 1: Calendar & Clock

Mission requirements: Complete a perpetual calendar clock that can be updated via the Internet and display local weather information

Design idea: Get time and weather information in JSON format from the Internet, parse it, format it, and display it on the screen

Import the required modules

import os
import board
import displayio
import wifi
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
import socketpool
import adafruit_requests
import ssl

Initialize screen, image group, set font

screen = board.DISPLAY
contents = displayio.Group()
font = bitmap_font.load_font("/font/font.pcf")

Set the URL to get time and weather

time_url = "http://quan.suning.com/getSysTime.do"
weather_url = http://t.weather.sojson.com/api/weather/city/101010100

Use requests to obtain time and weather information in JSON format and parse it

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
time_data = requests.get(time_url).json()['sysTime2'][:-3]
weather_data = requests.get(weather_url).json()

Format and output weather, time, temperature, humidity and other information

text_1 = weather_data['cityInfo']['city'] + '天气'
text_2 = time_data
text_3 = weather_data['data']['forecast'][0]['week']
text_4 = '温度:' + weather_data['data']['wendu'] + '摄氏度'
text_5 = '湿度:' + weather_data['data']['shidu']

Add each information to the image group and complete the display of the image group

content_1 = label.Label(font, text=text_1, color=0xffffff, scale=1)
content_1.x = 10
content_1.y = 15
contents.append(content_1)

content_2 = label.Label(font, text=text_2, color=0xffffff, scale=1)
content_2.x = 10
content_2.y = 40
contents.append(content_2)

content_3 = label.Label(font, text=text_3, color=0xffffff, scale=1)
content_3.x = 10
content_3.y = 65
contents.append(content_3)

content_4 = label.Label(font, text=text_4, color=0xffffff, scale=1)
content_4.x = 10
content_4.y = 90
contents.append(content_4)

content_5 = label.Label(font, text=text_5, color=0xffffff, scale=1)
content_5.x = 10
content_5.y = 115
contents.append(content_5)

screen.show(contents)
while True:
 pass

The effect is as shown below:

Project summary:

Project Introduction:
This project is based on the Adafruit ESP32-S3 TFT Feather development board. The main functions are realized by using the onboard TFT display, WIKFI module and colorful LED lights.

Expected goals of the project:
Complete the control of the TFT display screen and output multiple lines of Chinese display;
complete the use of network functions, and successfully create a hotspot, connect to wifi, and the screen can display hotspot/wifi information;
complete the control of colorful lamp beads, and control random color changes through buttons;
complete the comprehensive use of the above functions, obtain time and local weather information through wifi, and display it on the screen.

Challenges in the project implementation process
The development board itself has a wealth of onboard modules, and the firmware burning is very simple. Combined with CPY's diverse libraries, the overall difficulty of the project is not high, but there are still two challenges:
1. Preliminary preparation
for the project The preliminary preparation for the project is mainly firmware burning, library importing, and wifi configuration file settings. There are sufficient tutorials for these parts. After careful study, it is relatively smooth. However, due to lack of experience, the library import was not planned in the early stage. The required library was frequently repeated many times. "Write code-find the necessary library-find the corresponding library-import".
2. Solution to Chinese font library
Due to the size of the font library file itself, there is not enough space for onboard storage, so the font file needs to be compressed. This process took a lot of time and took a lot of detours. The solution found at the beginning of the project was to keep only the necessary characters in the font library to reduce the size, but this approach is feasible for mature project development. For novices who are debugging and thinking about what to do next, it may cause the trouble of repeatedly adjusting the font library. After consulting with friends in the group, I found an alternative solution: compress the font library as much as possible and put it into the internal storage while ensuring its integrity. Although the size is still large, it is sufficient for debugging projects.

Summary:
This project is very suitable for beginners like me as the first project to start with. Through this project, I learned the following:
Burning CPY firmware in DFU mode
Importing libraries in DFU mode
Modifying and importing Chinese fonts Editing
the settings.toml configuration file
Calling onboard modules (screen, wifi module, LED)
Creating an image group to display text
Wi-Fi connection
Creating a hotspot
Obtaining information through the requests module
Parsing json information

Experience:
As a newbie, I have always been interested in MCU, but I have no idea, and I can't find a suitable space and channel. This event gave me a good starting point for MCU development: the
project difficulty is reasonable, there are many tutorials, and it is suitable for getting started;
cpy is easy to use, which reduces the difficulty of writing code, and you can spend more energy on learning hardware;
forums and WeChat groups are frequent, and novices can find references and channels for inquiry when they have questions;
reimbursement is used as an incentive, so novices are easy to stick to it.
Although there was a small episode of logistics in this event, the flaws are not enough to hide the merits. Completing this project gave me great confidence to have a deeper understanding of the field of MCU. Thanks to DigiKey and EEWORLD for bringing such a good event. Next time I have the opportunity, I will participate in more projects and learn more skills.

This post is from DigiKey Technology Zone

Latest reply

The project summary is well organized, thumbs up   Details Published on 2023-11-11 07:37
 
 

6580

Posts

0

Resources
2
 

The project summary is well organized, thumbs up

This post is from DigiKey Technology Zone
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list