Difference between revisions of "1.5inch OLED Module"

From Waveshare Wiki
Jump to: navigation, search
 
(24 intermediate revisions by 5 users not shown)
Line 3: Line 3:
 
<div class="tabbertab" title="Instruction">
 
<div class="tabbertab" title="Instruction">
 
{{Infobox item
 
{{Infobox item
|img=[[File:360px-1.5inch-OLED-Module-intro.jpg|300px|{{Amazon_nolink|default={{#urlget:amazon|0}}|{#urlget:Amazon|0}}|default|}}|ur1=link=https://www.waveshare.com/1.5inch-oled-module.htm}}|1.5inch OLED Module]]
+
|img=[[File:360px-1.5inch-OLED-Module-intro.jpg|300px|{{Amazon_nolink|default={{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}|url=link=https://www.waveshare.com/1.5inch-oled-module.htm}}|1.5inch OLED Module]]
 
|caption=1.5inch RGB OLED Module, I2C interfaces,  
 
|caption=1.5inch RGB OLED Module, I2C interfaces,  
 
|category=[[:Category:OLEDs / LCDs|OLEDs / LCDs]]
 
|category=[[:Category:OLEDs / LCDs|OLEDs / LCDs]]
Line 19: Line 19:
 
*Controller: SSD1327
 
*Controller: SSD1327
 
*Support interface: 4-wire SPI/I2C
 
*Support interface: 4-wire SPI/I2C
*Resolution: 128x128
+
*Resolution: 128 x 128
 
*Display size: 1.5inch
 
*Display size: 1.5inch
 
*Dimensions: 44.5mm * 37mm
 
*Dimensions: 44.5mm * 37mm
 
*Display color: 16-bit grayscale
 
*Display color: 16-bit grayscale
 
*Working voltage: 3.3V/5V
 
*Working voltage: 3.3V/5V
 +
 
==Pinout==
 
==Pinout==
 
{|border=1; style="width:700px;text-align:center" align="center";  
 
{|border=1; style="width:700px;text-align:center" align="center";  
Line 105: Line 106:
 
|GND || GND || GND
 
|GND || GND || GND
 
|-align="center"
 
|-align="center"
|DIN || SPI:D10(MOSI) / I2C:D2 || SPI:MOSI / I2C:SDA.1
+
|DIN || MOSI / SDA|| 19 / 3
 
|-align="center"
 
|-align="center"
|CLK || SPI:D11(SCLK) / I2C:D3 || SPI:SCLK / I2C:SCL.1
+
|CLK || SCLK / SCL || 23 / 5
 
|-align="center"
 
|-align="center"
|CS || D8(CE0) || CE0
+
|CS || CE0|| 24
 
|-align="center"
 
|-align="center"
|DC || D25 || GPIO.6
+
|DC || 25 || 22
 
|-align="center"
 
|-align="center"
|RST || D27 || GPIO.2
+
|RST || 27 || 13
 
|}
 
|}
 
*Four-wire SPI wiring diagram
 
*Four-wire SPI wiring diagram
 
[[File:600px-1.5inch_OLED_Module-树莓派.jpg]]
 
[[File:600px-1.5inch_OLED_Module-树莓派.jpg]]
 
+
{{OLED rpi code analyze}}
==Enable SPI and I2C interfaces==
 
*Open terminal, use command to enter the configuration page<br />
 
<pre>
 
sudo raspi-config
 
Choose Interfacing Options -> SPI -> Yes  to enable SPI interface
 
</pre>
 
[[file:RPI_open_spi.png|900px]]<br />
 
Reboot Raspberry Pi:<br />
 
<pre>
 
sudo reboot
 
</pre>
 
Please make sure that SPI interface was not used by other devices <br />
 
I2C is the same, enter the configuration interface and select Interfaceing Options -> I2C -> Yes to open the IIC interface, and then restart
 
==Install Libraries==
 
*Install BCM2835 libraries
 
<pre>
 
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
 
tar zxvf bcm2835-1.68.tar.gz
 
cd bcm2835-1.68/
 
sudo ./configure && sudo make && sudo make check && sudo make install
 
#For more details, please refer to http://www.airspayce.com/mikem/bcm2835/
 
</pre>
 
 
 
*Install wiringPi libraries
 
<pre>
 
sudo apt-get install wiringpi
 
#For the Raspberry Pi system after May 2019, it may need to be upgraded
 
wget https://project-downloads.drogon.net/wiringpi-latest.deb
 
sudo dpkg -i wiringpi-latest.deb
 
gpio -v
 
#You will get 2.52 information if you install it correctly
 
 
 
#Bullseye branch system use the following command:
 
git clone https://github.com/WiringPi/WiringPi
 
cd WiringPi
 
./build
 
gpio -v
 
# Run gpio -v and version 2.60 will appear. If it does not appear, it means that there is an installation error
 
</pre>
 
 
 
*Install Python libraries
 
<pre>
 
#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
 
#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
 
</pre>
 
 
 
==Download Examples==
 
Open Raspberry Pi terminal and run the following command<br />
 
<pre>
 
sudo apt-get install p7zip-full
 
sudo wget  https://www.waveshare.com/w/upload/2/2c/OLED_Module_Code.7z
 
7z x OLED_Module_Code.7z -O./OLED_Module_Code
 
cd OLED_Module_Code/RaspberryPi
 
</pre>
 
 
 
==Run the demo codes==
 
Please go into the RaspberryPi directory (demo codes) first and run the commands in terminal<br />
 
==='''C codes'''===
 
*Re-compile the demo codes<br />
 
<pre>
 
cd c
 
sudo make clean
 
sudo make -j 8
 
</pre>
 
 
 
*After the compilation is complete, the main file is generated, '''enter the command according to the OLED model you are using.'''If you have purchased a 1.3inch OLED Module (C), please enter the following command:
 
sudo ./main 1.3c
 
If you have purchased a 1.5inch RGB OLED Module, please enter the following command:
 
sudo ./main 1.5rgb
 
The command of each LCD model can check in the following table:
 
{| class="wikitable"
 
|-
 
! LCD model !! Command
 
|-
 
| 0.91inch OLED Module || <pre>sudo ./main 0.91</pre>
 
|-
 
|  0.95inch RGB OLED (A)/(B) || <pre>sudo ./main 0.95rgb</pre>
 
|-
 
|  0.96inch OLED (A)/(B) || <pre>sudo ./main 0.96</pre>
 
|-
 
| 1.3inch OLED (A)/(B) || <pre>sudo ./main 1.3</pre>
 
|-
 
| 1.3inch OLED Module (C) || <pre>sudo ./main 1.3c</pre>
 
|-
 
| 1.5inch OLED Module || <pre>sudo ./main 1.5</pre>
 
|-
 
| 1.5inch RGB OLED Module || <pre>sudo ./main 1.5rgb</pre>
 
|}
 
*Please make sure that the SPI is not occupied by other devices, you can check in the middle of /boot/config.txt<br />
 
 
 
==='''Python'''===
 
*Enter the python directory and run<br />
 
<pre>
 
cd python/example
 
</pre>
 
*'''Run the demo of the corresponding model OLED''', the program supports python2/3
 
'''If''' you have purchased a 1.3inch OLED Module (C), please enter:
 
<pre>
 
# python2
 
sudo python OLED_1in3_c_test.py
 
# python3
 
sudo python3 OLED_1in3_c_test.py
 
</pre>
 
'''If''' you have purchased a 1.5inch RGB OLED Module, please enter:
 
<pre>
 
# python2
 
sudo python OLED_1in5_rgb_test.py
 
# python3
 
sudo python3 OLED_1in5_rgb_test.py
 
</pre>
 
 
 
The command of each LCD model can check in the following table:
 
{| class="wikitable"
 
|-
 
! LCD Model !! Command(python2)
 
|-
 
| 0.91inch OLED Module || <pre>sudo python OLED_0in91_test.py</pre>
 
|-
 
|  0.95inch RGB OLED (A)/(B) || <pre>sudo python OLED_0in95_rgb_test.py</pre>
 
|-
 
|  0.96inch OLED (A)/(B) || <pre>sudo python OLED_0in96_test.py</pre>
 
|-
 
| 1.3inch OLED (A)/(B) || <pre>sudo python OLED_1in3_c_test.py</pre>
 
|-
 
| 1.3inch OLED Module (C) || <pre>sudo python OLED_1in3_test.py</pre>
 
|-
 
| 1.5inch OLED Module || <pre>sudo python OLED_1in5_test.py</pre>
 
|-
 
| 1.5inch RGB OLED Module || <pre>sudo python OLED_1in5_rgb_test.py</pre>
 
|}
 
*Please make sure that the SPI is not occupied by other devices, you can check in the middle of /boot/config.txt
 
 
 
==Description of C codes==
 
==='''Hardware interface'''===
 
We have carried out the low-level encapsulation, if you need to know the internal implementation can go to the corresponding directory to check, for the reason that the hardware platform and the internal implementation are different <br>
 
 
 
You can open DEV_Config.c(.h) to see definitions,which in the directory RaspberryPi\c\lib\Config<br>
 
<pre>
 
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: 
 
</pre>
 
[[File:RPI_open_spi1.png|900px]]<br />
 
*Interface selection:
 
<pre>
 
#define USE_SPI_4W  1
 
#define USE_IIC    0
 
Note:
 
    Modified here directly to switch SPI/I2C.
 
</pre>
 
*Data type
 
<pre>
 
#define UBYTE      uint8_t
 
#define UWORD      uint16_t
 
#define UDOUBLE    uint32_t
 
</pre>
 
*Module initialization and exit processing.
 
<pre>
 
void DEV_Module_Init(void);
 
void DEV_Module_Exit(void);
 
Note:
 
  Here is some GPIO processing before and after using the LCD screen.
 
</pre>
 
*Write GPIO.
 
<pre>
 
void DEV_Digital_Write(UWORD Pin, UBYTE Value)
 
Parameter:
 
    UWORD Pin: GPIO Pin number
 
UBYTE Value:
 
    level to be output, 0 or 1
 
</pre>
 
*Read GPIO.
 
<pre>
 
UBYTE DEV_Digital_Read(UWORD Pin)
 
Parameter:
 
    UWORD Pin:GPIO Pin number
 
    Return value: level of GPIO, 0 or 1
 
</pre>
 
*GPIO mode setting  .
 
<pre>
 
void DEV_GPIO_Mode(UWORD Pin, UWORD Mode)
 
Parameters:
 
    UWORD Pin: GPIO Pin number
 
    UWORD Mode: Mode, 0: input, 1: output
 
</pre>
 
 
 
==='''GUI functions'''===
 
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).<br>
 
[[File:RPI_open_spi-GUI.png|900px]]<br />
 
The fonts can be found in RaspberryPi\c\lib\Fonts directory.<br />
 
[[File:RPI_open_spi3.png|900px]]<br />
 
 
 
*New Image Properties: Create a new image buffer, this property includes the image buffer name, width, height, flip Angle, color.<br />
 
<pre>
 
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;
 
</pre>
 
 
 
*Select image buffer: The purpose of the selection is that you can create multiple image attributes, there can be multiple images buffer, you can select each image you create.<br />
 
<pre>
 
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;
 
</pre>
 
 
 
*Image Rotation: Set the rotation Angle of the selected image, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.<br />
 
<pre>
 
void Paint_SetRotate(UWORD Rotate)
 
Parameters:
 
        Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees.
 
</pre>
 
 
 
*Sets the size of the pixels.<br />
 
<pre>
 
void Paint_SetScale(UBYTE scale)
 
Parameters:
 
scale: the size of pixels, 2: each pixel occupies one bit; 4: Each pixel occupies two bits.
 
</pre>
 
 
 
*Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror,  horizontal mirror, vertical mirror, or image center mirror.<br />
 
<pre>
 
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.
 
</pre>
 
 
 
*Set points of the display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.<br />
 
<pre>
 
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
 
</pre>
 
 
 
*Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.
 
<pre>
 
void Paint_Clear(UWORD Color)
 
Parameters:
 
        Color: fill Color
 
</pre>
 
 
 
*The fill color of a certain window in the image buffer: the image buffer part of the window filled with a certain color, usually used to fresh the screen into blank, often used for time display, fresh the last second of the screen.
 
<pre>
 
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
 
</pre>
 
 
 
*Draw point: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, the style of the point.<br />
 
<pre>
 
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 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;
 
</pre>
 
 
 
*Draw line: In the image buffer, draw line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width and the style of the line.<br />
 
<pre>
 
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: the y-starting coordinate of the a 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 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;
 
</pre>
 
 
 
* Draw rectangle: In the image buffer, draw a rectangle from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width of the line, whether to fill the inside of the rectangle.<br />
 
<pre>
 
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 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;
 
</pre>
 
*Draw circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.<br />
 
<pre>
 
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 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;
 
</pre>
 
*Write Ascii character: In the image buffer, use (Xstart Ystart) as the left vertex, write an Ascii character, you can select Ascii visual character library, font foreground color, font background color.
 
<pre>
 
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
 
</pre>
 
*Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, write a string of English characters, you can choose Ascii visual character library, font foreground color, font background color.<br />
 
<pre>
 
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
 
</pre>
 
*Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, write a string of Chinese characters, you can choose character font, font foreground color, font background color of the GB2312 encoding
 
<pre>
 
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
 
</pre>
 
*Write numbers: In the image buffer,use (Xstart Ystart) as the left vertex, write a string of numbers, you can choose Ascii visual character library, font foreground color, font background color.
 
<pre>
 
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
 
</pre>
 
*Display time: in the image buffer,use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font background color.;
 
<pre>
 
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
 
</pre>
 
 
 
==Python(for Raspberry Pi)==
 
It is compatible with python2.7 and python3.<br />
 
The calls of the python are less complex compared to C demo.
 
==='''config.py'''===
 
*Select interface.
 
<pre>
 
Device_SPI = 1
 
Device_I2C = 0
 
Note: Switch SPI/I2C modified here
 
</pre>
 
*Module initialization and exit processing.
 
<pre>
 
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
 
</pre>
 
*SPI write data.
 
def spi_writebyte(data)
 
*IIC write data. 
 
i2c_writebyte(reg, value):
 
 
 
==='''main.py'''===
 
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
 
 
 
==='''GUI functions'''===
 
Python has an image library [http://effbot.org/imagingbook PIL official library link], it do not need to write code from the logical layer like C, can directly call to the image library for image processing. The following will take 1.54inch LCD as an example, we provide a brief description for the demo.
 
*It needs to use the image library and install the library.
 
sudo apt-get install python3-pil 
 
And then import the library<br />
 
from PIL import Image,ImageDraw,ImageFont.
 
Among them, Image is the basic library, ImageDraw is the drawing function, and ImageFont is the text function.
 
*Define an image buffer
 
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".
 
 
 
*Create a drawing object based on Image1 on which all drawing operations will be performed on here.
 
draw = ImageDraw.Draw(image1)
 
*Draw line.
 
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.
 
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 circle.
 
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 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 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.
 
*Character.
 
The ImageFont module needs to be imported and instantiated:
 
<pre>
 
Font1 = ImageFont.truetype("../Font/Font01.ttf",25)
 
Font2 = ImageFont.truetype("../Font/Font01.ttf",35)
 
Font3 = ImageFont.truetype("../Font/Font02.ttf",32)
 
</pre>
 
You can use the fonts of Windows or other fonts which is in ttc format..<br />
 
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 character, you can directly use the fonts; for Chinese character, you need to add a symbol u:
 
<pre>
 
draw.text((5, 68), 'Hello world', fill = 0, font=Font1)
 
text= u"微雪电子"
 
draw.text((5, 200), text, fill = 0, font=Font3)
 
</pre>
 
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’微雪电子’, font color is white.
 
*Read local picture.
 
image = Image.open('../pic/pic.bmp')
 
The parameter is the image path.
 
*Other functions.
 
Python's image library is very powerful, if you need to implement more, you can learn on the website http://effbot.org/imagingbook pil.
 
  
 
=Working with STM32=
 
=Working with STM32=
Provides routines based on STM32F103RBT6
+
Provides demos based on STM32F103RBT6.
 
===Hardware Coonnection===
 
===Hardware Coonnection===
The examples are based on STM32F103RBT6 as well as the connection table. If you want to use other MCU, you need to port the project and change the connection according to the actual hardware.
+
The examples are based on STM32F103RBT6 as well as the connection table. If you want to use another MCU, you need to port the project and change the connection according to the actual hardware.
 
{|border=1; style="width:700px;" align="center"
 
{|border=1; style="width:700px;" align="center"
 
|+Connect to STM32F103RBT6
 
|+Connect to STM32F103RBT6
Line 672: Line 143:
 
|RST||PA9
 
|RST||PA9
 
|}
 
|}
*Four-wire SPI wiring diagram
+
*Four-wire SPI wiring diagram.
 
[[File:600px-1.5inch_OLED_Module-STM32.jpg|600px]]
 
[[File:600px-1.5inch_OLED_Module-STM32.jpg|600px]]
 
+
{{OLED stm32 code analyze}}
===Run the demo===
 
*Download the demo, find the STM32 demo file directory, use Keil5 to open oled_demo.uvprojx in the \STM32\STM32-F103RBT6\MDK-ARM directory.
 
*Then modify the corresponding function comment in main.c according to the LCD model you are using, and then recompile and download to your board.
 
:[[File:OLED STM32 code0.png|500px]]
 
*For examples, if you are using 1.3inch OLED Module (C),you need to comment out the line 105. (Note: there cannot be multiple sentences without comment at the same time; the line number may be changed, please modify it according to the actual situation)
 
*The demo folder of each LCD model can fine in the following table:
 
{| class="wikitable"
 
|-
 
! LCD Model !! Demo function
 
|-
 
| 0.91inch OLED Module || <pre>OLED_0in91_test();</pre>
 
|-
 
|  0.95inch RGB OLED (A)/(B) || <pre>OLED_0in95_rgb_test();</pre>
 
|-
 
|  0.96inch OLED (A)/(B) || <pre>OLED_0in96_test();</pre>
 
|-
 
| 1.3inch OLED (A)/(B) || <pre>OLED_1in3_test();</pre>
 
|-
 
| 1.3inch OLED Module (C) || <pre>OLED_1in3_c_test();</pre>
 
|-
 
| 1.5inch OLED Module || <pre>OLED_1in5_test();</pre>
 
|-
 
| 1.5inch RGB OLED Module || <pre>OLED_1in5_rgb_test();</pre>
 
|}
 
===Software description===
 
*The demo is developed based on the HAL library. Download the demo, find the STM32 program file directory, and open the oled_demo.uvprojx in the STM32\STM32F103RBT6\MDK-ARM directory to check the program.
 
:[[File:OLED_STM32_code1.png|500px]]
 
*In addition, you can see the file directory of the project in the STM32\STM32-F103RBT6\User\ directory. The five folders are the underlying driver, sample program, font, GUI, and OLED driver.
 
:[[File:OLED_STM32_code2.png|600px]]
 
 
 
===Demo description===
 
===='''Hardware interface'''====
 
We package the bottom for different hardware platforms.
 
You can check the DEV_Config.c(.h) file for more description.<br />
 
*Interface selection
 
<pre>
 
#define USE_SPI_4W 1
 
#define USE_IIC              0
 
#define USE_IIC_SOFT 0
 
Note:
 
    Switch SPI/I2C directly modified here
 
</pre>
 
*Data type
 
<pre>
 
#define UBYTE      uint8_t
 
#define UWORD      uint16_t
 
#define UDOUBLE    uint32_t
 
</pre>
 
*Module initialization and exit processing
 
<pre>
 
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;
 
</pre>
 
*Write and read GPIO
 
<pre>
 
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
 
UBYTE DEV_Digital_Read(UWORD Pin);
 
</pre>
 
 
 
* SPI write data
 
UBYTE SPI4W_Write_Byte(uint8_t value);
 
* IIC write data
 
void I2C_Write_Byte(uint8_t value, uint8_t Cmd);
 
 
 
===='''Application function'''====
 
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)<br />
 
[[File:OLED_STM32_code3.png|500px]]<br />
 
The character font which GUI dependent is in the directory STM32\STM32F103RB\User\Fonts<br />
 
[[File:OLED_STM32_code4.png|500px]]
 
*New Image Properties: Create a new image property, this property includes the image buffer name, width, height, flip Angle, color.
 
<pre>
 
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;
 
</pre>
 
*Set the clear screen function
 
<pre>
 
void Paint_SetClearFuntion(void (*Clear)(UWORD));
 
parameter:
 
    Clear : Pointer to the clear screen function, used to quickly clear the screen to a certain color;
 
</pre>
 
*Set the drawing pixel function.
 
<pre>
 
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;
 
</pre>
 
*Select image buffer: the purpose of the selection is that you can create multiple image attributes, there can be multiple images buffer, you can select each image you create.
 
<pre>
 
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
 
</pre>
 
*Image Rotation: Set the selected image rotation Angle, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.
 
<pre>
 
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;
 
</pre>
 
*Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror, horizontal mirror, vertical mirror, or image center mirror.
 
<pre>
 
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.
 
</pre>
 
*Set points of display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.
 
<pre>
 
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
 
</pre>
 
*Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.
 
<pre>
 
void Paint_Clear(UWORD Color)
 
Parameters:
 
    Color: fill Color
 
</pre>
 
*The fill color of a certain window in the image buffer: the image buffer part of the window filled with a certain color, usually used to fresh the screen into blank, often used for time display, fresh the last second of the screen.
 
<pre>
 
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
 
</pre>
 
*Draw point: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, the style of the point.
 
<pre>
 
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;
 
</pre>
 
*Draw line: In the image buffer, draw line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, line width, line style. 
 
<pre>
 
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;
 
</pre>
 
* Draw rectangle: In the image buffer, draw a rectangle from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width of the line, whether to fill the inside of the rectangle.
 
<pre>
 
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;
 
</pre>
 
*Draw circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.
 
<pre>
 
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;
 
</pre>
 
*Write Ascii character: In the image buffer, use (Xstart Ystart) as the left vertex, write an Ascii character, you can select Ascii visual character library, font foreground color, font background color.
 
<pre>
 
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
 
</pre>
 
*Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, write a string of English characters, you can choose Ascii visual character library, font foreground color, font background color.
 
<pre>
 
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
 
</pre>
 
*Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, write a string of Chinese characters, you can choose GB2312 encoding character font, font foreground color, font background color.
 
<pre>
 
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
 
</pre>
 
*Write numbers: In the image buffer,use (Xstart Ystart) as the left vertex, write a string of numbers, you can choose Ascii visual character library, font foreground color, font background color.
 
<pre>
 
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
 
</pre>
 
*Display time: in the image buffer,use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font background color.
 
<pre>
 
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
 
</pre>
 
  
 
=Arduino Tutorial=
 
=Arduino Tutorial=
Provides routines based on UNO PLUS
+
Provides demos based on UNO PLUS
 
===Hardware connection===
 
===Hardware connection===
 
{|border=1; style="width:700px;" align="center"
 
{|border=1; style="width:700px;" align="center"
Line 1,013: Line 171:
 
*I2C connection
 
*I2C connection
 
[[File:600px-1.5inch_OLED_Module-Aduino .jpg|600px]]
 
[[File:600px-1.5inch_OLED_Module-Aduino .jpg|600px]]
 
+
===IDE Installation===
===Run the demo===
+
*[https://www.waveshare.com/wiki/Arduino_ide_download Arduino IDE Installation]
*Download the demo and find the Arduino demo file directory.
 
*Use Arduino IDE to open the .ino file in the project folder of the corresponding model, recompile and download the demo to your board.
 
*For example, if you are using the 1.3inch OLED Module (C), open OLED_1in3_c.ino under the \Arduino\OLED_1in3_c directory
 
 
 
 
===Software description===
 
===Software description===
*Download the demo on the Resources, open the Arduino demo file directory, you can see the Arduino program of different models of OLED.
+
*Download the demo on the Resources, open the Arduino demo file directory, and you can see the Arduino program for different models of OLED.
 
:[[File:OLED_Arduino_code1.png|600px]]
 
:[[File:OLED_Arduino_code1.png|600px]]
 
*Choose the folder according to the LCD model you are using, and open the xxx.ino file. Take the 1.3inch OLED Module (C) as an example: open OLED_1in3_c, then double-click OLED_1in3_c.ino to open the Arduino project.
 
*Choose the folder according to the LCD model you are using, and open the xxx.ino file. Take the 1.3inch OLED Module (C) as an example: open OLED_1in3_c, then double-click OLED_1in3_c.ino to open the Arduino project.
 
:[[File:OLED_Arduino_code2.png|700px]]
 
:[[File:OLED_Arduino_code2.png|700px]]
*The demo folder of each LCD model can fine in the following table:
+
*The demo folder of each LCD model can find in the following table:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! LCD Model !! Demo folder
+
! Screen Model!! Demo Function
 
|-
 
|-
 
| 0.91inch OLED Module || OLED_0in91
 
| 0.91inch OLED Module || OLED_0in91
Line 1,034: Line 188:
 
|-
 
|-
 
|  0.96inch OLED (A)/(B) || OLED_0in96
 
|  0.96inch OLED (A)/(B) || OLED_0in96
 +
|-
 +
|  0.96inch OLED Module (C)/(D)/(E) || OLED_0in96
 +
|-
 +
| 1.27inch RGB OLED Module || OLED_1in27_rgb
 
|-
 
|-
 
| 1.3inch OLED (A)/(B) || OLED_1in3
 
| 1.3inch OLED (A)/(B) || OLED_1in3
 
|-
 
|-
 
| 1.3inch OLED Module (C) || OLED_1in3_c
 
| 1.3inch OLED Module (C) || OLED_1in3_c
 +
|-
 +
| 1.32inch OLED Module || OLED_1in32
 
|-
 
|-
 
| 1.5inch OLED Module || OLED_1in5
 
| 1.5inch OLED Module || OLED_1in5
Line 1,079: Line 239:
  
 
===='''The upper application'''====
 
===='''The upper application'''====
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 STM32\STM32F103RB\User\GUI\GUI_Paint.c(.h)
+
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 STM32\STM32F103RB\User\GUI\GUI_Paint.c(.h).<br />
 
[[File:OLED_STM32_code3.png|500px]]<br />
 
[[File:OLED_STM32_code3.png|500px]]<br />
 
The character font which GUI dependent is in the directory STM32\STM32F103RB\User\Fonts<br />
 
The character font which GUI dependent is in the directory STM32\STM32F103RB\User\Fonts<br />
Line 1,324: Line 484:
 
Provide a full set of documents, procedures, data sheets, etc.
 
Provide a full set of documents, procedures, data sheets, etc.
 
==Documentation==
 
==Documentation==
*[https://www.waveshare.net/w/upload/c/ce/1.5inch_OLED_Moudule.pdf Schematic]
+
*[https://files.waveshare.com/upload/c/ce/1.5inch_OLED_Moudule.pdf Schematic]
  
 
==Program==
 
==Program==
*[[:File:OLED_Module_Code (9).7z|Demo Code]]
+
*[https://files.waveshare.com/upload/2/2c/OLED_Module_Code.7z Demo Code]
  
==3D drawings==
 
*[https://www.waveshare.net/w/upload/c/c5/1.5inch_RGB_OLED_3D_Drawing.zip 3D Drawing]
 
 
==Software==
 
==Software==
*[https://www.waveshare.net/w/upload/7/78/LcmZimo.zip LCD]
+
*[https://files.waveshare.com/upload/7/78/LcmZimo.zip LCD]
*[https://www.waveshare.net/w/upload/b/bd/Image2Lcd2.9.zip Image2lcd]
+
*[https://files.waveshare.com/upload/b/bd/Image2Lcd2.9.zip Image2lcd]
  
 
==Data sheet==
 
==Data sheet==
*[https://www.waveshare.net/w/upload/a/ac/SSD1327-datasheet.pdf SDD1327 Datasheet]
+
*[https://files.waveshare.com/upload/a/ac/SSD1327-datasheet.pdf SDD1327 Datasheet]
<!-- *[https://{{SERVERNAME}}/w/upload/4/43/UG-2828GDEDF11.pdf UG-2828GDEDF11 User Manual] -->
+
*[https://files.waveshare.com/upload/c/c3/1.5inch_OLED_Specification.pdf 1.5inch OLED Datasheet]
*[https://www.waveshare.net/w/upload/c/c3/1.5inch_OLED_Specification.pdf 1.5inch OLED Datasheet]
+
 
 
 
==3D drawings==
 
==3D drawings==
[https://www.waveshare.net/w/upload/f/f3/1in5_OLED_Drawing.zip 1.5inch OLED Module 3D drawings]
+
*[https://files.waveshare.com/upload/f/f3/1in5_OLED_Drawing.zip 1.5inch OLED Module 3D drawings]
 +
==2D drawings==
 +
*[https://files.waveshare.com/wiki/1.5inch%20OLED%20Module/1_5inch_oled_module_size.pdf 1.5inch OLED Module 2D drawings_PDF]
 +
*[https://files.waveshare.com/wiki/1.5inch%20OLED%20Module/1IN5_OLED_2D_Drawing.zip 1.5inch OLED Module 2D drawings_DXF]
 
</div>
 
</div>
 
<div class="tabbertab" title="Support">
 
<div class="tabbertab" title="Support">
Line 1,353: Line 513:
 
2. The same picture cannot be displayed for a long time, otherwise it will produce afterimages and cause damage to the OLED.<br/>
 
2. The same picture cannot be displayed for a long time, otherwise it will produce afterimages and cause damage to the OLED.<br/>
 
}}
 
}}
{{Service00}}
+
=Support=
 +
{{Servicebox1}}
 
</div>
 
</div>
 
</div>
 
</div>

Latest revision as of 09:12, 8 March 2024

1.5inch OLED Module
1.5inch OLED Module

1.5inch RGB OLED Module, I2C interfaces,
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Introduction

1.5inch OLED Module provide Raspberry Pi, STM32, Arduino demos.

Specification

  • Controller: SSD1327
  • Support interface: 4-wire SPI/I2C
  • Resolution: 128 x 128
  • Display size: 1.5inch
  • Dimensions: 44.5mm * 37mm
  • Display color: 16-bit grayscale
  • Working voltage: 3.3V/5V

Pinout

PIN Description
VCC Power input
GND Ground
DIN Data input
SCL Clock input
CS Chip select
DC Data/command signal selection
RST Reset signal

Hardware Configuration

1.5inch oled module.png
The module uses 4-wire SPI communication by default, that is, BS0 is connected to 0 by default (1 and 0 do not represent the level, but the welding method of resistance connection, the specific hardware connection is shown in the table below);
Note: The picture above is the welding on the hardware, and the table below is the actual hardware connection.

Letter of agreement BS CS DC DIN CLK
4Wire SPI 0 Chip Select DC MOSI SCK
I2C 1 dangling 0/1 SDA SCL

The specific hardware configuration is as follows:
Use 4-wire SPI: the factory setting, BS is connected to 0 and connected to GND, DIN is connected to the control pin MOSI, and CLK is connected to the control pin SCK;
Using I2C: BS is connected to 1 and connected to VCC, DIN is connected to control pin SDA, CLK is connected to control pin SCL, CS can be left unconnected, but do not leave DC floating, this pin is used to configure the address of the I2C slave device and is connected to a high-level OLED device The address is 0X3D, and the address of the OLED device connected to a low level is 0X3C.
PS: The program defaults to SPI mode. If you need to switch the mode, please modify DEV_Config.h. For details, please refer to the program description - bottom hardware interface - interface selection

Working Principle

  • SSD1327 is a 128*128 pixel OLED controller, and the OLED used in this product has a built-in secondary controller, and the controller can support 16-bit grayscale display, so that some pictures within 16-bit grayscale can be displayed;
  • The OLED supports 8bit 8080 parallel, 8bit 6800 parallel, three-wire SPI, four-wire SPI and I2C control. Because parallel control will waste IO ports, three-wire SPI is not commonly used, so the module can choose four-wire SPI and I2C control.
  • The controller can support 16-bit depth images, and the 16-bit depth can be controlled by 4 bits. The controller also handles this in hardware: 1 byte controls two pixels, so if the controller uses horizontal scanning, the control difficulty is the lowest . (For details, please refer to the data sheet: page30)

1.5inch oled module data.png

SPI protocol

1.5inch oled module spi.png
Note: The difference from the traditional SPI protocol is that the data line sent from the slave to the host is hidden because it only needs to be displayed. Please refer to Datasheet Page 21 for the table.

  • CS# is the slave chip select, and the chip will be enabled only when CS is low.
  • D/C# is the data/command control pin of the chip, write command when DC = 0, write data when DC = 1
  • SDIN is the transmitted data, that is, a 16-bit grayscale image;
  • SCLK is the SPI communication clock.
  • For SPI communication, data is transmitted with timing, that is, the combination of clock phase (CPHA) and clock polarity (CPOL):
  • The level of CPOL determines the idle state level of the serial synchronous clock. CPOL = 0, which is a low level. CPOL does not have much impact on the transport protocol;
  • The level of CPHA determines whether the serial synchronization clock is collected on the first clock transition edge or the second clock transition edge. When CPHL = 0, data acquisition is performed on the first transition edge;
  • The combination of the two becomes four SPI communication methods. SPI0 is usually used in China, that is, CPHL = 0, CPOL = 0

I2C protocol

1.5inch oled module I2C.png
See Datasheet Page 23 for details

  1. send a 7-byte slave device address + a byte of read and write bits, and then wait for the response from the slave device. This is similar to most I2C communications. Changing the 7-bit address can be controlled by the DC pin;
  2. send one data bit + one command data bit + 6 control own bytes, in fact, the useful thing is that the command data is, this bit is set to 0 to write the command, and set to 1 is to write the data;
  3. send 8 bits of data. Such a control transfer is complete.

Note: OLED data cannot be read when the controller uses serial communication.

Raspberry Pi Guide

This product provides BCM2835, WiringPi, file IO, RPI (Python) library routines

Hardware connection

When connecting the Raspberry Pi, choose to use the 7PIN cable to connect, please refer to the pin correspondence table below.

Raspberry Pi connection pin correspondence
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
  • Four-wire SPI wiring diagram

600px-1.5inch OLED Module-树莓派.jpg

Enable SPI and I2C Interface

  • Open the Raspberry Pi and enter the following command to access the configuration interface:
sudo raspi-config
Select Interfacing Options -> SPI -> Yes to enable the SPI interface

RPI open spi.png
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.

Install Library

If you use bookworm system, you can only use lgpio library, bcm2835 and wiringPi can't be installed and used.

BCM2835

#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/

WiringPi

#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.

lgpio

#Enter the Raspberry Pi and run the following commands:
wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
sudo make install

#For more details, you can refer to the official website: https://github.com/gpiozero/lg

Python

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 spidev
sudo apt-get install python3-smbus

Download the Test Demo

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

Run the Test Demo

The following commands should be executed in the RaspberryPi directory, otherwise, the directory will not be indexed:

C

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.49inch OLED Module  
sudo ./main 0.49
------------------------------
#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 Transparent OLED
sudo ./main 1.51
------------------------------
#1.54inch OLED Module
sudo ./main 1.54
------------------------------
#2.42inch OLED Module
sudo ./main 2.42

Python

  • Enter the Python demo directory:
cd python/example
  • Run the demo corresponding to the OLED model, the demo supports python2/3:

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
  • Model instruction correspondence table:
#0.49inch OLED Module 
sudo python OLED_0in49_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 Transparent OLED
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
  • Please make sure that the SPI is not occupied by other devices, you can check in the middle of /boot/config.txt.

Description of C codes (API)

Hardware Interface

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:
RPI open spi1.png
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

  • Interface selection:
#define USE_SPI_4W  1
#define USE_IIC     0
Note: Modified here directly to switch SPI/I2C
  • Data type:
#define UBYTE      uint8_t
#define UWORD      uint16_t
#define UDOUBLE    uint32_t
  • Module initialization and exit processing.
void DEV_Module_Init(void);
void DEV_Module_Exit(void);
Note: 
  Here is some GPIO processing before and after using the LCD screen.
  • Write GPIO:
void DEV_Digital_Write(UWORD Pin, UBYTE Value)
Parameter: 
     UWORD Pin: GPIO Pin number
     UBYTE Value: level to be output, 0 or 1
  • Read GPIO:
UBYTE DEV_Digital_Read(UWORD Pin)
Parameter:
     UWORD Pin: GPIO Pin number
     Return value: level of GPIO, 0 or 1
  • GPIO mode setting:
void DEV_GPIO_Mode(UWORD Pin, UWORD Mode)
Parameters: 
     UWORD Pin: GPIO Pin number
     UWORD Mode: Mode, 0: input, 1: output

GUI Functions

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).
C-GUI.png
The fonts can be found in RaspberryPi\c\lib\Fonts directory.
RPI open spi3.png

  • New image properties: Create a new image buffer, this property includes the image buffer name, width, height, flip angle, and color.
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;
  • Select image buffer: The purpose of the selection is that you can create multiple image attributes, there can be multiple image buffers, and you can select each image you create.
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;
  • Image rotation: Set the rotation Angle of the selected image, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.
void Paint_SetRotate(UWORD Rotate)
Parameters:
        Rotate: ROTATE_0, ROTATE_90, ROTATE_180, and ROTATE_270 correspond to 0, 90, 180, and 270 degrees.
  • Sets the size of the pixels:
void Paint_SetScale(UBYTE scale)
Parameters:
	scale: the size of pixels, 2: each pixel occupies one bit; 4: Each pixel occupies two bits.
  • Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror, horizontal mirror, vertical mirror, or image center mirror.
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.
  • Set points of the display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.
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
  • Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.
void Paint_Clear(UWORD Color)
Parameters:
        Color: fill Color
  • The fill color of a certain window in the image buffer: the image buffer part of the window filled with a certain color, usually used to fresh the screen into blank, often used for time display, fresh the last second of the screen.
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
  • Draw point: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, the style of the point.
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;
  • Draw the line: In the image buffer, draw a line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width and the style of the line.
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;
  • Draw a rectangle: In the image buffer, draw a rectangle from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width of the line, and whether to fill the inside of the rectangle.
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;
  • Draw circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.
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;
  • Write Ascii character: In the image buffer, use (Xstart Ystart) as the left vertex, and write an Ascii character, you can select Ascii visual character library, font foreground color, and font background color.
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
  • Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, and write a string of English characters, you can choose Ascii visual character library, font foreground color, and font 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
  • Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, and write a string of Chinese characters, you can choose character font, font foreground color, and font background color of the GB2312 encoding.
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
  • Write numbers: In the image buffer, use (Xstart Ystart) as the left vertex, and write a string of numbers, you can choose Ascii visual character library, font foreground color, and font 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
  • Display time: in the image buffer, use (Xstart Ystart) as the left vertex, display time, you can choose Ascii visual character font, font foreground color, and font 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

Python (for Raspberry Pi)

It is compatible with python and python3.
The calls of python are less complex compared to the C demo.

Config.py

  • Select interface.
Device_SPI = 1
Device_I2C = 0
Note: Switch SPI/I2C modified here. 
  • Module initialization and exit processing.
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
  • SPI writes data.
def spi_writebyte(data)
  • IIC writes data.
i2c_writebyte(reg, value):

Main.py

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

GUI Functions

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.

  • It needs to use the image library and install the library.
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.

  • Define an image buffer:
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".

  • Create a drawing object based on Image1 on which all drawing operations will be performed on here.
draw = ImageDraw.Draw(image1)
  • Draw a line:
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 a rectangle:
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 a circle:
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.

  • Write a character:

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.

  • Read local pictures:
image = Image.open('../pic/pic.bmp')

The parameter is the image path.

  • Other functions:

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.

Working with STM32

Provides demos based on STM32F103RBT6.

Hardware Coonnection

The examples are based on STM32F103RBT6 as well as the connection table. If you want to use another MCU, you need to port the project and change the connection according to the actual hardware.

Connect to STM32F103RBT6
OLED STM32
VCC 3.3V
GND GND
DIN SPI:PA7/I2C:PB9 / I2C_SOFT:PC8
SCL SPI:PA5/I2C:PB8 / I2C_SOFT:PC6
CS PB6
DC PA8
RST PA9
  • Four-wire SPI wiring diagram.

600px-1.5inch OLED Module-STM32.jpg

Run the demo

  • Download the program, find the STM32 program file directory, use STM32CubeIDE to open the .cproject in the \STM32\STM32F103RBT6\ directory.
  • Then modify the corresponding function comment in the main.c according to the LCD model you are using, and then recompile and download to your board.
OLED STM32 code0.png
  • If you are using a 1.3-inch OLED Module (C), you need to comment out line 105. (Note: there cannot be multiple sentences without comment at the same time; the line number may be changed, please modify it according to the actual situation.)
  • The demo folder of each LCD model can be found in the following table:
Model Demo Function
0.49inch OLED Module OLED_0in49_test();
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();

Software description

  • The demo is developed based on the HAL library, and the software used is STM32CubeIDE. Download the demo, find the STM32 demo file directory, and open the .cproject in the STM32\STM32F103RBT6\ directory to see the demo.
OLED STM32 code71.jpg
  • In addition, you can see the file directory of the project in the STM32\STM32-F103RBT6\User\ directory. The five folders are the underlying driver, sample demo, font, GUI, and OLED driver.
OLED STM32 code72.jpg

Demo description

Hardware interface

We package the bottom for different hardware platforms. You can check the DEV_Config.c(.h) file for more description.

  • Interface selection
#define USE_SPI_4W 		 1
#define USE_IIC      	         0
#define USE_IIC_SOFT		 0
Note: Switch SPI/I2C directly modified here
  • Data type
#define UBYTE      uint8_t
#define UWORD      uint16_t
#define UDOUBLE    uint32_t
  • Module initialization and exit processing:
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;
  • Write and read GPIO:
void 	DEV_Digital_Write(UWORD Pin, UBYTE Value);
UBYTE 	DEV_Digital_Read(UWORD Pin);
  • SPI writes data:
UBYTE	 SPI4W_Write_Byte(uint8_t value);
  • IIC writes data:
void	 I2C_Write_Byte(uint8_t value, uint8_t Cmd);

Application Function

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)
OLED STM32 code3.png
The character font GUI dependent is in the directory STM32\STM32F103RB\User\Fonts
OLED STM32 code4.png

  • New image properties: Create a new image property, this property includes the image buffer name, width, height, flip Angle, and color.
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;
  • Set the clear screen function:
void Paint_SetClearFuntion(void (*Clear)(UWORD));
parameter:
    Clear: Pointer to the clear screen function, used to quickly clear the screen to a certain color;
  • Set the drawing pixel function:
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;
  • Select image buffer: the purpose of the selection is that you can create multiple image attributes, there can be multiple images buffer, you can select each image you create.
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
  • Image rotation: Set the selected image rotation Angle, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.
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;
  • Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror, horizontal mirror, vertical mirror, or image center mirror.
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.
  • Set points of display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.
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
  • Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.
void Paint_Clear(UWORD Color)
Parameters:
    Color: fill Color
  • The fill color of a certain window in the image buffer: the image buffer part of the window filled with a certain color, usually used to fresh the screen into blank, often used for time display, fresh the last second of the screen.
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
  • Draw point: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, and the style of the point.
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;
  • Draw the line: In the image buffer, draw a line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, line width, and line 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;
  • Draw a rectangle: In the image buffer, draw a rectangle from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width of the line, and whether to fill the inside of the rectangle.
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;
  • Draw a circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.
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;
  • Write Ascii character: In the image buffer, use (Xstart Ystart) as the left vertex, and write an Ascii character, you can select Ascii visual character library, font foreground color, and font background color.
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
  • Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, and write a string of English characters, you can choose Ascii visual character library, font foreground color, or font 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
  • Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, and write a string of Chinese characters, you can choose GB2312 encoding character font, font foreground color, font 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
  • Write numbers: In the image buffer, use (Xstart Ystart) as the left vertex, and write a string of numbers, you can choose Ascii visual character library, font foreground color, font 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
  • Display time: in the image buffer, use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font 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

Arduino Tutorial

Provides demos based on UNO PLUS

Hardware connection

Arduino UNO connection
OLED UNO
VCC 5V
GND GND
DIN SPI:D11/I2C:SDA
CLK SPI:D13/I2C:SCL
CS D10
DC D7
RST D8
  • I2C connection

600px-1.5inch OLED Module-Aduino .jpg

IDE Installation

Software description

  • Download the demo on the Resources, open the Arduino demo file directory, and you can see the Arduino program for different models of OLED.
OLED Arduino code1.png
  • Choose the folder according to the LCD model you are using, and open the xxx.ino file. Take the 1.3inch OLED Module (C) as an example: open OLED_1in3_c, then double-click OLED_1in3_c.ino to open the Arduino project.
OLED Arduino code2.png
  • The demo folder of each LCD model can find in the following table:
Screen Model Demo Function
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
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 RGB OLED Module OLED_1in5_rgb

Program Description

Underlying hardware interface

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)

  • Interface selection
#define USE_SPI_4W 		 1
#define USE_IIC      	         0
Note:Switch SPI/I2C directly modified here
  • Data type
#define UBYTE      uint8_t
#define UWORD      uint16_t
#define UDOUBLE    uint32_t
  • Module initialization and exit processing
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;
  • Write and read GPIO
void 	DEV_Digital_Write(UWORD Pin, UBYTE Value);
UBYTE 	DEV_Digital_Read(UWORD Pin);
  • SPI write data
UBYTE	 SPI4W_Write_Byte(uint8_t value);
  • IIC write data
void	 I2C_Write_Byte(uint8_t value, uint8_t Cmd);

The upper application

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 STM32\STM32F103RB\User\GUI\GUI_Paint.c(.h).
OLED STM32 code3.png
The character font which GUI dependent is in the directory STM32\STM32F103RB\User\Fonts
OLED STM32 code4.png

  • New Image Properties: Create a new image property, this property includes the image buffer name, width, height, flip Angle, color.
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;
  • Set the clear screen function, usually call the clear function of OLED directly.
void Paint_SetClearFuntion(void (*Clear)(UWORD));
parameter:
    Clear : Pointer to the clear screen function, used to quickly clear the screen to a certain color;
  • Set the drawing pixel function.
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;
  • Select image buffer:the purpose of the selection is that you can create multiple image attributes, image buffer can exist multiple, you can select each image you create.
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
  • Image Rotation: Set the selected image rotation Angle, preferably after Paint_SelectImage(), you can choose to rotate 0, 90, 180, 270.
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;
  • Image mirror flip: Set the mirror flip of the selected image. You can choose no mirror, horizontal mirror, vertical mirror,or image center mirror.
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.
  • Set points of display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.
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
  • Image buffer fill color: Fills the image buffer with a color, usually used to flash the screen into blank.
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
  • Draw points: In the image buffer, draw points on (Xpoint, Ypoint), you can choose the color, the size of the point, the style of the point.
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;
  • Line drawing: In the image buffer, line from (Xstart, Ystart) to (Xend, Yend), you can choose the color, line width, line 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;
  • Draw rectangle: In the image buffer, draw a rectangle from (Xstart, Ystart) to (Xend, Yend), you can choose the color, the width of the line, whether to fill the inside of the rectangle.
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, whether to fill the inside of the rectangle
        typedef enum {
                DRAW_FILL_EMPTY = 0,
                DRAW_FILL_FULL,
        } DRAW_FILL;
  • Draw circle: In the image buffer, draw a circle of Radius with (X_Center Y_Center) as the center. You can choose the color, the width of the line, and whether to fill the inside of the circle.
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;
  • Write Ascii character: In the image buffer, at (Xstart Ystart) as the left vertex, write an Ascii character, you can select Ascii visual character library, font foreground color, font background color.
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
  • Write English string: In the image buffer, use (Xstart Ystart) as the left vertex, write a string of English characters, can choose Ascii visual character library, font foreground color, font 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
  • Write Chinese string: in the image buffer, use (Xstart Ystart) as the left vertex, write a string of Chinese characters, you can choose GB2312 encoding character font, font foreground color, font 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
  • Write numbers: In the image buffer,use (Xstart Ystart) as the left vertex, write a string of numbers, you can choose Ascii visual character library, font foreground color, font 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
  • Display time: in the image buffer,use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font 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

Resources

Provide a full set of documents, procedures, data sheets, etc.

Documentation

Program

Software

Data sheet

3D drawings

2D drawings

FAQ

 Answer:
OLED does not have a backlight, and the display is self-illuminating. Only connect VCC and GND, the OLED will not light up. Program control is required to brighten the OLED.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
1. Be careful not to connect the power supply in reverse.

2. The same picture cannot be displayed for a long time, otherwise it will produce afterimages and cause damage to the OLED.

{{{3}}}
{{{4}}}

{{{5}}}


Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 AM GMT+8 (Monday to Friday)