2024-3-23 22:26:43 [显示全部楼层]
295浏览
查看: 295|回复: 5

[ESP8266/ESP32] FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕

[复制链接]
本帖最后由 aramy 于 2024-3-24 20:56 编辑

很开心收到了试用产品:FireBeetle 2 ESP32 C6开发板。这个板子支持 Wi-Fi 6,蓝牙 5,Zigbee 3.0,Thread 1.3通讯协议,太阳能充电。
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图1
这个开发板是属于FireBeetle 2系列的开发板,板子上有个GDI接口。手上有一个自制的FireBeetle 2的扩展板。扩展板上有SHT30、SD卡和一个1.47寸TFT显示屏,屏幕是IPS屏,172*320 SPI接口ST7789驱动。这里将扩展板装上,扩展板上有个摄像头,这里暂时不用。先用这个板子点亮屏幕玩一下。
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图2

FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图3
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图4
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图5
到手,就开始尝试点亮屏幕。
  • 使用ESP-IDF点亮屏幕
电脑上安装有ESP-IDF4.4.6环境,但是在Vscode里选择硬件,居然没有esp32-c6,看来是芯片太新了,重新安装esp-idf5.1.2版本,然后就有esp32-c6芯片选择了。
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图6
选择例程,使用HELLO_WORLD例程。esp-idf5以后开始使用组件了,修改芯片类型,然后在main文件夹里创建 idf_component.yml文件。
  1. dependencies:
  2.   espressif/esp_lvgl_port: "^1.4.0"
复制代码
使用这个配置,自动加载lvgl。将加载的组件里例程中的main.c整个复制到hello_world_main.c文件里。系统默认的就是使用st7789的驱动。
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图7
修改几个地方:1、删掉触摸屏部分的代码。2、修改SPI驱动,使用SPI2_HOST。3、修改管脚,使用FireBeetle的管脚对应。
  1. #include "esp_err.h"
  2. #include "esp_log.h"
  3. #include "esp_check.h"
  4. #include "driver/i2c.h"
  5. #include "driver/gpio.h"
  6. #include "driver/spi_master.h"
  7. #include "esp_lcd_panel_io.h"
  8. #include "esp_lcd_panel_vendor.h"
  9. #include "esp_lcd_panel_ops.h"
  10. #include "esp_lvgl_port.h"
  11. /* LCD size */
  12. #define EXAMPLE_LCD_H_RES   (172)
  13. #define EXAMPLE_LCD_V_RES   (320)
  14. /* LCD settings */
  15. #define EXAMPLE_LCD_SPI_NUM         (SPI2_HOST)
  16. #define EXAMPLE_LCD_PIXEL_CLK_HZ    (40 * 1000 * 1000)
  17. #define EXAMPLE_LCD_CMD_BITS        (8)
  18. #define EXAMPLE_LCD_PARAM_BITS      (8)
  19. #define EXAMPLE_LCD_COLOR_SPACE     (ESP_LCD_COLOR_SPACE_BGR)
  20. #define EXAMPLE_LCD_BITS_PER_PIXEL  (16)
  21. #define EXAMPLE_LCD_DRAW_BUFF_DOUBLE (1)
  22. #define EXAMPLE_LCD_DRAW_BUFF_HEIGHT (50)
  23. #define EXAMPLE_LCD_BL_ON_LEVEL     (1)
  24. /* LCD pins */
  25. #define EXAMPLE_LCD_GPIO_SCLK       (GPIO_NUM_23)
  26. #define EXAMPLE_LCD_GPIO_MOSI       (GPIO_NUM_22)
  27. #define EXAMPLE_LCD_GPIO_RST        (GPIO_NUM_14)
  28. #define EXAMPLE_LCD_GPIO_DC         (GPIO_NUM_8)
  29. #define EXAMPLE_LCD_GPIO_CS         (GPIO_NUM_1)
  30. #define EXAMPLE_LCD_GPIO_BL         (GPIO_NUM_15)
  31. /* Touch settings */
  32. #define EXAMPLE_TOUCH_I2C_NUM       (0)
  33. #define EXAMPLE_TOUCH_I2C_CLK_HZ    (400000)
  34. /* LCD touch pins */
  35. #define EXAMPLE_TOUCH_I2C_SCL       (GPIO_NUM_18)
  36. #define EXAMPLE_TOUCH_I2C_SDA       (GPIO_NUM_8)
  37. #define EXAMPLE_TOUCH_GPIO_INT      (GPIO_NUM_3)
  38. static const char *TAG = "EXAMPLE";
  39. /* LCD IO and panel */
  40. static esp_lcd_panel_io_handle_t lcd_io = NULL;
  41. static esp_lcd_panel_handle_t lcd_panel = NULL;
  42. /* LVGL display and touch */
  43. static lv_disp_t *lvgl_disp = NULL;
  44. static esp_err_t app_lcd_init(void)
  45. {
  46.     esp_err_t ret = ESP_OK;
  47.     /* LCD backlight */
  48.     gpio_config_t bk_gpio_config = {
  49.         .mode = GPIO_MODE_OUTPUT,
  50.         .pin_bit_mask = 1ULL << EXAMPLE_LCD_GPIO_BL
  51.     };
  52.     ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));
  53.     /* LCD initialization */
  54.     ESP_LOGD(TAG, "Initialize SPI bus");
  55.     const spi_bus_config_t buscfg = {
  56.         .sclk_io_num = EXAMPLE_LCD_GPIO_SCLK,
  57.         .mosi_io_num = EXAMPLE_LCD_GPIO_MOSI,
  58.         .miso_io_num = GPIO_NUM_NC,
  59.         .quadwp_io_num = GPIO_NUM_NC,
  60.         .quadhd_io_num = GPIO_NUM_NC,
  61.         .max_transfer_sz = EXAMPLE_LCD_H_RES * EXAMPLE_LCD_DRAW_BUFF_HEIGHT * sizeof(uint16_t),
  62.     };
  63.     ESP_RETURN_ON_ERROR(spi_bus_initialize(EXAMPLE_LCD_SPI_NUM, &buscfg, SPI_DMA_CH_AUTO), TAG, "SPI init failed");
  64.     ESP_LOGD(TAG, "Install panel IO");
  65.     const esp_lcd_panel_io_spi_config_t io_config = {
  66.         .dc_gpio_num = EXAMPLE_LCD_GPIO_DC,
  67.         .cs_gpio_num = EXAMPLE_LCD_GPIO_CS,
  68.         .pclk_hz = EXAMPLE_LCD_PIXEL_CLK_HZ,
  69.         .lcd_cmd_bits = EXAMPLE_LCD_CMD_BITS,
  70.         .lcd_param_bits = EXAMPLE_LCD_PARAM_BITS,
  71.         .spi_mode = 0,
  72.         .trans_queue_depth = 10,
  73.     };
  74.     ESP_GOTO_ON_ERROR(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)EXAMPLE_LCD_SPI_NUM, &io_config, &lcd_io), err, TAG, "New panel IO failed");
  75.     ESP_LOGD(TAG, "Install LCD driver");
  76.     const esp_lcd_panel_dev_config_t panel_config = {
  77.         .reset_gpio_num = EXAMPLE_LCD_GPIO_RST,
  78.         .color_space = EXAMPLE_LCD_COLOR_SPACE,
  79.         .bits_per_pixel = EXAMPLE_LCD_BITS_PER_PIXEL,
  80.     };
  81.     ESP_GOTO_ON_ERROR(esp_lcd_new_panel_st7789(lcd_io, &panel_config, &lcd_panel), err, TAG, "New panel failed");
  82.     esp_lcd_panel_reset(lcd_panel);
  83.     esp_lcd_panel_init(lcd_panel);
  84.     esp_lcd_panel_mirror(lcd_panel, true, true);
  85.     esp_lcd_panel_disp_on_off(lcd_panel, true);
  86.     /* LCD backlight on */
  87.     ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_LCD_GPIO_BL, EXAMPLE_LCD_BL_ON_LEVEL));
  88.     return ret;
  89. err:
  90.     if (lcd_panel) {
  91.         esp_lcd_panel_del(lcd_panel);
  92.     }
  93.     if (lcd_io) {
  94.         esp_lcd_panel_io_del(lcd_io);
  95.     }
  96.     spi_bus_free(EXAMPLE_LCD_SPI_NUM);
  97.     return ret;
  98. }
  99. static esp_err_t app_lvgl_init(void)
  100. {
  101.     /* Initialize LVGL */
  102.     const lvgl_port_cfg_t lvgl_cfg = {
  103.         .task_priority = 4,         /* LVGL task priority */
  104.         .task_stack = 4096,         /* LVGL task stack size */
  105.         .task_affinity = -1,        /* LVGL task pinned to core (-1 is no affinity) */
  106.         .task_max_sleep_ms = 500,   /* Maximum sleep in LVGL task */
  107.         .timer_period_ms = 5        /* LVGL timer tick period in ms */
  108.     };
  109.     ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL port initialization failed");
  110.     /* Add LCD screen */
  111.     ESP_LOGD(TAG, "Add LCD screen");
  112.     const lvgl_port_display_cfg_t disp_cfg = {
  113.         .io_handle = lcd_io,
  114.         .panel_handle = lcd_panel,
  115.         .buffer_size = EXAMPLE_LCD_H_RES * EXAMPLE_LCD_DRAW_BUFF_HEIGHT * sizeof(uint16_t),
  116.         .double_buffer = EXAMPLE_LCD_DRAW_BUFF_DOUBLE,
  117.         .hres = EXAMPLE_LCD_H_RES,
  118.         .vres = EXAMPLE_LCD_V_RES,
  119.         .monochrome = false,
  120.         /* Rotation values must be same as used in esp_lcd for initial settings of the screen */
  121.         .rotation = {
  122.             .swap_xy = false,
  123.             .mirror_x = false,
  124.             .mirror_y = true,
  125.         },
  126.         .flags = {
  127.             .buff_dma = true,
  128.         }
  129.     };
  130.     lvgl_disp = lvgl_port_add_disp(&disp_cfg);
  131.     return ESP_OK;
  132. }
  133. static void _app_button_cb(lv_event_t *e)
  134. {
  135.     lv_disp_rot_t rotation = lv_disp_get_rotation(lvgl_disp);
  136.     rotation++;
  137.     if (rotation > LV_DISP_ROT_270) {
  138.         rotation = LV_DISP_ROT_NONE;
  139.     }
  140.     /* LCD HW rotation */
  141.     lv_disp_set_rotation(lvgl_disp, rotation);
  142. }
  143. static void app_main_display(void)
  144. {
  145.     lv_obj_t *scr = lv_scr_act();
  146.     /* Task lock */
  147.     lvgl_port_lock(0);
  148.     /* Your LVGL objects code here .... */
  149.     /* Label */
  150.     lv_obj_t *label = lv_label_create(scr);
  151.     lv_label_set_recolor(label, true);
  152.     lv_obj_set_width(label, EXAMPLE_LCD_H_RES);
  153.     lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
  154.     lv_label_set_text(label, "#FF0000 "LV_SYMBOL_BELL" Hello world Espressif and LVGL "LV_SYMBOL_BELL"#\n#FF9400 "LV_SYMBOL_WARNING" For simplier initialization, use BSP "LV_SYMBOL_WARNING" #");
  155.     lv_obj_align(label, LV_ALIGN_CENTER, 0, -30);
  156.     /* Button */
  157.     lv_obj_t *btn = lv_btn_create(scr);
  158.     label = lv_label_create(btn);
  159.     lv_label_set_text_static(label, "Rotate screen");
  160.     lv_obj_align(btn, LV_ALIGN_BOTTOM_MID, 0, -30);
  161.     lv_obj_add_event_cb(btn, _app_button_cb, LV_EVENT_CLICKED, NULL);
  162.     /* Task unlock */
  163.     lvgl_port_unlock();
  164. }
  165. void app_main(void)
  166. {
  167.     /* LCD HW initialization */
  168.     ESP_ERROR_CHECK(app_lcd_init());
  169.     /* LVGL initialization */
  170.     ESP_ERROR_CHECK(app_lvgl_init());
  171.     /* Show LVGL objects */
  172.     app_main_display();
  173. }
复制代码
编译、烧写,屏幕能点亮,但是字体恨不清晰,这里修改一下LVGL的高低字节关系。
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图8
再次烧写,还是有问题。屏幕颜色还是不对,图形有偏移。要想修正这些问题,需要修改ST7789的驱动,但是组件文件貌似修改会报错好烦!先这样吧!
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图9


使用arduino,第一选择自然是vscode+platformio。但是很可惜,在vscode里找了半天没有ESP32-C6这款开发板。切换编辑器,使用Arduino1.8.16。首先按DFROBOT的介绍,安装esp32的编程环境(提供的服务器需要梯子,很难安装成功),参考群里老师,更换服务器:https://djzrs.github.io/picx-ima ... sp32_dev_index.json。安装开发板esp32.
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图15
再安装GDL的库(https://gitee.com/dfrobot/DFRobot_GDL),参考DR0649这个屏幕,使用官方的例程,将例程中的管脚修改为自己的C6的管脚。
  1. #include "DFRobot_GDL.h"
  2. #define TFT_DC  8
  3. #define TFT_CS  1
  4. #define TFT_RST 14
  5. DFRobot_ST7789_172x320_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);
  6. void setup() {
  7.   Serial.begin(115200);
  8.   screen.begin();//生成了screen对象
  9. }
  10. void loop(){
  11.     testDrawPixel();
  12.     testLine();
  13.     testFastLines(COLOR_RGB565_PURPLE,COLOR_RGB565_YELLOW);      
  14.     testRects(COLOR_RGB565_BLACK,COLOR_RGB565_WHITE);
  15.     testRoundRects();
  16.     testCircles(24,COLOR_RGB565_BLUE);
  17.     testTriangles(COLOR_RGB565_YELLOW);
  18.     testPrint();
  19. }
  20. /*测试画像素点*/
  21. void testDrawPixel() {
  22.   /*
  23.    *@brief 清屏
  24.    *@param c 屏幕颜色
  25.    */
  26.   screen.fillScreen(COLOR_RGB565_BLACK);
  27.   int x = 0;
  28.   int y = screen.height();
  29.   for(int i = 0; i <= screen.width()/2; i += 10){
  30.     for (x = screen.width() - i; x >= i; x-=10 ){
  31.       /*
  32.        *@brief 画像素点
  33.        *@param x 横坐标
  34.        *       y 纵坐标
  35.        *       c 像素点颜色
  36.        */
  37.       screen.drawPixel(x, y, COLOR_RGB565_ORANGE);
  38.       delay(10);
  39.     }
  40.     for (y = screen.height() - i; y >= i; y-=10){
  41.       screen.drawPixel(x, y, COLOR_RGB565_ORANGE);
  42.       delay(10);
  43.     }
  44.     for (x = i; x <= screen.width() - i + 1; x+=10 ){
  45.       screen.drawPixel(x, y, COLOR_RGB565_ORANGE);
  46.       delay(10);
  47.     }
  48.     for (y = i; y <= screen.height() - i + 1; y+=10){
  49.       screen.drawPixel(x, y, COLOR_RGB565_ORANGE);
  50.       delay(10);
  51.     }
  52.   }
  53. }
  54. /*测试画线*/
  55. void testLine(){
  56.      //0x00FF 是格式为RGB565的颜色数据
  57.   uint16_t color = 0x00FF;
  58.   screen.fillScreen(COLOR_RGB565_BLACK);
  59.   for (int16_t x=0; x < screen.width(); x+=6) {
  60.     /*
  61.      *@brief 画线段
  62.      *@param x0 第一个顶点横坐标
  63.      *       y0 第一个顶点纵坐标
  64.      *       x1 第二个顶点横坐标
  65.      *       y1 第二个顶点纵坐标
  66.      *       c 线段颜色
  67.      */
  68.     screen.drawLine(/*x0=*/screen.width()/*屏幕宽度*//2, /*y0=*/screen.height()/*屏幕高度*//2, /*x1=*/x, /*y1=*/0, /*c=*/color+=0x0700);
  69.   }
  70.   for (int16_t y=0; y < screen.height(); y+=6) {
  71.     screen.drawLine(screen.width()/2, screen.height()/2, screen.width(), y, color+=0x0700);
  72.   }
  73.   for (int16_t x = screen.width(); x >= 0; x-=6) {
  74.     screen.drawLine(screen.width()/2, screen.height()/2, x,screen.height(), color+=0x0700);
  75.   }
  76.   for (int16_t y = screen.height(); y >= 0; y-=6) {
  77.     screen.drawLine(screen.width()/2, screen.height()/2, 0, y, color+=0x0700);
  78.   }
  79. }
  80. /*测试快速画线(需设置延时),只有横线和纵线*/
  81. void testFastLines(uint16_t color1, uint16_t color2) {
  82.   for (int16_t y=0; y < screen.height(); y+=4) {
  83.     /*
  84.      *@brief 画线段
  85.      *@param x 第一个顶点横坐标
  86.      *       y 第一个顶点纵坐标
  87.      *       w 线段的长度
  88.      *       c 线段颜色
  89.      */
  90.     screen.drawFastHLine(/*x=*/0, /*y=*/y, /*w=*/screen.width(),/*c=*/color2);
  91.     delay(10);
  92.   }
  93.   for(int16_t x=0; x < screen.width(); x+=3) {
  94.     /*
  95.      *@brief 画线段
  96.      *@param x 第一个顶点横坐标
  97.      *       y 第一个顶点纵坐标
  98.      *       h 线段的长度
  99.      *       c 线段颜色
  100.      */
  101.     screen.drawFastVLine(/*x=*/x, /*y=*/0, /*h=*/screen.height(), /*c=*/color1);
  102.     delay(10);
  103.   }
  104. }
  105. /*测试画矩形*/
  106. void testRects(uint16_t color1, uint16_t color2) {
  107.     screen.fillScreen(COLOR_RGB565_BLACK);
  108.     int16_t x=screen.width()-12;
  109.     for (; x > 100; x-=screen.width()/40) {
  110.       /*
  111.        *@brief 画空心矩形
  112.        *@param x 顶点横坐标
  113.        *@param y 顶点纵坐标
  114.        *@param w 横向边长
  115.        *@param h 纵向边长
  116.        *@param color 填充颜色,565结构的RGB色
  117.        */
  118.       screen.drawRect(/*x=*/screen.width()/2 -x/2, /*y=*/screen.height()/2 -x/2 , /*w=*/x, /*h=*/x, /*color=*/color2+=0x0F00);
  119.       delay(100);
  120.     }
  121.     /*
  122.      *@brief 画填充矩形
  123.      *@param x 顶点横坐标
  124.      *@param y 顶点纵坐标
  125.      *@param w 横向边长
  126.      *@param h 纵向边长
  127.      *@param color 填充颜色,565结构的RGB色
  128.     */
  129.     screen.fillRect(/*x=*/screen.width()/2 -x/2, /*y=*/screen.height()/2 -x/2 , /*w=*/x, /*h=*/x, /*color=*/color2);
  130.     delay(100);
  131.     for(; x > 6; x-=screen.width()/40){
  132.       screen.drawRect(screen.width()/2 -x/2, screen.height()/2 -x/2 , x, x, color1);
  133.       delay(100);
  134.     }
  135. }
  136. /*测试画圆角矩形*/
  137. void testRoundRects() {
  138.   screen.fillScreen(COLOR_RGB565_BLACK);
  139.    //0xF00F 是格式为RGB565的颜色数据
  140.   int color = 0xF00F;
  141.   int i;
  142.   int x = 0;
  143.   int y = 0;
  144.   int w = screen.width()-3;
  145.   int h = screen.height()-3;
  146.   for(i = 0 ; i <= 16; i+=2) {
  147.     /*
  148.      *@brief 画空心圆角矩形
  149.      *@param x0 起始顶点横坐标
  150.      *@param y0 起始顶点纵坐标
  151.      *@param w 横向边长
  152.      *@param h 纵向边长
  153.      *@param radius 圆角半径
  154.      *@param color 边框颜色,565结构的RGB色
  155.      */
  156.     screen.drawRoundRect(/*x0=*/x, /*y0=*/y, /*w=*/w, /*h=*/h, /*radius=*/20, /*color=*/color);
  157.     x+=5;
  158.     y+=5;
  159.     w-=10;
  160.     h-=10;
  161.     color+=0x0100;
  162.     delay(50);
  163.   }
  164.   for(i = 0 ; i <= 16; i+=2) {
  165.     /*
  166.      *@brief 画填充圆角矩形
  167.      *@param x0 起始顶点横坐标
  168.      *@param y0 起始顶点纵坐标
  169.      *@param w 横向边长
  170.      *@param h 纵向边长
  171.      *@param radius 圆角半径
  172.      *@param color 填充颜色,565结构的RGB色
  173.      */
  174.     screen.fillRoundRect(/*x0=*/x, /*y0=*/y, /*w=*/w, /*h=*/h, /*radius=*/10, /*color=*/color);
  175.     x+=5;
  176.     y+=5;
  177.     w-=10;
  178.     h-=10;
  179.     color+=0x0500;
  180.     delay(50);
  181.   }
  182. }
  183. /*测试画圆*/
  184. void testCircles(uint8_t radius, uint16_t color) {
  185.   screen.fillScreen(COLOR_RGB565_BLACK);
  186.   for (int16_t x=radius; x <=screen.width()-radius; x+=radius*2) {
  187.     for (int16_t y=radius; y <=screen.height()-radius; y+=radius*2) {
  188.       /*
  189.        *@brief 画空心圆
  190.        *@param x0 圆心横坐标
  191.        *@param y0 圆心纵坐标
  192.        *@param r 半径
  193.        *@param color 圆周颜色,565结构的RGB色
  194.        */
  195.       screen.drawCircle(/*x0=*/x, /*y0=*/y, /*r=*/radius, /*color=*/color);
  196.         if(x == y ||x == -y ||x == y + 2*radius)
  197.           /*
  198.            *@brief 画填充圆
  199.            *@param x0 圆心横坐标
  200.            *@param y0 圆心纵坐标
  201.            *@param r 半径
  202.            *@param color 填充颜色,565结构的RGB色
  203.            */
  204.           screen.fillCircle(/*x0=*/x, /*y0=*/y, /*r=*/radius, /*color=*/color);
  205.        color += 800;
  206.        delay(100);
  207.     }
  208.   }
  209. }
  210. /*测试画三角形*/
  211. void testTriangles(uint16_t color){
  212.   screen.fillScreen(COLOR_RGB565_BLACK);
  213.   for (int16_t i=0; i <=screen.width(); i+=24)
  214.     /*
  215.      *@brief 画空心三角形
  216.      *@param x0 起始顶点横坐标
  217.      *@param y0 起始顶点纵坐标
  218.      *@param x1 第二个顶点横坐标
  219.      *@param y1 第二个顶点纵坐标
  220.      *@param x2 第三个顶点横坐标
  221.      *@param y2 第三个顶点纵坐标
  222.      *@param color 边框颜色,565结构的RGB色
  223.      */
  224.     screen.drawTriangle(/*x0=*/i,/*y0=*/0,/*x1=*/0,/*y1=*/screen.height()-i,/*x2=*/screen.width()-i,/*y2=*/screen.height(), /*color=*/color);
  225.   for (int16_t i=0; i <screen.width(); i+=24)
  226.     screen.drawTriangle(screen.width(),i*4/3,0,screen.height()-i*4/3,i,0, color);
  227.   for (int16_t i=0; i <screen.width(); i+=24)
  228.     screen.drawTriangle(screen.width(),i*4/3,i,0,screen.width()-i,screen.height(), color);
  229.   color = COLOR_RGB565_RED;
  230.   for (int16_t i=0; i <=screen.width(); i+=24)
  231.     /*
  232.      *@brief 画填充三角形
  233.      *@param x0 起始顶点横坐标
  234.      *@param y0 起始顶点纵坐标
  235.      *@param x1 第二个顶点横坐标
  236.      *@param y1 第二个顶点纵坐标
  237.      *@param x2 第三个顶点横坐标
  238.      *@param y2 第三个顶点纵坐标
  239.      *@param color 填充颜色,565结构的RGB色
  240.      */
  241.     screen.fillTriangle(/*x0=*/i,/*y0=*/0,/*x1=*/0,/*y1=*/screen.height()-i,/*x2=*/screen.width()-i,/*y2=*/screen.height(), /*color=*/color+=100);
  242.   for (int16_t i=0; i <screen.width(); i+=24)
  243.     screen.fillTriangle(screen.width(),i*4/3,0,screen.height()-i*4/3,i,0, color+=100);
  244.   for (int16_t i=0; i <screen.width(); i+=24)
  245.     screen.fillTriangle(screen.width(),i*4/3,i,0,screen.width()-i,screen.height(), color+=100);
  246. }
  247. void testPrint() {
  248. //0x00FF 是格式为RGB565的颜色数据
  249.   int16_t color = 0x00FF;
  250.   //设置文本自动换行模式
  251.   //true=文本自动换行,false=不自动换行
  252.   screen.setTextWrap(false);
  253.   //填充颜色,565结构的RGB色
  254.   screen.fillScreen(COLOR_RGB565_BLACK);
  255.   //设置坐标位置x=0,y=50
  256.   screen.setCursor(0, 50);
  257.   //设置文本颜色;这是变化的值
  258.   screen.setTextColor(color+=0x3000);
  259.   //设置文本大小为0
  260.   screen.setTextSize(0);
  261.   //输出文本
  262.   screen.println("Hello World!");
  263.   screen.setTextColor(color+=0x3000);
  264.   //设置文本大小为1
  265.   screen.setTextSize(1);
  266.   screen.println("Hello World!");
  267.   screen.setTextColor(color+=0x3000);
  268.   //设置文本大小为2
  269.   screen.setTextSize(2);
  270.   screen.println("Hello World!");
  271.   screen.setTextColor(color+=0x3000);
  272.   //设置文本大小为3
  273.   screen.setTextSize(3);
  274.   screen.println("Hello World!");
  275.   screen.setTextColor(color+=0x3000);
  276.   //设置文本大小为4
  277.   screen.setTextSize(4);
  278.   screen.println("Hello!");
  279.   //设置文本大小为5
  280.   screen.setTextSize(5);
  281.   screen.print("Hello!");
  282.   delay(2000);
  283.   //设置坐标位置x=0,y=0
  284.   screen.setCursor(0, 0);
  285.   //填充颜色,565结构的RGB色
  286.   screen.fillScreen(COLOR_RGB565_BLACK);
  287.   screen.setTextSize(2);
  288.   screen.setTextColor(color+=0x3000);
  289.   screen.print("a = ");
  290.   screen.setTextColor(color+=0x3000);
  291.   int a = 1234;
  292.   screen.println(a, 1);
  293.   screen.setTextColor(color+=0x3000);
  294.   screen.print(8675309, HEX);
  295.   screen.println("this is HEX!");
  296.   screen.println("");
  297.   screen.setTextColor(color+=0x0F00);
  298.   screen.println("running for: ");
  299.   screen.setTextColor(color+=0x0F00);
  300.   //输出毫秒时间
  301.   screen.print(millis());
  302.   screen.setTextColor(color+=0x0F00);
  303.   screen.println("/1000 seconds.");
  304.   char *text = "Hi DFRobot!";
  305.   screen.setTextColor(color+=0x0F00);
  306.   screen.setTextWrap(true);
  307.   screen.setTextSize(3);
  308.   screen.println(text);
  309.   //screen.setFonts((const gdl_Font_t *)SIMKAIFont18ptBitmaps);
  310.   screen.println(text);
  311.   delay(2000);
  312. }
复制代码
编译、烧写。一次点亮!
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图10
  • 使用micropython点亮屏幕
从本论坛乔老师那里下载到micropython的固件,然后按说明烧写固件。
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图11

FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图12

就能顺利地连上mpy了。在这里找到一个ST7789的驱动。下载下来,放到lib文件夹里。这里略作改动,添加了自己屏幕的分辨率。

FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图13

最后简简单单地测试一下。图像有点偏,在代码中做一下调整,将图片移动到屏幕中央。搞定收工。

  1. from machine import Pin, SPI
  2. import st7789 as st7789
  3. import vga1_16x32 as font
  4. def main():
  5.     spi = SPI(1, baudrate=40000000, sck=Pin(23), mosi=Pin(22))
  6.     tft = st7789.ST7789(spi,172,320,xstart=33, ystart=0,
  7.         reset=Pin(14, Pin.OUT), cs=Pin(1, Pin.OUT), dc=Pin(8, Pin.OUT), backlight=Pin(15, Pin.OUT), rotation=0)
  8.     tft.fill(st7789.WHITE)
  9.     tft.text(font, "Hello!", 0, 0,color=st7789.RED, background=st7789.BLACK)
  10.     tft.text(font, "DFROBOT", 20, 160,color=st7789.GREEN, background=st7789.WHITE)
  11.     tft.text(font, "today!", 0, 320-32)   
  12. main()
复制代码
FireBeetle 2 ESP32 C6 试用——使用不同姿势点亮屏幕图14

简单滴测试了一下,在三种编程环境下点亮屏幕,总有一种方法适合自己!


_深蓝_  中级技师 来自手机

发表于 2024-3-23 23:13:37

好好好,果断收藏!!!
回复

使用道具 举报

HonestQiao  高级技师

发表于 2024-3-24 08:53:10

非常非常棒!!!非常非常棒!!!
回复

使用道具 举报

麦壳maikemaker  初级技师

发表于 2024-3-24 08:53:30

牛蛙,太棒了,学习资料棒棒哒
回复

使用道具 举报

有明堂  学徒

发表于 2024-3-24 16:33:49

太厉害了,太多要学习了,收藏!
回复

使用道具 举报

豆爸  高级技师

发表于 2024-4-6 12:51:59

学习了!!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail