Docs

Micro-controllers, wireless transmission and database

Head

SSD1306 OLED I2C Display with Nucleo STM32F446RE using STM32CubeIDE

Prerequisites

This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with Nucleo STM32F446RE using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=oAwZ0cjlmN8

Wiring Diagram

Diagram

Image1

STM32CubeIDE Settings

Click connectivity --> Click I2C1

For I2C select I2C

Configuration --> Parameter Settings

For I2C speed select Fast Mode

Set PB8 to I2C1_SCL

Set PB9 to I2C1_SDA

Libraries

Inside Core/Inc Folder

fonts.h ssd1306.h

Inside Core/Src Folder

fonts.c ssd1306.c

Additional code on top of STM32CubeIDE generated code (main.c file)


/* USER CODE BEGIN Includes */
#include "fonts.h"
#include "ssd1306.h"
/* USER CODE END Includes */

/* USER CODE BEGIN 2 */
SSD1306_Init();
SSD1306_GotoXY (0,0);
SSD1306_Puts ("MICROPETA", &Font_11x18, 1);
SSD1306_GotoXY (0, 30);
SSD1306_Puts ("BY NIZAR", &Font_11x18, 1);
SSD1306_UpdateScreen();
HAL_Delay (1000);
SSD1306_ScrollRight(0,7);
HAL_Delay(3000);
SSD1306_ScrollLeft(0,7);
HAL_Delay(3000);
SSD1306_Stopscroll();
SSD1306_Clear();

int num=2024;
char snum[5];
SSD1306_GotoXY (30,20);
itoa(num, snum, 10);
SSD1306_Puts (snum, &Font_16x26, 1);
SSD1306_UpdateScreen();

//SSD1306_DrawLine(POINT1 X, POINT1 Y, POINT2 X, POINT2 Y, 1);
SSD1306_DrawLine(1,54,126,54,1);
SSD1306_UpdateScreen();
HAL_Delay (5000);
SSD1306_Clear();

// For Rectangle, we need to use two corner points
// SSD1306_DrawRectangle(POINT1 X, POINT1 Y, POINT2 X, POINT2 Y, 1);
SSD1306_DrawRectangle(17,1,115,14,1);
// SSD1306_DrawTriangle(POINT1X, POINT1Y, POINT2X, POINT2Y, POINT3X, POINT3Y, 1);
SSD1306_DrawTriangle(73,22,124,62,74,54,1);
// SSD1306_DrawCircle(CENTER POINT X, CENTER POINT Y, RADIUS, 1);
SSD1306_DrawCircle(34,50,13,1);
SSD1306_UpdateScreen();
/* USER CODE END 2 */