• sales

    +86-0755-88291180

ESP32 C3 0.42LCD Graphics Test

1、 Import WS2812FX Graphics Library

1.1. Click on Sketch

1.2. Click on include library

1.3. Click on manage Libraries

1.4. Search for WS2812FX in the search box

1.5. Click on IN STALLED to install

2、Burning code

#ifdefU8X8_HAVE_HW_SPI

#include<SPI.h>

#endif

#ifdefU8X8_HAVE_HW_I2C

#include<Wire.h>

#endif

#defineLED_COUNT1

#defineLED_PIN2

#defineSDA_PIN5

#defineSCL_PIN6

WS2812FX ws2812fx =WS2812FX(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);

U8G2_SSD1306_72X40_ER_F_HW_I2Cu8g2(U8G2_R0,/* reset=*/U8X8_PIN_NONE);// EastRising 0.42" OLED

voidu8g2_prepare(void){

u8g2.setFont(u8g2_font_6x10_tf);

u8g2.setFontRefHeightExtendedText();

u8g2.setDrawColor(1);

u8g2.setFontPosTop();

u8g2.setFontDirection(0);

}

voidu8g2_box_frame(uint8_ta){

u8g2.drawStr(0,0,"drawBox");

u8g2.drawBox(5,10,20,10);

u8g2.drawBox(10+a,15,30,7);

u8g2.drawStr(0,30,"drawFrame");

u8g2.drawFrame(5,10+30,20,10);

u8g2.drawFrame(10+a,15+30,30,7);

}

voidu8g2_disc_circle(uint8_ta){

u8g2.drawStr(0,0,"drawDisc");

u8g2.drawDisc(10,18,9);

u8g2.drawDisc(24+a,16,7);

u8g2.drawStr(0,30,"drawCircle");

u8g2.drawCircle(10,18+30,9);

u8g2.drawCircle(24+a,16+30,7);

}

voidu8g2_r_frame(uint8_ta){

u8g2.drawStr(0,0,"drawRFrame/Box");

u8g2.drawRFrame(5,10,40,30, a+1);

u8g2.drawRBox(50,10,25,40, a+1);

}

voidu8g2_string(uint8_ta){

u8g2.setFontDirection(0);

u8g2.drawStr(30+a,31," 0");

u8g2.setFontDirection(1);

u8g2.drawStr(30,31+a," 90");

u8g2.setFontDirection(2);

u8g2.drawStr(30-a,31," 180");

u8g2.setFontDirection(3);

u8g2.drawStr(30,31-a," 270");

}

voidu8g2_line(uint8_ta){

u8g2.drawStr(0,0,"drawLine");

u8g2.drawLine(7+a,10,40,55);

u8g2.drawLine(7+a*2,10,60,55);

u8g2.drawLine(7+a*3,10,80,55);

u8g2.drawLine(7+a*4,10,100,55);

}

voidu8g2_triangle(uint8_ta){

uint16_toffset = a;

u8g2.drawStr(0,0,"drawTriangle");

u8g2.drawTriangle(14,7,45,30,10,40);

u8g2.drawTriangle(14+offset,7-offset,45+offset,30-offset,57+offset,10-offset);

u8g2.drawTriangle(57+offset*2,10,45+offset*2,30,86+offset*2,53);

u8g2.drawTriangle(10+offset,40+offset,45+offset,30+offset,86+offset,53+offset);

}

voidu8g2_ascii_1(){

chars[2] =" ";

uint8_tx, y;

u8g2.drawStr(0,0,"ASCII page 1");

for(y =0; y <6; y++){

for(x =0; x <16; x++){

s[0] = y*16+ x +32;

u8g2.drawStr(x*7, y*10+10, s);

}

}

}

voidu8g2_ascii_2(){

chars[2] =" ";

uint8_tx, y;

u8g2.drawStr(0,0,"ASCII page 2");

for(y =0; y <6; y++){

for(x =0; x <16; x++){

s[0] = y*16+ x +160;

u8g2.drawStr(x*7, y*10+10, s);

}

}

}

voidu8g2_extra_page(uint8_ta)

{

u8g2.drawStr(0,0,"Unicode");

u8g2.setFont(u8g2_font_unifont_t_symbols);

u8g2.setFontPosTop();

u8g2.drawUTF8(0,24,"☀ ☁");

switch(a){

case0:

case1:

case2:

case3:

u8g2.drawUTF8(a*3,36,"☂");

break;

case4:

case5:

case6:

case7:

u8g2.drawUTF8(a*3,36,"☔");

break;

}

}

#definecross_width24

#definecross_height24

staticconstunsignedcharcross_bits[] U8X8_PROGMEM  ={

0x00, 0x18, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x42, 0x00,

0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x81, 0x00, 0x00, 0x81, 0x00,

0xC0, 0x00, 0x03, 0x38, 0x3C, 0x1C, 0x06, 0x42, 0x60, 0x01, 0x42, 0x80,

0x01, 0x42, 0x80, 0x06, 0x42, 0x60, 0x38, 0x3C, 0x1C, 0xC0, 0x00, 0x03,

0x00, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00,

0x00, 0x42, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x18, 0x00,};

#definecross_fill_width24

#definecross_fill_height24

staticconstunsignedcharcross_fill_bits[] U8X8_PROGMEM  ={

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x64, 0x00, 0x26,

0x84, 0x00, 0x21, 0x08, 0x81, 0x10, 0x08, 0x42, 0x10, 0x10, 0x3C, 0x08,

0x20, 0x00, 0x04, 0x40, 0x00, 0x02, 0x80, 0x00, 0x01, 0x80, 0x18, 0x01,

0x80, 0x18, 0x01, 0x80, 0x00, 0x01, 0x40, 0x00, 0x02, 0x20, 0x00, 0x04,

0x10, 0x3C, 0x08, 0x08, 0x42, 0x10, 0x08, 0x81, 0x10, 0x84, 0x00, 0x21,

0x64, 0x00, 0x26, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};

#definecross_block_width14

#definecross_block_height14

staticconstunsignedcharcross_block_bits[] U8X8_PROGMEM  ={

0xFF, 0x3F, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20,

0xC1, 0x20, 0xC1, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20,

0x01, 0x20, 0xFF, 0x3F,};

voidu8g2_bitmap_overlay(uint8_ta){

uint8_tframe_size =28;

u8g2.drawStr(0,0,"Bitmap overlay");

u8g2.drawStr(0, frame_size +12,"Solid / transparent");

u8g2.setBitmapMode(false/* solid */);

u8g2.drawFrame(0,10, frame_size, frame_size);

u8g2.drawXBMP(2,12, cross_width, cross_height, cross_bits);

if(a &4)

u8g2.drawXBMP(7,17, cross_block_width, cross_block_height, cross_block_bits);

u8g2.setBitmapMode(true/* transparent*/);

u8g2.drawFrame(frame_size +5,10, frame_size, frame_size);

u8g2.drawXBMP(frame_size +7,12, cross_width, cross_height, cross_bits);

if(a &4)

u8g2.drawXBMP(frame_size +12,17, cross_block_width, cross_block_height, cross_block_bits);

}

voidu8g2_bitmap_modes(uint8_ttransparent){

constuint8_tframe_size =24;

u8g2.drawBox(0, frame_size *0.5, frame_size *5, frame_size);

u8g2.drawStr(frame_size *0.5,50,"Black");

u8g2.drawStr(frame_size *2,50,"White");

u8g2.drawStr(frame_size *3.5,50,"XOR");

if(!transparent){

u8g2.setBitmapMode(false/* solid */);

u8g2.drawStr(0,0,"Solid bitmap");

}else{

u8g2.setBitmapMode(true/* transparent*/);

u8g2.drawStr(0,0,"Transparent bitmap");

}

u8g2.setDrawColor(0);// Black

u8g2.drawXBMP(frame_size *0.5,24, cross_width, cross_height, cross_bits);

u8g2.setDrawColor(1);// White

u8g2.drawXBMP(frame_size *2,24, cross_width, cross_height, cross_bits);

u8g2.setDrawColor(2);// XOR

u8g2.drawXBMP(frame_size *3.5,24, cross_width, cross_height, cross_bits);

}

uint8_tdraw_state =0;

voiddraw(void){

u8g2_prepare();

switch(draw_state >>3){

case0:u8g2_box_frame(draw_state&7);break;

case1:u8g2_disc_circle(draw_state&7);break;

case2:u8g2_r_frame(draw_state&7);break;

case3:u8g2_string(draw_state&7);break;

case4:u8g2_line(draw_state&7);break;

case5:u8g2_triangle(draw_state&7);break;

case6:u8g2_ascii_1();break;

case7:u8g2_ascii_2();break;

case8:u8g2_extra_page(draw_state&7);break;

case9:u8g2_bitmap_modes(0);break;

case10:u8g2_bitmap_modes(1);break;

case11:u8g2_bitmap_overlay(draw_state&7);break;

}

}

voidsetup(void){

ws2812fx.init();

ws2812fx.setBrightness(255);

ws2812fx.setSpeed(1000);

ws2812fx.setColor(0x007BFF);

ws2812fx.setMode(FX_MODE_STATIC);

ws2812fx.start();

Wire.begin(SDA_PIN, SCL_PIN);

u8g2.begin();

}

voidloop(void){

ws2812fx.service();

// picture loop

u8g2.clearBuffer();

draw();

u8g2.sendBuffer();

// increase the state

draw_state++;

if(draw_state >=12*8)

draw_state =0;

// deley between each page

delay(100);

}


2.1. Copy the code into the Arduino IDE

2.2. Use a type-c cable to connect the computer to the ESP 32-c3 development board. After successful connection, the serial port will be displayed in the computer management window

2.3Click on Tools in the Arduino IDE, then click on Port and select the serial port Adafruit QT ESP32-C3

2.4Click on Verify

2.5.Click on upload

2.6 The test results are as follows