Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales01@spotpear.com
dragon_manager@163.com
services01@spotpear.com
manager01@spotpear.com
WhatsApp:13246739196
PIN | Description |
VCC | 5V/3.3V Power Input |
GND | Power Ground |
DIN | Data Input |
CLK | Clock Signal Input |
CS | Chip selection, low active |
DC | Data/command, low for command, high for data |
RST | Reset, low active |
OLED module provides two kinds of driver interfaces: 4-wire SPI and I2C interfaces respectively. There are two optional soldering resistors on the back of the module at the lower left corner, through the choice of resistors to select the corresponding communication mode, as shown in the figure:
The module adopts a 4-wire SPI communication mode by default, that is, the resistor is connected to the SPI by default. The specific hardware configuration is as follows:
That is the factory demo setting: two 0R resistors are connected to the SPI position;
Two 0R resistors are connected to the I2C position;
PS: The demo is set as SPI mode by default, if you need to switch the mode, please modify the DEV_Config.h. See demo description - underlying hardware interface - interface selection for more details.
Provide BCM2835, WiringPi, and RPI (Python) library demo.
When connecting to the Raspberry Pi, you can use a 7PIN cable to connect according to the following table:
OLED | Raspberry Pi | |
BCM2835 | Board | |
VCC | 3.3V | 3.3V |
GND | GND | GND |
DIN | MOSI / SDA | 19 / 3 |
CLK | SCLK / SCL | 23 / 5 |
CS | CE0 | 24 |
DC | 25 | 22 |
RST | 27 | 13 |
sudo raspi-config Select Interfacing Options -> SPI -> Yes to enable the SPI interface
And then reboot the Raspberry Pi:
sudo reboot
Same for I2C, enter the configuration interface and select Interfaces Options -> I2C -> Yes to turn on the IIC interface, then reboot.
#Open the Raspberry Pi terminal and run the following command: wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz tar zxvf bcm2835-1.71.tar.gz cd bcm2835-1.71/ sudo ./configure && sudo make && sudo make check && sudo make install #For more, you can refer to the official website: http://www.airspayce.com/mikem/bcm2835/
#Open the Raspberry Pi terminal and run the following command: cd sudo apt-get install wiringpi #For Raspberry Pi systems after May 2019 (earlier than that do not need to execute), an upgrade may be required: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v #Run gpio -v and version 2.52 will appear, if it does not appear, it means there is an installation error. #The Bullseye branch system uses the following command: git clone https://github.com/WiringPi/WiringPi cd WiringPi ./build gpio -v #Run gpio -v and version 2.70 will appear, if it does not appear, it means there is an installation error.
#python2 sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install RPi.GPIO sudo pip install spidev sudo apt-get install python-smbus #python3 sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip3 install RPi.GPIO sudo pip3 install spidev sudo apt-get install python3-smbus
Open the Raspberry Pi and run:
sudo apt-get install p7zip-full sudo wget https://files.waveshare.com/upload/2/2c/OLED_Module_Code.7z 7z x OLED_Module_Code.7z cd OLED_Module_Code/RaspberryPi
The following commands should be executed in the RaspberryPi directory, otherwise, the directory will not be indexed:
cd c sudo make clean sudo make -j 8
Test demos for all screens can be called directly by entering the corresponding size:
sudo ./main #Screen size
Depending on the OLED, one of the following commands should be entered.
#0.91inch OLED Module sudo ./main 0.91 ------------------------------ #0.95inch RGB OLED (A)/(B) sudo ./main 0.95rgb ------------------------------ #0.96inch OLED (A)/(B) sudo ./main 0.96 ------------------------------ #0.96inch OLED Module (C)/(D)/(E) sudo ./main 0.96 ------------------------------ #0.96inch RGB OLED Module sudo ./main 0.96rgb ------------------------------ #1.27inch RGB OLED Module sudo ./main 1.27rgb ------------------------------ #1.3inch OLED (A)/(B) sudo ./main 1.3 ------------------------------ #1.3inch OLED Module (C) sudo ./main 1.3c ------------------------------ #1.32inch OLED Module sudo ./main 1.32 ------------------------------ #1.5inch OLED Module sudo ./main 1.5 ------------------------------ #1.5inch OLED Module (B) sudo ./main 1.5b ------------------------------ #1.5inch RGB OLED Module sudo ./main 1.5rgb ------------------------------ #1.51inch OLED Module sudo ./main 1.51 ------------------------------ #1.54inch OLED Module sudo ./main 1.54 ------------------------------ #2.42inch OLED Module sudo ./main 2.42
cd python/example
If you have purchased a 1.3inch OLED Module (C), please enter:
# python2 sudo python OLED_1in3_c_test.py # python3 sudo python3 OLED_1in3_c_test.py
If you have purchased a 1.5inch RGB OLED Module, please enter:
# python2 sudo python OLED_1in5_rgb_test.py # python3 sudo python3 OLED_1in5_rgb_test.py
#0.91inch OLED Module sudo python OLED_0in91_test.py ------------------------------------ #0.95inch RGB OLED (A)/(B) sudo python OLED_0in95_rgb_test.py ------------------------------------ #0.96inch OLED (A)/(B) sudo python OLED_0in96_test.py ------------------------------------ #0.96inch OLED Module (C)/(D)/(E) sudo python OLED_0in96_test.py ------------------------------------ #0.96inch RGB OLED Module sudo python OLED_0in96_rgb_test.py ------------------------------------ #1.27inch RGB OLED Module sudo python OLED_1in27_rgb_test.py ------------------------------------ #1.3inch OLED (A)/(B) sudo python OLED_1in3_test.py ------------------------------------ #1.3inch OLED Module (C) sudo python OLED_1in3_c_test.py ------------------------------------ #1.32inch OLED Module sudo python OLED_1in32_test.py ------------------------------------ #1.5inch OLED Module sudo python OLED_1in5_test.py ------------------------------------ #1.5inch OLED Module (B) sudo python OLED_1in5_b_test.py ------------------------------------ #1.5inch RGB OLED Module sudo python OLED_1in5_rgb_test.py ------------------------------------ #1.51inch OLED Module sudo python OLED_1in51_test.py ------------------------------------ #1.54inch OLED Module sudo python OLED_1in54_test.py ------------------------------------ #2.42inch OLED Module sudo python OLED_2in42_test.py
1. There are three ways for C to drive: BCM2835 library, WiringPi library, and Dev library respectively
2. We use Dev libraries by default. If you need to change to BCM2835 or WiringPi libraries, please open RaspberryPi\c\Makefile and modify lines 13-15 as follows:
We have carried out the underlying encapsulation. Because the hardware platform is different, the internal implementation is different. If you need to know the internal implementation, you can go to the corresponding directory to view
You can see many definitions in DEV_Config.c(.h), in the directory: RaspberryPi\c\lib\Config
#define USE_SPI_4W 1 #define USE_IIC 0 Note: Modified here directly to switch SPI/I2C
#define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
void DEV_Module_Init(void); void DEV_Module_Exit(void); Note: Here is some GPIO processing before and after using the LCD screen.
void DEV_Digital_Write(UWORD Pin, UBYTE Value) Parameter: UWORD Pin: GPIO Pin number UBYTE Value: level to be output, 0 or 1
UBYTE DEV_Digital_Read(UWORD Pin) Parameter: UWORD Pin: GPIO Pin number Return value: level of GPIO, 0 or 1
void DEV_GPIO_Mode(UWORD Pin, UWORD Mode) Parameters: UWORD Pin: GPIO Pin number UWORD Mode: Mode, 0: input, 1: output
If you need to draw pictures, display Chinese and English characters, display pictures, etc., we provide some basic functions here about some graphics processing in the directory RaspberryPi\c\lib\GUI\GUI_Paint.c(.h).
The fonts can be found in RaspberryPi\c\lib\Fonts directory.
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: Image: the name of the image buffer, which is actually a pointer to the first address of the image buffer; Width: image buffer Width; Height: the Height of the image buffer; Rotate: Indicates the rotation Angle of an image Color: the initial Color of the image;
void Paint_SelectImage(UBYTE *image) Parameters: Image: the name of the image buffer, which is actually a pointer to the first address of the image buffer;
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees.
void Paint_SetScale(UBYTE scale) Parameters: scale: the size of pixels, 2: each pixel occupies one bit; 4: Each pixel occupies two bits.
void Paint_SetMirroring(UBYTE mirror) Parameters: Mirror: indicates the image mirroring mode. MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN correspond to no mirror, horizontal mirror, vertical mirror, and image center mirror respectively.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: the X position of a point in the image buffer Ypoint: Y position of a point in the image buffer Color: indicates the Color of the dot
void Paint_Clear(UWORD Color) Parameters: Color: fill Color
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xstart: the x-starting coordinate of the window Ystart: the y-starting coordinate of the window Xend: the x-end coordinate of the window Yend: the y-end coordinate of the window Color: fill Color
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: indicates the X coordinate of a point. Ypoint: indicates the Y coordinate of a point. Color: fill Color Dot_Pixel: The size of the dot, the demo provides 8 size pointss by default. typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Dot_Style: the size of a point that expands from the center of the point or from the bottom left corner of the point to the right and up. typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: the x-starting coordinate of the line Ystart: the y-starting coordinate of the line Xend: the x-end coordinate of a line Yend: the y-end coordinate of a line Color: fill Color Line_width: The width of the line, the demo provides 8 sizes of width by default. typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Line_Style: line style. Select whether the lines are joined in a straight or dashed way. typedef enum { LINE_STYLE_SOLID = 0, LINE_STYLE_DOTTED, } LINE_STYLE;
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: the starting X coordinate of the rectangle Ystart: the starting Y coordinate of the rectangle Xend: the x-end coordinate of the rectangle Yend: the y-end coordinate of the rectangle Color: fill Color Line_width: The width of the four sides of a rectangle. And the demo provides 8 sizes of width by default. typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: Fill, whether to fill the inside of the rectangle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: the x-coordinate of the center of the circle Y_Center: the y-coordinate of the center of the circle Radius: indicates the Radius of a circle Color: fill Color Line_width: The width of the arc, with a default of 8 widths typedef enum { DOT_PIXEL_1X1 = 1, // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: fill, whether to fill the inside of the circle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y-coordinate of the left vertex of a character Ascii_Char: indicates the Ascii character Font: Ascii visual character library, in the Fonts folder the demo provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: Ascii visual character library, in the Fonts folder the demo provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: GB2312 encoding character Font library, in the Fonts folder the demo provides the following Fonts: Font12CN: ASCII font 11*21, Chinese font 16*21 Font24CN: ASCII font24 *41, Chinese font 32*41 Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xpoint: the x-coordinate of the left vertex of a character Ypoint: the Y coordinate of the left vertex of the font Nummber: indicates the number displayed, which can be a decimal Digit: It's a decimal number Font: Ascii visual character library, in the Fonts folder the demo provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PTime: display time, A time structure is defined here, as long as the hours, minutes, and seconds are passed to the parameters; Font: Ascii visual character library, in the Fonts folder the demo provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
It is compatible with python and python3.
The calls of python are less complex compared to the C demo.
Device_SPI = 1 Device_I2C = 0 Note: Switch SPI/I2C modified here.
def module_init() def module_exit() Note: 1. Here is some GPIO processing before and after using the LCD screen. 2. The module_init() function is automatically called in the INIT () initializer on the LCD, but the module_exit() function needs to be called by itself
def spi_writebyte(data)
i2c_writebyte(reg, value):
The main function, if your Python version is Python2, is re-executed in Linux command mode as follows.
sudo python main.py
If your Python version is Python3, run the following command in Linux.
sudo python3 main.py
Python has an image library PIL official library link, it does not need to write code from the logical layer like C and can directly call the image library for image processing. The following will take a 1.54-inch LCD as an example, we provide a brief description of the demo.
sudo apt-get install python3-pil
And then import the library
from PIL import Image,ImageDraw,ImageFont.
Among them, Image is the basic library, ImageDraw is the drawing function, and ImageFont is the text function.
image1 = Image.new("1", (disp.width, disp.height), "WHITE")
The first parameter defines the color depth of the image, which is defined as "1" to indicate the bitmap of one-bit depth. The second parameter is a tuple that defines the width and height of the image. The third parameter defines the default color of the buffer, which is defined as "WHITE".
draw = ImageDraw.Draw(image1)
draw.line([(0,0),(127,0)], fill = 0)
The first parameter is a four-element tuple starting at (0, 0) and ending at (127,0). Draw a line. Fill ="0" means the color of the line is white.
draw.rectangle([(20,10),(70,60)],fill = "WHITE",outline="BLACK")
The first argument is a tuple of four elements. (20,10) is the coordinate value in the upper left corner of the rectangle, and (70,60) is the coordinate value in the lower right corner of the rectangle. Fill =" WHITE" means BLACK inside, and outline="BLACK" means the color of the outline is black.
draw.arc((150,15,190,55),0, 360, fill =(0,255,0)
Draw an inscribed circle in the square, the first parameter is a tuple of 4 elements, with (150, 15) as the upper left corner vertex of the square, (190, 55) as the lower right corner vertex of the square, specifying the level median line of the rectangular frame is the angle of 0 degrees, the second parameter indicates the starting angle, the third parameter indicates the ending angle, and fill = 0 indicates that the color of the line is white. If the figure is not square according to the coordination, you will get an ellipse.
Besides the arc function, you can also use the chord function for drawing a solid circle.
draw.ellipse((150,65,190,105), fill = 0)
The first parameter is the coordination of the enclosing rectangle. The second and third parameters are the beginning and end degrees of the circle. The fourth parameter is the fill color of the circle.
The ImageFont module needs to be imported and instantiated:
Font1 = ImageFont.truetype("../Font/Font01.ttf",25) Font2 = ImageFont.truetype("../Font/Font01.ttf",35) Font3 = ImageFont.truetype("../Font/Font02.ttf",32)
You can use the fonts of Windows or other fonts which is in ttc format..
Note: Each character library contains different characters; If some characters cannot be displayed, it is recommended that you can refer to the encoding set ro used. To draw English characters, you can directly use the fonts; for Chinese characters, you need to add a symbol u:
draw.text((5, 68), 'Hello world', fill = 0, font=Font1) text= u"微雪电子" draw.text((5, 200), text, fill = 0, font=Font3)
The first parameter is a two-element tuple with (5,68) as the left vertex, and use font1, fill is font color, fill = 0 means that the font color is white, and the second sentence shows '微雪电子', and the font color is white.
image = Image.open('../pic/pic.bmp')
The parameter is the image path.
Python's image library is very powerful, if you need to achieve other features, you can go to the official website to learn http://effbot.org/imagingbook pil.
Provide the demo based on STM32F103RBT6.
The example demo we provide is based on the STM32F103RBT6, and the provided connections correspond to the pins of the STM32F103RBT6. If you need to port the demo, please make sure to connect it according to the actual pin configuration.
OLED | STM32 |
VCC | 3.3V |
GND | GND |
DIN | SPI:PA7 / I2C:PB9 / I2C_SOFT:PC8 |
CLK | SPI:PA5 / I2C:PB8 / I2C_SOFT:PC6 |
CS | PB6 |
DC | PA8 |
RST | PA9 |
Screen Model | Demo Function |
---|---|
0.91inch OLED Module | OLED_0in91_test(); |
0.95inch RGB OLED (A)/(B) | OLED_0in95_rgb_test(); |
0.96inch OLED (A)/(B) | OLED_0in96_test(); |
0.96inch OLED Module (C)/(D)/(E) | OLED_0in96_test(); |
0.96inch RGB OLED Module | OLED_0in96_rgb_test(); |
1.27inch RGB OLED Module | OLED_1in27_rgb_test(); |
1.3inch OLED (A)/(B) | OLED_1in3_test(); |
1.3inch OLED Module (C) | OLED_1in3_c_test(); |
1.32inch OLED Module | OLED_1in32_test(); |
1.5inch OLED Module | OLED_1in5_test(); |
1.5inch OLED Module(B) | OLED_1in5_b_test(); |
1.5inch RGB OLED Module | OLED_1in5_rgb_test(); |
1.54inch OLED Module | OLED_1in54_test(); |
2.42inch OLED Module | OLED_2in42_test(); |
We package the bottom for different hardware platforms. You can check the DEV_Config.c(.h) file for more description.
#define USE_SPI_4W 1 #define USE_IIC 0 #define USE_IIC_SOFT 0 Note: Switch SPI/I2C directly modified here
#define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
UBYTE System_Init(void); void System_Exit(void); Note: 1. Here is some GPIO processing before and after using the LCD screen. 2. After the System_Exit(void) function is used, the OLED display will be turned off;
void DEV_Digital_Write(UWORD Pin, UBYTE Value); UBYTE DEV_Digital_Read(UWORD Pin);
UBYTE SPI4W_Write_Byte(uint8_t value);
void I2C_Write_Byte(uint8_t value, uint8_t Cmd);
For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do, and we provide some basic functions here about some graphics processing, you can check in the directory STM32\STM32F103RB\User\GUI\GUI_Paint.c(.h)
The character font GUI dependent is in the directory STM32\STM32F103RB\User\Fonts
void Paint_NewImage(UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: Width: image buffer Width; Height: the Height of the image buffer; Rotate: Indicates the rotation Angle of an image Color: the initial Color of the image;
void Paint_SetClearFuntion(void (*Clear)(UWORD)); parameter: Clear: Pointer to the clear screen function, used to quickly clear the screen to a certain color;
void Paint_SetDisplayFuntion(void (*Display)(UWORD,UWORD,UWORD)); parameter: Display: Pointer to the pixel drawing function, which is used to write data to the specified location in the internal RAM of the OLED;
void Paint_SelectImage(UBYTE *image) Parameters: Image: the name of the image cache, which is actually a pointer to the first address of the image buffer
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees respectively;
void Paint_SetMirroring(UBYTE mirror) Parameters: Mirror: indicates the image mirroring mode. MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN correspond to no mirror, horizontal mirror, vertical mirror, and about image center mirror respectively.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: the X position of a point in the image buffer Ypoint: Y position of a point in the image buffer Color: indicates the Color of the dot
void Paint_Clear(UWORD Color) Parameters: Color: fill Color
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xstart: the x-starting coordinate of the window Ystart: indicates the Y starting point of the window Xend: the x-end coordinate of the window Yend: indicates the y-end coordinate of the window Color: fill Color
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: indicates the X coordinate of a point Ypoint: indicates the Y coordinate of a point Color: fill Color Dot_Pixel: The size of the dot, providing a default of eight size points typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Dot_Style: the size of a point that expands from the center of the point or from the bottom left corner of the point to the right and up typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: the x-starting coordinate of the line Ystart: the y-starting coordinate of the line Xend: the x-end coordinate of the line Yend: the y-end coordinate of the line Color: fill Color Line_width: The width of the line, the demo provides 8 sizes of width by default. typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Line_Style: line style. Select whether the lines are joined in a straight or dashed way typedef enum { LINE_STYLE_SOLID = 0, LINE_STYLE_DOTTED, } LINE_STYLE;
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: the starting X coordinate of the rectangle Ystart: the starting Y coordinate of the rectangle Xend: the x-end coordinate of the rectangle Yend: the y-end coordinate of the rectangle Color: fill Color Line_width: The width of the four sides of a rectangle. And the demo provides 8 sizes of width by default. DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: Fill, whether to fill the inside of the rectangle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: the x-coordinate of the center of a circle Y_Center: the y-coordinate of the center of the circle Radius: indicates the Radius of a circle Color: fill Color Line_width: The width of the arc, with a default of 8 widths typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: fill, whether to fill the inside of the circle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y-coordinate of the left vertex of a character Ascii_Char: indicates the Ascii character Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y-coordinate of the left vertex of a character PString: string, string is a pointer Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y-coordinate of the left vertex of a character PString: string, string is a pointer Font: GB2312 encoding character Font library, in the Fonts folder provides the following Fonts: Font12CN: ASCII font 11*21, Chinese font 16*21 Font24CN: ASCII font24 *41, Chinese font 32*41 Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y-coordinate of the left vertex of a character Nummber: indicates the number displayed, which can be a decimal Digit: It's a decimal number Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y-coordinate of the left vertex of a character PTime: display time, here defined a good time structure, as long as the hour, minute and second bits of data to the parameter; Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
Provide a demo based on UNO PLUS.
The example code we provide is based on the UNO PLUS, and the provided connections correspond to the pins of the UNO PLUS. If you need to port the demo, please make sure to connect it according to the actual pin configuration.
OLED | UNO |
VCC | 3.3V/5V |
GND | GND |
DIN | SPI:D11 / I2C:SDA |
CLK | SPI:D13 / I2C:SCL |
CS | D10 |
DC | D7 |
RST | D8 |
Four-wire SPI wiring diagram:
LCD Model | Demo File |
---|---|
0.91inch OLED Module | OLED_0in91 |
0.95inch RGB OLED (A)/(B) | OLED_0in95_rgb |
0.96inch OLED (A)/(B) | OLED_0in96 |
0.96inch OLED Module (C)/(D)/(E) | OLED_0in96 |
0.96inch RGB OLED Module | OLED_0in96_rgb |
1.27inch RGB OLED Module | OLED_1in27_rgb |
1.3inch OLED (A)/(B) | OLED_1in3 |
1.3inch OLED Module (C) | OLED_1in3_c |
1.32inch OLED Module | OLED_1in32 |
1.5inch OLED Module | OLED_1in5 |
1.5inch OLED Module(B) | OLED_1in5_B |
1.5inch RGB OLED Module | OLED_1in5_rgb |
1.51inch Transparent OLED | OLED_1in51 |
1.54inch OLED Module | OLED_1in54 |
2.42inch OLED Module | OLED_2in42 |
Because the hardware platform and the internal implementation are different. If you need to know the internal implementation, you can see many definitions in the directory DEV_Config.c(.h)
#define USE_SPI_4W 1 #define USE_IIC 0 Note: Switch SPI/I2C directly modified here
#define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
UBYTE System_Init(void); void System_Exit(void); Note: 1. Here is some GPIO processing before and after using the LCD screen. 2. After the System_Exit(void) function is used, the OLED display will be turned off;
void DEV_Digital_Write(UWORD Pin, UBYTE Value); UBYTE DEV_Digital_Read(UWORD Pin);
UBYTE SPI4W_Write_Byte(uint8_t value);
void I2C_Write_Byte(uint8_t value, uint8_t Cmd);
For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do, and we provide some basic functions here about some graphics processing in the directory:
Arduino\OLED_xxx\GUI_Paint.c(.h)
void Paint_NewImage(UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: Width: image buffer Width; Height: the Height of the image buffer; Rotate: Indicates the rotation Angle of an image Color: the initial Color of the image;
void Paint_SetClearFuntion(void (*Clear)(UWORD)); parameter: Clear: Pointer to the clear screen function, used to quickly clear the screen to a certain color;
void Paint_SetDisplayFuntion(void (*Display)(UWORD,UWORD,UWORD)); parameter: Display: Pointer to the pixel drawing function, which is used to write data to the specified location in the internal RAM of the OLED;
void Paint_SelectImage(UBYTE *image) Parameters: Image: the name of the image cache, which is actually a pointer to the first address of the image buffer
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees respectively;
void Paint_SetMirroring(UBYTE mirror) Parameters: Mirror: indicates the image mirroring mode. MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN correspond to no mirror, horizontal mirror, vertical mirror, and about image center mirror respectively.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: the X position of a point in the image buffer Ypoint: Y position of a point in the image buffer Color: indicates the Color of the dot
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xstart: the x-starting coordinate of the window Ystart: indicates the Y starting point of the window Xend: the x-end coordinate of the window Yend: indicates the y-end coordinate of the window Color: fill Color
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: indicates the X coordinate of a point Ypoint: indicates the Y coordinate of a point Color: fill Color Dot_Pixel: The size of the dot, providing a default of eight size points typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Dot_Style: the size of a point that expands from the center of the point or from the bottom left corner of the point to the right and up typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: the x-starting coordinate of a line Ystart: indicates the Y starting point of a line Xend: x-terminus of a line Yend: the y-end coordinate of a line Color: fill Color Line_width: The width of the line, which provides a default of eight widths typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Line_Style: line style. Select whether the lines are joined in a straight or dashed way typedef enum { LINE_STYLE_SOLID = 0, LINE_STYLE_DOTTED, } LINE_STYLE;
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: the starting X coordinate of the rectangle Ystart: indicates the Y starting point of the rectangle Xend: X terminus of the rectangle Yend: specifies the y-end coordinate of the rectangle Color: fill Color Line_width: The width of the four sides of a rectangle. Default eight widths are provided typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: Fill, in whether to fill the inside of the rectangle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: the x-coordinate of the center of a circle Y_Center: Y coordinate of the center of a circle Radius: indicates the Radius of a circle Color: fill Color Line_width: The width of the arc, with a default of 8 widths typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: fill, whether to fill the inside of the circle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex Ascii_Char: indicates the Ascii character Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: GB2312 encoding character Font library, in the Fonts folder provides the following Fonts: Font12CN: ASCII font 11*21, Chinese font 16*21 Font24CN: ASCII font24 *41, Chinese font 32*41 Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xpoint: the x-coordinate of the left vertex of a character Ypoint: the Y coordinate of the left vertex of the font Nummber: indicates the number displayed, which can be a decimal Digit: It's a decimal number Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PTime: display time, here defined a good time structure, as long as the hour, minute and second bits of data to the parameter; Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
Provide the demo based on ESP32.
The demo we provide is based on the ESP32-S3, and the connections provided correspond to the pins of the ESP32-S3. If you need to port the demo, please connect it according to the actual pins.
OLED | ESP32 |
VCC | 3.3V/5V |
GND | GND |
DIN | SPI:IO11 / I2C:IO17 |
CLK | SPI:IO12 / I2C:IO16 |
CS | IO10 |
DC | IO46 |
RST | IO3 |
Four-wire SPI wiring diagram:
We have encapsulated the low-level hardware interface. Due to different hardware platforms, the internal implementations vary. If you need to understand the internal implementation, you can check the corresponding directory. In DEV_Config.c(.h), you can find many definitions.
#define USE_SPI_4W 1 #define USE_IIC 0 Note: Modify here to switch SPI/I2C
#define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
UBYTE System_Init(void); void System_Exit(void); Note: 1. Here we are handling some GPIO operations before and after using the LCD screen. 2. After using the System_Exit function, the OLED display screen will be turned off.
void DEV_Digital_Write(UWORD Pin, UBYTE Value); UBYTE DEV_Digital_Read(UWORD Pin);
UBYTE SPI4W_Write_Byte(uint8_t value);
void I2C_Write_Byte(uint8_t value, uint8_t Cmd);
For the screen, if you need to draw pictures, display Chinese and English characters, display pictures, etc., you can use the upper application to do so, and we provide some basic functions here about some graphics processing in the directory: ESP32\OLED_xxx\GUI_Paint.c(.h)
void Paint_NewImage(UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) Parameters: Width: image buffer Width; Height: the Height of the image buffer; Rotate: Indicates the rotation Angle of an image Color: the initial Color of the image;
void Paint_SetClearFuntion(void (*Clear)(UWORD)); parameter: Clear: Pointer to the clear screen function, used to quickly clear the screen to a certain color;
void Paint_SetDisplayFuntion(void (*Display)(UWORD,UWORD,UWORD)); parameter: Display: Pointer to the pixel drawing function, which is used to write data to the specified location in the internal RAM of the OLED;
void Paint_SelectImage(UBYTE *image) Parameters: Image: the name of the image cache, which is actually a pointer to the first address of the image buffer
void Paint_SetRotate(UWORD Rotate) Parameters: Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees respectively;
void Paint_SetMirroring(UBYTE mirror) Parameters: Mirror: indicates the image mirroring mode. MIRROR_NONE, MIRROR_HORIZONTAL, MIRROR_VERTICAL, MIRROR_ORIGIN correspond to no mirror, horizontal mirror, vertical mirror, and about image center mirror respectively.
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) Parameters: Xpoint: the X position of a point in the image buffer Ypoint: Y position of a point in the image buffer Color: indicates the Color of the dot
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) Parameters: Xstart: the x-starting coordinate of the window Ystart: indicates the Y starting point of the window Xend: the x-end coordinate of the window Yend: indicates the y-end coordinate of the window Color: fill Color
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) Parameters: Xpoint: indicates the X coordinate of a point Ypoint: indicates the Y coordinate of a point Color: fill Color Dot_Pixel: The size of the dot, providing a default of eight size points typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Dot_Style: the size of a point that expands from the center of the point or from the bottom left corner of the point to the right and up typedef enum { DOT_FILL_AROUND = 1, DOT_FILL_RIGHTUP, } DOT_STYLE;
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, LINE_STYLE Line_Style , LINE_STYLE Line_Style) Parameters: Xstart: the x-starting coordinate of a line Ystart: indicates the Y starting point of a line Xend: x-terminus of a line Yend: the y-end coordinate of a line Color: fill Color Line_width: The width of the line, which provides a default of eight widths typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Line_Style: line style. Select whether the lines are joined in a straight or dashed way typedef enum { LINE_STYLE_SOLID = 0, LINE_STYLE_DOTTED, } LINE_STYLE;
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: Xstart: the starting X coordinate of the rectangle Ystart: indicates the Y starting point of the rectangle Xend: X terminus of the rectangle Yend: specifies the y-end coordinate of the rectangle Color: fill Color Line_width: The width of the four sides of a rectangle. Default eight widths are provided typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: Fill, in whether to fill the inside of the rectangle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) Parameters: X_Center: the x-coordinate of the center of a circle Y_Center: Y coordinate of the center of a circle Radius: indicates the Radius of a circle Color: fill Color Line_width: The width of the arc, with a default of 8 widths typedef enum { DOT_PIXEL_1X1 , // 1 x 1 DOT_PIXEL_2X2 , // 2 X 2 DOT_PIXEL_3X3 , // 3 X 3 DOT_PIXEL_4X4 , // 4 X 4 DOT_PIXEL_5X5 , // 5 X 5 DOT_PIXEL_6X6 , // 6 X 6 DOT_PIXEL_7X7 , // 7 X 7 DOT_PIXEL_8X8 , // 8 X 8 } DOT_PIXEL; Draw_Fill: fill, whether to fill the inside of the circle typedef enum { DRAW_FILL_EMPTY = 0, DRAW_FILL_FULL, } DRAW_FILL;
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Ascii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex Ascii_Char: indicates the Ascii character Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PString: string, string is a pointer Font: GB2312 encoding character Font library, in the Fonts folder provides the following Fonts: Font12CN: ASCII font 11*21, Chinese font 16*21 Font24CN: ASCII font24 *41, Chinese font 32*41 Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) Parameters: Xpoint: the x-coordinate of the left vertex of a character Ypoint: the Y coordinate of the left vertex of the font Nummber: indicates the number displayed, which can be a decimal Digit: It's a decimal number Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Background, UWORD Color_Foreground) Parameters: Xstart: the x-coordinate of the left vertex of a character Ystart: the Y coordinate of the font's left vertex PTime: display time, here defined a good time structure, as long as the hour, minute and second bits of data to the parameter; Font: Ascii visual character library, in the Fonts folder provides the following Fonts: Font8: 5*8 font Font12: 7*12 font Font16: 11*16 font Font20: 14*20 font Font24: 17*24 font Color_Foreground: Font color Color_Background: indicates the background color
Provide a demo based on Pico.
The demo we provide is based on Pico, and the connections provided correspond to Pico's pins. If you need to port the demo, please connect it according to the actual pins.
OLED | Pico |
VCC | 3.3V/5V |
GND | GND |
DIN | SPI:GP11 / I2C:GP8 |
CLK | SPI:GP10 / I2C:GP9 |
CS | GP13 |
DC | GP14 |
RST | GP12 |
4-spi SPI wiring diagram:
1): Press and hold the button on the Pico board, then connect the Pico to your computer's USB port using a Micro USB cable. Afterward, release the button. Once connected, your computer should automatically recognize a removable drive named "RPI-RP2." 2): Copy the "rp2-pico-20210418-v1.15.uf2" file from the "micropython" directory to the recognized removable drive ("RPI-RP2"). 3): Update the Thonny IDE: sudo apt upgrade thonny 4): Open the Thonny IDE by clicking on the Raspberry Pi logo, navigating to "Programming," and selecting "Thonny Python IDE." Then, go to "Tools" -> "Options..." -> "Interpreter." Choose "MicroPython (Raspberry Pi Pico and ttyACM0 port)." 5): In the Thonny IDE, open the "Code\Pico\micropython\Pico-OLED-1.54(spi).py" file, and then run the current script (the green triangle).
def write_cmd(self, cmd)
def write_data(self, buf)
def init_display(self)
def show(self)
When connecting the Jetson Nano, choose to connect it with a 7PIN cable. Please refer to the pinout table below.
OLED | Jetson Nano | |
BCM | Board | |
VCC | 3.3V | 3.3V |
GND | GND | GND |
DIN | MOSI / SDA | 19 / 3 |
CLK | SCLK / SCL | 23 / 5 |
CS | CE0 | 24 |
DC | 25 | 22 |
RST | 27 | 13 |
It is the same as I2C. Open the Jetson Nano terminal and click here to see how to open I2C.
#python2 sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install Jetson.GPIO sudo pip install spidev sudo apt-get install python-smbus #python3 sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip install Jetson.GPIO sudo pip3 install spidev sudo apt-get install python3-smbus
Open the Jetson Nano terminal and execute:
sudo apt-get install p7zip-full sudo wget https://files.waveshare.com/upload/2/2c/OLED_Module_Code.7z 7z x OLED_Module_Code.7z -o./OLED_Module_Code cd OLED_Module_Code/RaspberryPi
Please run the following commands on the Jetson Nano directory, or it can not be indexed the directory.
cd python/example
If you purchased 1.54inch OLED Module. please input:
# python2 sudo python OLED_1in54_test.py # python3 sudo python3 OLED_1in54_test.py
#1.54inch OLED Module sudo python OLED_1in54_test.py ------------------------------------ #2.42inch OLED Module sudo python OLED_2in42_test.py
Applicable for python and python3.
Device_SPI = 1 Device_I2C = 0
Note: Modify here to switch SPI/I2C.
def module_init() def module_exit() Note: 1. Here is some GPIO processing before and after using the LCD screen. 2. The module_init() function is automatically called in the INIT () initializer on the LCD, but the module_exit() function needs to be called by itself
def spi_writebyte(data)
i2c_writebyte(reg, value):
The main function, if your Python version is Python2, is re-executed in Linux command mode as follows.
sudo python main.py
If your Python version is Python3, run the following command in Linux.
sudo python3 main.py
Python has an image library PIL official library link, it does not need to write code from the logical layer like C and can directly call the image library for image processing. The following will take a 1.54-inch LCD as an example, we provide a brief description of the demo.
sudo apt-get install python3-pil
And then import the library
from PIL import Image,ImageDraw,ImageFont.
Among them, Image is the basic library, ImageDraw is the drawing function, and ImageFont is the text function.
image1 = Image.new("1", (disp.width, disp.height), "WHITE")
The first parameter defines the color depth of the image, which is defined as "1" to indicate the bitmap of one-bit depth. The second parameter is a tuple that defines the width and height of the image. The third parameter defines the default color of the buffer, which is defined as "WHITE".
draw = ImageDraw.Draw(image1)
draw.line([(0,0),(127,0)], fill = 0)
The first parameter is a four-element tuple starting at (0, 0) and ending at (127,0). Draw a line. Fill ="0" means the color of the line is white.
draw.rectangle([(20,10),(70,60)],fill = "WHITE",outline="BLACK")
The first argument is a tuple of four elements. (20,10) is the coordinate value in the upper left corner of the rectangle, and (70,60) is the coordinate value in the lower right corner of the rectangle. Fill =" WHITE" means BLACK inside, and outline="BLACK" means the color of the outline is black.
draw.arc((150,15,190,55),0, 360, fill =(0,255,0)
Draw an inscribed circle in the square, the first parameter is a tuple of 4 elements, with (150, 15) as the upper left corner vertex of the square, (190, 55) as the lower right corner vertex of the square, specifying the level median line of the rectangular frame is the angle of 0 degrees, the second parameter indicates the starting angle, the third parameter indicates the ending angle, and fill = 0 indicates that the color of the line is white. If the figure is not square according to the coordination, you will get an ellipse.
Besides the arc function, you can also use the chord function for drawing a solid circle.
draw.ellipse((150,65,190,105), fill = 0)
The first parameter is the coordination of the enclosing rectangle. The second and third parameters are the beginning and end degrees of the circle. The fourth parameter is the fill color of the circle.
The ImageFont module needs to be imported and instantiated:
Font1 = ImageFont.truetype("../Font/Font01.ttf",25) Font2 = ImageFont.truetype("../Font/Font01.ttf",35) Font3 = ImageFont.truetype("../Font/Font02.ttf",32)
You can use the fonts of Windows or other fonts which is in ttc format..
Note: Each character library contains different characters; If some characters cannot be displayed, it is recommended that you can refer to the encoding set ro used. To draw English characters, you can directly use the fonts; for Chinese characters, you need to add a symbol u:
draw.text((5, 68), 'Hello world', fill = 0, font=Font1) text= u"微雪电子" draw.text((5, 200), text, fill = 0, font=Font3)
The first parameter is a two-element tuple with (5,68) as the left vertex, and use font1, fill is font color, fill = 0 means that the font color is white, and the second sentence shows '微雪电子', and the font color is white.
image = Image.open('../pic/pic.bmp')
The parameter is the image path.
Python's image library is very powerful, if you need to achieve other features, you can go to the official website to learn http://effbot.org/imagingbook pil.