stm32 uses oled display and buttons to adjust PID parameters to realize human-computer interaction

stm32 uses oled display and buttons to adjust PID parameters to realize human-computer interaction


Last semester, I was working on a four-wheeled vehicle in school to use PID to walk in a straight line. During the debugging process, I used to download the program into the control board for debugging every time I changed a parameter, and observe whether the car was offset to determine the PID parameter, but then I found out This kind of efficiency is very slow. After being reminded by others, I made a small human-computer interaction interface to display the pid parameters and adjust the pid parameters.
The following is the display effect:
insert image description here
insert image description here
Then I attach the main code:

//  功能描述   : OLED 7针SPI接口演示例程(STM32F103系列)
//              说明: 
//              ----------------------------------------------------------------
//              GND  电源地
//              VCC  3.3v电源
//              D0   PA5(SCL)
//              D1   PA7(SDA)
//              RES  PB0
//              DC   PB1
//              CS   PA4              

#include "delay.h"
#include "sys.h"
#include "oled.h"
#include  "key.h"

int main(void)
{
    
    
	
	u8 t[]={
    
    10,10,10};	//因为取整数在显示屏上面显示比较好处理,所以这里把要显示的数字都改成整数
	//至于在PID调参数的时候,你可以把这里的t[0]、t[1]、t[2]当成是P、I、D的参数
	//把t[0]、t[1]、t[2]除以10就可以变成小数了,u8是0-255的范围
	delay_init();
	OLED_Init();
	KEY_Init();         //初始化按键
	
	OLED_ColorTurn(0);	//0正常显示,1 反色显示
    OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示
	OLED_Refresh();
	while(1)
	{
    
    
	//由于带回来的器材有限,我这里只做了一个参数的调节,其他参数也是一样的道理
	if(KEY0==1)
	t[0]++;
	if(KEY1==1)
	t[0]--;
		
	OLED_ShowString(0,0,"P:",16);
	OLED_ShowNum(16,0,t[0],3,16);
	OLED_ShowChar(32,0,46,16);//显示ASCII字符,一个ASCII为46的小数点	
		
	OLED_ShowString(0,16,"I:",16);
	OLED_ShowNum(16,16,t[1],3,16);
	OLED_ShowChar(32,16,46,16);//显示ASCII字符,一个ASCII为46的小数点	
		
	OLED_ShowString(0,32,"D:",16);
	OLED_ShowNum(16,32,t[2],3,16);
	OLED_ShowChar(32,32,46,16);//显示ASCII字符,一个ASCII为46的小数点	
	
	OLED_Refresh();
	delay_ms(200);		
	}
}

The above is just a simple adjustment of three parameters. The method is to control the increase or decrease of the parameters through the buttons. Since the devices I brought home are not very sufficient, only one parameter adjustment is made in the program, that is, the parameters are controlled by two buttons. The increase or decrease of PID parameters can be adjusted and displayed on the screen.
About the various programs of OLED display, you can read my previous article, there are several OLED display.
The code link is attached below:
stm32 uses the oled display and buttons to display and adjust the PID parameters.
I will send it to you as soon as possible. If you have any questions, you can comment below!

Guess you like

Origin blog.csdn.net/weixin_44069765/article/details/113808758