[Digi-Key Follow me Issue 2] Task submission (continuously updated...)
[Copy link]
1. Task Selection
Task 1: Control the screen to display Chinese (mandatory task)
Complete the screen control and display Chinese
Matched device: Adafruit ESP32-S3 TFT Feather
Task 2: Use the network function (mandatory task)
Complete the use of network functions, be able to create a hotspot and connect to WiFi.
Matching device: Adafruit ESP32-S3 TFT Feather
Task 3: Control WS2812B (required task)
Use buttons to control the display and color switching of the onboard Neopixel LED
Matched device: Adafruit ESP32-S3 TFT Feather
Task 4: Choose 1 task you are interested in from the 5 tasks below and complete it (mandatory task)
■ Subtask 2: WS2812B effect control - complete a Neopixel (12 or more LEDs) controller, and display the effect through buttons and screen switching
Recommended devices: Adafruit ESP32-S3 TFT Feather, addressable RGB LED
Mission demonstration videos : Please go to the 5th floor of this post to watch
2. Task 1: Control the screen to display Chinese
To control the display of Chinese on the screen, the main focus is on the selection and production of the Chinese font library. In order to call it faster and occupy less space, we need to use the FontForge tool to edit the font library and save it as a .PCF file.
Then specify the location of the display library in the code, and save the text to be displayed in a text file. A simple experiment is to display two lines of "Monday: Sunny" alternately in light green and white at the positions (50,50) and (30,20) of the screen for two seconds.
Word, the code is as follows:
import board,time
from adafruit_display_text import bitmap_label
import terminalio
from adafruit_bitmap_font import bitmap_font
font = bitmap_font.load_font("font\sytq_16.pcf")
color = 0x00fa00
text2 = "周一:晴"
scale = 2
while True:
text_area2 = bitmap_label.Label(font,text=text2,scale=scale, color=color)
text_area2.x = 50
text_area2.y = 50
board.DISPLAY.show(text_area2)
time.sleep(2)
text_area3 = bitmap_label.Label(font,text=text2,scale=scale, color=0xffffff)
text_area3.x = 30
text_area3.y = 20
board.DISPLAY.show(text_area3)
time.sleep(2)
The Chinese display video is as follows:
中文显示
3. Task 2: Use of network functions
Experiment 1: Turn on the hotspot on your phone, connect to the hotspot with the experiment board and print the IP address.
import ssl, wifi, time
print("ESP32-S3 network test")
print("MAC地址:",[hex(i) for i in wifi.radio.mac_address])
while not wifi.radio.connected:
print("connetting ...")
time.sleep(1)
print("wiFi is conneted!")
print("IP地址",wifi.radio.ipv4_address)
while True:
pass
The printout is as follows:
Experiment 2: Use the development board to set up AP and use a mobile phone to connect to the development board's wifi.
import board
import wifi
SSID = "esp_a0"
PASSWORD = "12345abc"
wifi.radio.start_ap(SSID,PASSWORD)
print("WiFi:",SSID)
print("PASSWORD:",PASSWORD)
while True:
pass
IV. Task 3: Control WS2812B (Required Task)
This experiment combines the use of buttons. When the button is pressed, the status of the button is changed. If it is pressed, pixel_status is used to record it. A loop is made, and then the different colors of RGBWS2812B are controlled . If the button is not pressed, the ADC is used to sample the temperature module TMP235 and print out the corresponding temperature.
code show as below
import board
import time
import digitalio
import analogio
import neopixel
# WS2812B 电源控制
power = digitalio.DigitalInOut(board.NEOPIXEL_POWER)
power.direction = digitalio.Direction.OUTPUT
power.value = True
# WS2812B设置
pixel = neopixel.NeoPixel(board.NEOPIXEL,1)
#亮度
pixel.brightness = 0.5
led=digitalio.DigitalInOut(board.LED)
led.direction=digitalio.Direction.OUTPUT
#led.switch_to_output()
# board.BUTTON 与 board.BOOTO 等同
button = digitalio.DigitalInOut(board.BUTTON)
button.switch_to_input(pull=digitalio.Pull.UP)
#模拟输入 TMP235 温度传感器 T=V*100-50
analog_pin = analogio.AnalogIn(board.A1)
#普通按键状态
status = False
t=0
colour=0
pixel_status =0
while 1:
if not button.value:
if status==False:
print("Press down")
status= True
led.value=status
if pixel_status==0:
pixel.fill((125,0,0))# red: (255,0,0)
print("pixel_status is:",pixel_status)
if pixel_status==1:
pixel.fill((0,125,0))# green: (0,255,0)
print("pixel_status is:",pixel_status)
if pixel_status==2:
pixel.fill((0,0,125))# blue: (0,0,255)
print("pixel_status is:",pixel_status)
if pixel_status==3:
pixel.fill((0,125,125))# cyan: (0,255,255)
print("pixel_status is:",pixel_status)
if pixel_status==4:
pixel.fill((125,0,125))# purple: (255,0,255)
print("pixel_status is:",pixel_status)
if pixel_status==5:
pixel.fill((125,125,0))# yellow: (255,255,0)
print("pixel_status is:",pixel_status)
if pixel_status==6:
pixel.fill((125,125,125))# white: (255,255,255)
print("pixel_status is:",pixel_status)
if pixel_status==7:
pixel.fill((0,0,0))# black (off): (0,0,0)
print("pixel_status is:",pixel_status)
if pixel_status<7:
pixel_status=pixel_status+1
else:
pixel_status=0
else:
status=False
led.value=status
while(t==100):
print("DC value is:",analog_pin.value)
Tempt = analog_pin.value*3.3/65535*100-50
print("Tempt is", Tempt)
t=0
print("pixel_status is:",pixel_status-1)
break
t=t+1
time.sleep(0.01)
The test video is as follows:
按键控制板载REB灯
5. Task 4: Sub-task 2: WS2812B effect control - Complete a Neopixel (12 or more LEDs) controller and display the effect by pressing buttons and switching the screen
Following Task 3 , increase the number of WS2812B to 16 and display the color of the RGB light on the display.
Here I change the fill color of a circle to change the displayed color. Each time you change the fill color, you need to add it back to shape_group.
circle = Circle(x0=200,y0=60,r=30,fill=CYAN,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
Please note that if characters and graphics are displayed at the same time, the previous one will be overwritten, and text_grouo and shape_group cannot be added to each other. You can only discard the characters.
The test code is as follows:
import board
import time
import digitalio
import analogio
import neopixel
#屏幕像素 240(长)*135(高)
import terminalio,displayio
from adafruit_display_text import label
from adafruit_display_shapes.circle import Circle
#普通按键状态
status = False
t=0
colour=0
pixel_status =0
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255, 0)
PURPLE = (180, 0, 255)
WHITE = (255,255,255)
BLACK = (0,0,0)
# 1。屏幕基础配置
display = board.DISPLAY
#2。显示文本
text= "The neopixel test!"
text_area = label.Label(terminalio.FONT, text=text, color=0xFF0000, x=20 , y=20)
text_group = displayio.Group(scale=2,x=0,y=0)
text_group.append(text_area)
display.show(text_group)
# Subgroup for text scaling
#圆
#黑背景,白外框,内填RGB显示颜色
shape_group = displayio.Group()
circle = Circle(x0=200,y0=60,r=30,fill=BLACK,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
# WS2812B设置 数据口选择为A1
#pixel = neopixel.NeoPixel(board.A1,16)
pixel = neopixel.NeoPixel(board.A1, 16, brightness=0.1)
#亮度
#pixel.brightness = 0.5
led=digitalio.DigitalInOut(board.LED)
led.direction=digitalio.Direction.OUTPUT
#led.switch_to_output()
# board.BUTTON 与 board.BOOTO 等同
button = digitalio.DigitalInOut(board.BUTTON)
button.switch_to_input(pull=digitalio.Pull.UP)
#模拟输入 TMP235 温度传感器 T=V*100-50
analog_pin = analogio.AnalogIn(board.A0)
while 1:
if not button.value:
if status==False:
print("Press down")
status= True
led.value=status
if pixel_status==0:
pixel.fill(RED)# red: (255,0,0)
circle = Circle(x0=200,y0=60,r=30,fill=RED,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status==1:
pixel.fill(GREEN)# green: (0,255,0)
circle = Circle(x0=200,y0=60,r=30,fill=GREEN,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status==2:
pixel.fill(BLUE)# blue: (0,0,255)
circle = Circle(x0=200,y0=60,r=30,fill=BLUE,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status==3:
pixel.fill(CYAN)# cyan: (0,255,255)
circle = Circle(x0=200,y0=60,r=30,fill=CYAN,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status==4:
pixel.fill(PURPLE)# purple: (255,0,255)
circle = Circle(x0=200,y0=60,r=30,fill=PURPLE,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status==5:
pixel.fill(YELLOW)# yellow: (255,255,0)
circle = Circle(x0=200,y0=60,r=30,fill=YELLOW,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status==6:
pixel.fill(WHITE)# white: (255,255,255)
circle = Circle(x0=200,y0=60,r=30,fill=WHITE,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status==7:
pixel.fill(BLACK)# black (off): (0,0,0)
circle = Circle(x0=200,y0=60,r=30,fill=BLACK,outline=0xFFFFFF)
shape_group.append(circle)
display.show(shape_group)
print("pixel_status is:",pixel_status)
if pixel_status<7:
pixel_status=pixel_status+1
else:
pixel_status=0
else:
status=False
# display.show(shape_group)
led.value=status
while(t==100):
print("DC value is:",analog_pin.value)
Tempt = analog_pin.value*3.3/65535*100-50
print("Tempt is", Tempt)
t=0
print("pixel_status is:",pixel_status-1)
break
t=t+1
time.sleep(0.01)
Video below
多RGB显示
VI. Summary:
I have always wanted to play with ESP32, but I have been putting it aside because other materials all use official routines and the development environment is not good. This time, eeworld and Digi-Key provided a Feather development board, which has a complete development environment and materials, and uses CircuitPython for development. CircuitPython provides many libraries, which is very friendly to rookies like me. I hope that Digi-Key will provide more fun development boards in the third issue of Follow Me, so that I can learn and play with netizens in the forum. Finally, I would like to thank eeworld and Digi-Key for providing this opportunity.
7. Program code submission
|