401 views|3 replies

9

Posts

1

Resources
The OP
 

Digi-Key Follow me Second Issue Summary [Copy link]

 

Mission Report Video

https://training.eeworld.com.cn/video/38391

First of all, I am a freshman. I saw Long Ge's video on B station and was quite interested in it. I waited for the board for 2 months. In early October , the board finally arrived. Later, I completed the required tasks intermittently. I didn't do the optional tasks because I was too busy with school. I also thank EEworld community and Digi-Key Electronics for giving me this opportunity. The board is really beautiful and exquisite.

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 1 Preliminary preparations:

  1. Espressif Burning Tool
  2. Factory firmware Adafruit_Feather_ESP32S3_TFT_FactoryTest.bi
  3. CircuitPython Firmware
  4. IDE (I use Thonny)
  5. Font Files

Here are the specific steps:

  1. Connect the board to the computer. When you connect the board for the first time, the original interface will be displayed, which contains information such as battery voltage and power.
  2. Next, press the ret button twice to enter DFU state
  1. Then a USB drive named FTHRS3BOOT will pop up on the computer.
  2. Drag the pre-downloaded circuitpython firmware into the USB drive. As long as the file is copied, the burning is successful. No other software or other operations are required. It is more convenient than other boards I have played with.
  3. Because we need to display Chinese, we need to call two library files, adafruit_display_text and adafruit_bitmap_font, drag them to the lib folder under FTHRS3BOOT
  4. Next, create a new folder in FTHRS3BOOT, name it fonts, drag the downloaded font file into it, pay attention to the size, and do not use fonts that take up too much space.
  5. The next step is to write the program. The program is very simple, but the challenging part is to adjust it slowly, such as font, position, color, etc., to achieve the best effect.
    import board
    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 = 0x11ff11//定义颜色
    
    text2 = "浙江工商大学"//文本内容
    scale = 2//定义字体大小
    
    text_area2 = bitmap_label.Label(font,text=text2,scale=scale)
    text_area2.x = 10//控制文本的位置
    text_area2.y = 30
    board.DISPLAY.show(text_area2)
    
    while True:
     pass
    

    The following are the files used

adafruit-circuitpython-adafruit_feather_esp32s3_tft-en_US-8.2.3.uf2 (2.68 MB, downloads: 0) Adafruit_Feather_ESP32S3_TFT_FactoryTest.uf2 (638.5 KB, downloads: 0) wenquanyi_10pt.pcf (2.18 MB, downloads: 0) thonny-4.1.1.exe (20.85 MB, downloads: 0) flash_download_tool_3.9.5_0.zip (19.62 MB, downloads: 0)

Task 2: Network Function Usage

Because the campus network requires school account authentication and cannot be connected with a simple SSID and password, this period was completed at home.

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

Based on Task 1, we don't need any preliminary preparation, just type the code.

The following are the specific steps:

1. Create a hotspot

We only need to import the two libraries os and wifi, and then write the statement wifi.radio.start_ap

Directly on the code

import os
import wifi

 
wifi.radio.start_ap('ESP', '00000000')

Yes, it is very simple. The hotspot is now started. The first part of the brackets in the last line of code is the hotspot name, and the second part is the hotspot password. You can modify it yourself.

2. Connect to WiFi

Since this can also be done with one line of code, I decided to combine Task 2 with Task 1 so that some text can be displayed when the board is connected to WiFi.

It is also a library for more than 100 people.

Here is the code

import board                                         //第一个任务所需要的库
import terminalio
from adafruit_display_text import bitmap_label
from adafruit_bitmap_font import bitmap_font

import os                                            //第二个任务所需要的库
import wifi


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

color = 0x00ff00

wifi.radio.connect('WiFi名称', 'WiFi密码')             //你家的Wi-Fi名称和密码,可别真写这个进去

txt= "Wi-Fi已成功连接\n 重生之\n 我变成了ESP32 "

scale = 2                                             //下面的都是用来控制字体显示的具体数值

text_area = bitmap_label.Label(font,text=txt,scale=scale)
text_area.x = 8
text_area.y = 10


while True:
 pass

You can see that the connection has been successful

Task 3: Controlling the WS2812B

This task was completed during the evening study session on October 23.

[Digi-Key Follow Me Issue 2] Task 3: Control WS2812B

The main task of this task is to use the button to control the change of the lamp bead on the board. In fact, there is only one lamp bead and two buttons, but one of them is rst, so in the end one button controls one lamp bead.

A light can also produce many effects, such as controlling the flashing through a delay function, controlling the color with code, and so on.

In this task, I imported the official neopixel library and adafruit_led_animation library, which are mainly used to control the on and off of the light and the length of time it stays on.

When I thought everything was fine, the program did not run through. After checking the big guy's information, I found that I did not read the buttons and control the io port.

Careless

So we also need to call the library digitalio and library board

The following is the specific code. I have written my understanding in the comments. I hope you can correct me.

import board                                      //检测按键的库
import digitalio
import time                                       //控灯的库
import neopixel
from adafruit_display_text import label           //任务一的文字显示库(老常客了)
from adafruit_bitmap_font import bitmap_font


pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.brightness = 0.8                            //控制亮度

button = digitalio.DigitalInOut(board.BUTTON)     //初始化按键对象
button.direction = digitalio.Direction.INPUT      //设置按键为输入
button.pull = digitalio.Pull.UP                   //将按键设置为上拉
but_in=3

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

display = board.DISPLAY
font_file = "fonts/wenquanyi_10pt.pcf"             //加载任务一所用字体

font = bitmap_font.load_font(font_file)



      
def button():                                      //定义了一个按键函数
    global but_in
    if(not button.value):                          //按键没按下执行的操作
        but_in=but_in+1
    if (but_in>3):                                 //按键没按下执行的操作
        but_in=0
    
def dispinfo(str):                                 //又定义了一个灯光函数
    if(str=="RED"):
        color = 0xFF0000
        text_area = label.Label(font, text="红色", color=color)
        text_area.x = 80
        text_area.y = 60
        scale = 2
        display.show(text_area)
        pixel.fill(color)
        
    elif(str=="GREEN"):
        color = 0x00FF00
        text_area = label.Label(font, text="绿色", color=color)
        text_area.x = 80
        text_area.y = 60
        scale = 2
        pixel.fill(color)
   
    elif(str=="BLUE"):
        color = 0x0000FF
        text_area = label.Label(font, text="蓝色", color=color)
        text_area.x = 80
        text_area.y = 60
        scale = 2
        pixel.fill(color)
    else :
        color = 0xFFFFFF
        text_area = label.Label(font, text="按下按键以开始", color=color)
        text_area.x = 80
        text_area.y = 60
        scale = 2
        pixel.fill(color)
                                                    //分别输出红绿蓝
        display.show(text_area)
  

while True:                                         //最终输出的执行语句
    colbutton()
    if(but_in==0):
        dispinfo("RED")
    elif(but_in==1):
        dispinfo("BLUE")
    elif(but_in==2):
        dispinfo("GREEN")
    else:
        dispinfo("START")
 
   time.sleep(0.5)                                 //延时
   

Task 4: Subtask 1: Calendar & Clock

After a week, I found that subtask one of task four was indeed more difficult than the previous ones. I have been studying related knowledge in the last few evening self-study sessions.

I found that it is quite troublesome to implement the weather API call. After looking at the examples of the big guys, I learned that I can use the APIs of Amap and Xinzhi Weather. However, these require registration to obtain the key, which is quite troublesome.

We can use the free API interface provided by this website

https://www.sojson.com/api/weather.html

This requires us to obtain the city code of our city

Here is a corresponding table for you

链接已隐藏,如需查看请登录或者注册
Extraction code:

  • u8sk

After we get the returned JSON string, we need to further parse it and add various names in front of it, such as air quality, etc., so that the content can be read normally

This is the specific code below

One more thing, as the tasks progress, we need to import more and more library files, but the memory of the board is really limited, 2mb, and the previous font files are too large, so even the library cannot be dragged in.

I had to change the font. It seems that I still have to make my own font. It is not easy to control the memory prepared by the big guys, and I lose sight of the big picture.

In general, this is the content of the second issue of Digi-Key Electronics Follow me summary post, which includes four tasks: controlling the screen to display Chinese, using network functions, controlling WS2812B and calendar & clock. In each task, I have introduced the preliminary preparations and specific steps in detail. Among them, Task 1 requires calling two library files to control the screen to display Chinese, Task 2 requires creating a hotspot and connecting to WiFi, Task 3 requires controlling the changes of WS2812B lamp beads, and Task 4 requires obtaining city codes to implement weather API calls.

As a student majoring in electronic information, this kind of activity is both an incentive and a reward. After all, you can't learn anything in class. You still have to learn by yourself, practice by yourself, and gain your own insights. Below are the links to my various tasks. Thanks again to EEworld and Digi-Key Electronics for hosting this event.

Task 1: https://en.eeworld.com/bbs/thread-1260113-1-1.html

Task 2: https://en.eeworld.com/bbs/thread-1260316-1-1.html

Task 3: https://en.eeworld.com/bbs/thread-1260503-1-1.html

Task 4: https://en.eeworld.com/bbs/thread-1261095-1-1.html

Task 2 supplementary video https://training.eeworld.com.cn/video/38558

Task 4 supplementary video https://training.eeworld.com.cn/video/38559

The code is still under review

Approved, posted in the comments area

Code package: https://download.eeworld.com.cn/detail/Ykern/629871

This post is from DigiKey Technology Zone
 
 

9

Posts

1

Resources
2
 

https://download.eeworld.com.cn/detail/Ykern/629871

This post is from DigiKey Technology Zone

Comments

This is the link to the code  Details Published on 2023-11-25 23:16
 
 
 

9

Posts

1

Resources
3
 

This is the supplementary video of Task 2 after returning home https://training.eeworld.com.cn/video/38558

This is the supplementary video of Task 4 after returning home https://training.eeworld.com.cn/video/38559

This post is from DigiKey Technology Zone
 
 
 

9

Posts

1

Resources
4
 
Ykern published on 2023-11-15 15:13 https://download.eeworld.com.cn/detail/Ykern/629871

This is the link to the code

This post is from DigiKey Technology Zone
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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