Data display of 0.96 inch OLED display based on STM32

Keywords: stm32 ARM

1, SPI (serial peripheral interface)

1.1 definition of SPI

SPI (Serial Peripheral Interface) is the Serial Peripheral Interface.
SPI is a high-speed, full duplex, synchronous communication bus, and only occupies four wires on the pins of the chip, saving the pins of the chip. SPI is a ring bus structure, which is composed of ss(cs), sck, sdi and sdo. The timing is mainly to exchange data between two bidirectional shift registers under the control of sck.
The rising edge sends, the falling edge receives, and the high bit sends first.
When the rising edge arrives, the level on the sdo will be sent to the register of the slave device.
When the falling edge arrives, the level on the sdi will be received into the register of the master device.

1.2 SPI connection mode

SS (slave select): select the signal line from the device, often referred to as chip select signal line.
SCK (Serial Clock): clock signal line, used for communication data synchronization.
MOSI (Master Output, Slave Input): master device output / slave device input pin.
MISO(Master Input, Slave Output): master device input / slave device output pin.

1.3 SPI communication process

MOSI and MISO signals are valid only when NSS is at low level. MOSI and MISO transmit one bit of data in each clock cycle of SCK.

2, Use 0.96 inch OLED display to display data

2.1 experimental tools and materials

Software: keil
Hardware: PC, STM32 development board, 0.96 inch OLED display, FlyMcu (burning software)

2.2 introduction to 0.96 inch OLED display

Refer to the following link: 0.96inch SPI OLED Module

A manufacturer's demo: demo download

2.3 connecting display screen and development board

2.4 Chinese character dot matrix coding - generate font

3, The student ID name is displayed on the OLED screen

3.1 experimental requirements

Display your student number and name on the OLED.

3.2 Chinese character dot matrix coding

  • Chinese character dot matrix of pen owner's name:

  • Location of encoded file:

  • Student ID Name:

3.3 experimental code

  • Pen owner's complete source file (Github):
    https://github.com/longl118/Namexuehao
    In fact, we only need to display Chinese characters. We can directly replace the output characters in the demo with the Chinese character dot matrix we want.

3.4 experimental results

  • Burn.
  • Display on OLED:

4, Temperature and humidity acquisition - OLED display

4.1 code

void read_AHT20(void)
{
	uint8_t   i;
	for(i=0; i<6; i++)
	{
		readByte[i]=0;
	}

	//-------------
	I2C_Start();

	I2C_WriteByte(0x71);
	ack_status = Receive_ACK();
	readByte[0]= I2C_ReadByte();
	Send_ACK();

	readByte[1]= I2C_ReadByte();
	Send_ACK();

	readByte[2]= I2C_ReadByte();
	Send_ACK();

	readByte[3]= I2C_ReadByte();
	Send_ACK();

	readByte[4]= I2C_ReadByte();
	Send_ACK();

	readByte[5]= I2C_ReadByte();
	SendNot_Ack();
	//Send_ACK();

	I2C_Stop();

	//--------------
	if( (readByte[0] & 0x68) == 0x08 )
	{
		H1 = readByte[1];
		H1 = (H1<<8) | readByte[2];
		H1 = (H1<<8) | readByte[3];
		H1 = H1>>4;

		H1 = (H1*1000)/1024/1024;

		T1 = readByte[3];
		T1 = T1 & 0x0000000F;
		T1 = (T1<<8) | readByte[4];
		T1 = (T1<<8) | readByte[5];

		T1 = (T1*2000)/1024/1024 - 500;

		AHT20_OutData[0] = (H1>>8) & 0x000000FF;
		AHT20_OutData[1] = H1 & 0x000000FF;

		AHT20_OutData[2] = (T1>>8) & 0x000000FF;
		AHT20_OutData[3] = T1 & 0x000000FF;
	}
	else
	{
		AHT20_OutData[0] = 0xFF;
		AHT20_OutData[1] = 0xFF;

		AHT20_OutData[2] = 0xFF;
		AHT20_OutData[3] = 0xFF;
		printf("lyy");

	}
	/*Display the collected temperature and humidity through the serial port
	printf("\r\n");
	printf("Temperature:% d%d.%d",T1/100,(T1/10)%10,T1%10);
	printf("Humidity:% d%d.%d",H1/100,(H1/10)%10,H1%10);
	printf("\r\n");*/
	t=T1/10;
	t1=T1%10;
	a=(float)(t+t1*0.1);
	h=H1/10;
	h1=H1%10;
	b=(float)(h+h1*0.1);
	sprintf(strTemp,"%.1f",a);   //Call the Sprintf function to format the temperature data of DHT11 into the string array variable strTemp  
    sprintf(strHumi,"%.1f",b);    //Call the Sprintf function to format the humidity data of DHT11 into the string array variable strHumi  
	GUI_ShowCHinese(16,00,16,"Temperature and humidity display",1);
	GUI_ShowCHinese(16,20,16,"temperature",1);
	GUI_ShowString(53,20,strTemp,16,1);
	GUI_ShowCHinese(16,38,16,"humidity",1);
	GUI_ShowString(53,38,strHumi,16,1);
	delay_ms(1500);		
	delay_ms(1500);
}
  • main function call
#include "delay.h"
#include "usart.h"
#include "bsp_i2c.h"
#include "sys.h"

#include "oled.h"
#include "gui.h"
#include "test.h"

int main(void)
{	
	delay_init();	    	       //Delay function initialization    	  
	uart_init(115200);	 
	IIC_Init();
		  
	NVIC_Configuration(); 	   //Set NVIC interrupt packet 2: 2-bit preemption priority and 2-bit response priority 	
	OLED_Init();			         //Initialize OLED  
	OLED_Clear(0); 
	while(1)
	{
		//printf("temperature and humidity display");
		read_AHT20_once();
		OLED_Clear(0); 
		delay_ms(1500);
  }
}

4.2 Chinese character dot matrix coding

"Wen", 0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8,
0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00,
"Wet", 0x00,0x00,0x27,0xF8,0x14,0x08,0x14,0x08,0x87,0xF8,0x44,0x08,0x44,0x08,0x17,0xF8,
0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,0x23,0x30,0x21,0x20,0x2F,0xFE,0x00,0x00,
"Degree", 0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20,
0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E,

4.3 experimental results

Burn first and then view the OLED display:

5, The OLED screen slides to display long characters

5.1 code

5.2 dot matrix Chinese character coding

  • to a sophisticated person there is nothing new under the sun

5.3 experimental results

  • In addition, the student number and name are scrolled out:

A little summary

This experiment let me know how to generate dot matrix Chinese character coding, typesetting and format.
The process of LED displaying Chinese characters is mainly an understanding of the corresponding word library and how to convert the dot matrix format into hexadecimal format.
In addition to the several Chinese dot matrices given, other displays are also stored according to the dot matrix. In fact, the whole display screen is also a dot matrix. The display process is to change each small dot in the whole dot matrix of the display screen, so as to realize the display.

reference

  1. Data display of 0.96 inch OLED display based on STM32
  2. stm32 realizes the acquisition of temperature and humidity (AHT20) through I2C interface

Posted by fipp on Fri, 26 Nov 2021 15:11:20 -0800