1275 views|0 replies

1

Posts

1

Resources
The OP
 

Digi-Key Follow me Phase 2 Task Submission Summary [Copy link]

 

Hi everyone, I received this board in October, but I didn't have time to play with it until recently. Most of the friends in the forum used CircuitPython to complete the tasks of this Adafruit ESP32-S3 TFT FeatherCircuitPython, but I am used to writing code in C/C++, so I chose the esp-idf+lvgl solution. Although I did encounter some problems, as my first time writing esp32, I think it is still relatively easy to get started.

Because of the esp-idf solution, you need to configure the environment first. I used Mac+VSCode+esp-idf plug-in to configure it. Overall, it was very smooth. Just follow the official tutorial. For the specific process, please refer to the official tutorial: https://docs.espressif.com/projects/esp-idf/zh_CN/v5.1/esp32s3/get-started/index.html#get-started-how-to-get-esp-idf

After the project was created, the first thing to solve was the screen display problem. Finally, I used the code on github

链接已隐藏,如需查看请登录或者注册
to successfully light up the screen.

Task 1: Control the screen to display Chinese (mandatory task)

First, in order to display Chinese, we need to convert our Chinese fonts. The conversion uses the tool provided by lvgl: https://lvgl.io/tools/fontconverter . The range range can be found at https://jrgraphix.net/research/unicode.php

From here we can get the C array of the converted font

声明字体库
LV_FONT_DECLARE(font_OPPOSans_L_16);
static const lv_font_t *main_font = &font_OPPOSans_L_16;
// 使用字体库并创建要显示的标签
    lv_obj_t *lab_task = lv_label_create(parent);
    lv_obj_set_style_text_font(lab_task, main_font, LV_PART_MAIN);
    lv_label_set_text_fmt(lab_task, "得捷电子Follow me第2期 | 任务1-完成屏幕的控制,并且能显示中文");
    lv_obj_set_width(lab_task, lv_obj_get_width(lv_obj_get_parent(parent)));
    lv_label_set_long_mode(lab_task, LV_LABEL_LONG_SCROLL_CIRCULAR);
    lv_obj_align(lab_task, LV_ALIGN_BOTTOM_MID, 0, 0);

Task 2: Use of network functions (mandatory task)

Complete the use of network functions, be able to create hotspots and connect to WiFi

// 配置热点的参数,设置热点的类型等。。。。
    wifi_config_t wifi_config = {
            .ap = {
                    .ssid = FOLLOME2_ESP_WIFI_SSID,
                    .ssid_len = strlen(FOLLOME2_ESP_WIFI_SSID),
                    .channel = FOLLOME2_ESP_WIFI_CHANNEL,
                    .password = FOLLOME2_ESP_WIFI_PASS,
                    .max_connection = FOLLOME2_MAX_STA_CONN,
                    .authmode = WIFI_AUTH_WPA2_PSK,
                    .pmf_cfg = {
                            .required = true,
                    },
            },
    };

// 
    netif = esp_netif_create_default_wifi_sta();
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
	netif = esp_netif_create_default_wifi_ap();
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
    ESP_ERROR_CHECK(esp_wifi_start());
    esp_netif_ip_info_t ip_info;
    esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"), &ip_info);
    char ip_addr[16];
    inet_ntoa_r(ip_info.ip.addr, ip_addr, 16);

Task 3: Control WS2812B (Required Task)

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

配置WS2812B
#define NEOPIX_GPIO GPIO_NUM_33
#define NEOPIX_PWR_GPIO GPIO_NUM_34
gpio_config_t io_conf = {
                .mode = GPIO_MODE_OUTPUT,
                .pin_bit_mask = (1ULL<<NEOPIX_PWR_GPIO),
                .intr_type = GPIO_INTR_DISABLE,
                .pull_down_en = 0,
                .pull_up_en = 0,
        };
        err = gpio_config(&io_conf);
        if (err != ESP_OK) {
            ESP_LOGE(TAG, "configure GPIO for NEOPIX_PWR failed");
        }

    // 设置LED电源的GPIO引脚的电平为高电平(1)
    err = gpio_set_level(NEOPIX_PWR_GPIO, 1);
    // 配置LED灯带
    led_strip_config_t strip_config = {
            .strip_gpio_num = NEOPIX_GPIO, // LED数据线的GPIO引脚。
            .max_leds = 1, // LED灯带上LED的数量,这里设置为1。
            .led_pixel_format = LED_PIXEL_FORMAT_GRB, // LED的像素格式为GRB。
            .led_model = LED_MODEL_WS2812, // LED灯带的型号。
            .flags.invert_out = false, // 输出信号是否翻转,这里设置为不翻转。
    };
    // 配置RMT(Remote Control)控制器。
    led_strip_rmt_config_t rmt_config = {
            .clk_src = RMT_CLK_SRC_DEFAULT, // 时钟源设置为默认值。
            .resolution_hz = 10 * 1000 * 1000, // RMT的分辨率为10MHz。
            .flags.with_dma = false, // whether to enable the DMA feature
    };
    // 初始化LED灯带设备,并将配置参数传递给它。
    ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));

设置LED灯带上的第0个像素的颜色,并刷新LED灯带
    led_strip_set_pixel(led_strip, 0, r, g, b);
    led_strip_refresh(led_strip);

Task 4: Choose 1 task you are interested in from the 5 tasks below and complete it (mandatory task)

Subtask 1: Calendar & Clock - Complete a perpetual calendar clock that can be updated via the Internet and display local weather information

Recommended device: Adafruit ESP32-S3 TFT Feather

配置网络接入点,把网络切换成WIFI_MODE_STA模式,
配置sntp同步时间
    esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
    esp_sntp_setservername(0, "ntp.aliyun.com");
    esp_sntp_setservername(1, "time.asia.apple.com");
    esp_sntp_setservername(2, "pool.ntp.org");
    sntp_set_time_sync_notification_cb(time_sync_notification_cb);
	esp_sntp_init();
天气从http://d1.weather.com.cn/weather_index/{city code}.html获取,需要添加referer
类似curl http://d1.weather.com.cn/weather_index/101020100.html -e http://www.weather.com.cn/
// 配置请求
	char *response = calloc(8192, sizeof(char));
    esp_http_client_config_t config = {
            .url = WEATHER_URL,
            .event_handler = _http_event_handler,
            .crt_bundle_attach = esp_crt_bundle_attach,
            .buffer_size = 8192 * sizeof(char),
            .user_data = response,
            .user_agent = USER_AGENT
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    esp_http_client_set_header(client, "Referer", WEATHER_REFERER);
    esp_err_t err = esp_http_client_perform(client);
// 获取请求返回内容
        int64_t len = esp_http_client_get_content_length(client);
        ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %"PRId64,
                 esp_http_client_get_status_code(client),
                 len
        );
        response[len] = '\0';
        ESP_LOGI(TAG, "Response: %s", response);
    esp_http_client_cleanup(client);
// 解析请求转json
    char *json = NULL;
    jparse_ctx_t *jctx = NULL;
    char* pStart = strstr(response, "var dataSK =");
    pStart += 12;
    char* pEnd = strstr(pStart, "};");
    pEnd += 1;
    int len = pEnd - pStart;
    json = malloc(len + 1);
    memcpy(json, pStart, len);
    json[len] = '\0';
    free(response);
    response = NULL;
    jctx = (jparse_ctx_t *)malloc(sizeof(jparse_ctx_t));
    int ret = json_parse_start(jctx, json, strlen(json));
    if (ret != OS_SUCCESS) {
        ESP_LOGE(TAG, "json_parse_start failed\n");
        goto exception;
    }

Video : https://training.eeworld.com.cn/video/38432

Code package : https://download.eeworld.com.cn/detail/jakeli/629880

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