OLED(OLED)

The driver library uses the more universal software (simulated) IIC method to drive the OLED, but the Yahboom Self-balancing Robot V2 supports hardware IIC in the hardware circuit.

The content of this chapter only introduces OLED related methods, and does not introduce the implementation of software IIC

method

void OLED_I2C_Init()

Initialize OLED module

void OLED_Clear()

Clear the screen

void OLED_Refresh()

Refresh the screen

void OLED_Draw_Stringg(char *str, uint8_t x, uint8_t y, bool clear, bool refresh)

Write into the string at the specified location

parametertypeAnnotation
strchar *Want the string displayed by OLED
xuint8_tDraw the starting coordinates in the direction of string X
yuint8_tDraw the starting coordinates in the direction of the string y
clearboolWhether to empty the screen
refreshuint8_tWhether to screen immediately
After drawing is completed, you need to call the refresh method to display

void OLED_Draw_Line(char *str, uint8_t line, bool clear, bool refresh)

Write a string in a designated line /* Write a line of characters */

parametertypeAnnotation
strchar *Want the string displayed by OLED
lineuint8_tDisplay string in the first line
clearboolWhether to empty the screen
refreshuint8_tWhether to screen immediately
The default line height is 10

The following method is provided for driving chip SSD1306, which can be used for more detailed drawing operations

SSD1306_UpdateScreen()

The unit updates the OLED display content

Return valuetype
nonevoid

SSD1306_ToggleInvert()

Switch the color reversal of the OLED display

Return valuetype
nonevoid

SSD1306_Fill(SSD1306_COLOR_t Color)

Fill in the color of the screen

parametertypeAnnotation
ColorSSD1306_COLOR_tFill color
Return valuetype
nonevoid

SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color)

Draw a pixel in the specified coordinate

parametertypeAnnotation
xuint16_tX coordinate
yuint16_ty coordinate
colorSSD1306_COLOR_tPixel color
Return valuetype
nonevoid

SSD1306_GotoXY(uint16_t x, uint16_t y)

Set the drawing coordinates of the next character

parametertypeAnnotation
xuint16_tX coordinate
yuint16_ty coordinate
Return valuetype
nonevoid

SSD1306_Putc(char ch, FontDef_t *Font, SSD1306_COLOR_t color)

Draw a single character

parametertypeAnnotation
chcharCharacters to be drawn
FontFontDef_t*Font structure used
colorSSD1306_COLOR_tCharacter color
Return valuetype
nonechar

SSD1306_Puts(char *str, FontDef_t *Font, SSD1306_COLOR_t color)

Draw a string

parametertypeAnnotation
strchar*String to draw
FontFontDef_t*Font structure used
colorSSD1306_COLOR_tString color
Return valuetype
nonechar

SSD1306_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, SSD1306_COLOR_t c)

Draw a line

parametertypeAnnotation
x0uint16_tStarting point x coordinates
y0uint16_tStarting point y coordinate
x1uint16_tEnding point x coordinates
y1uint16_tEnding point y coordinates
cSSD1306_COLOR_tLine color
Return valuetype
void

SSD1306_DrawRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, SSD1306_COLOR_t c)

Drawing rectangle

parametertypeAnnotation
xuint16_tX coordinates in the upper left corner
yuint16_tY coordinate in the upper left corner
wuint16_tRectangular width
huint16_tRectangular height
cSSD1306_COLOR_tRectangular color
Return valuetype
nonevoid

SSD1306_DrawFilledRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, SSD1306_COLOR_t c)

Draw a rectangle

parametertypeAnnotation
xuint16_tX coordinates in the upper left corner
yuint16_tY coordinate in the upper left corner
wuint16_tRectangular width
huint16_tRectangular height
cSSD1306_COLOR_tRectangular color
Return valuetype
nonevoid

SSD1306_DrawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, SSD1306_COLOR_t color)

Draw a triangle

parametertypeAnnotation
x1uint16_tThe first point X coordinates
y1uint16_tThe first point y coordinates
x2uint16_tThe second point x coordinates
y2uint16_tThe second point y coordinates
x3uint16_tThird point X coordinates
y3uint16_tThe third point y coordinate
colorSSD1306_COLOR_tTriangular color
Return valuetype
nonevoid

SSD1306_DrawCircle(int16_t x0, int16_t y0, int16_t r, SSD1306_COLOR_t c)

Draw a circle

parametertypeAnnotation
x0int16_tThe x coordinate of the center of the circle
y0int16_tY coordinate of the center of the circle
rint16_tradius
cSSD1306_COLOR_tRound color
Return valuetype
nonevoid

SSD1306_DrawFilledCircle(int16_t x0, int16_t y0, int16_t r, SSD1306_COLOR_t c)

Draw a circle

parametertypeAnnotation
x0int16_tThe x coordinate of the center of the circle
y0int16_tY coordinate of the center of the circle
rint16_tradius
cSSD1306_COLOR_tFill in round colors
Return valuetype
nonevoid

ssd1306_I2C_Init()

Initialize I2C interface

Return valuetype
nonevoid

ssd1306_I2C_Write(uint8_t address, uint8_t reg, uint8_t data)

Write data to the specified address and register

parametertypeAnnotation
addressuint8_tI2C device address
reguint8_tRegister address
datauint8_tData to be written
Return valuetype
nonevoid

ssd1306_I2C_WriteMulti(uint8_t address, uint8_t reg, uint8_t *data, uint16_t count)

Write multiple data to the specified address and register

parametertypeAnnotation
addressuint8_tI2C device address
reguint8_tRegister address
datauint8_t*Pointing to data pointer
countuint16_tNumber of data to be written
Return valuetype
nonevoid

Example


#include "bsp_oled_i2c.h"
#include "bsp_oled.h"
int main() {
    OLED_I2C_Init();
    OLED_Clear();
    while(1) {
        OLED_DrawLine("Hello Yahboom!",1, 0, true, true);
    }
    return 0;
}