Graffiti module development (pressure sensor HX711) - 4 Graffiti module data communication

Posted by ScotDiddle on Sat, 05 Mar 2022 20:36:38 +0100

summary

Graffiti intelligence (NYSE: TUYA) is a leading technology company committed to making life smarter. Graffiti provides a cloud platform that can connect everything intelligently, creates an interconnected development standard, connects the intelligent needs of brands, OEM s, developers, retailers and various industries, and graffiti solutions enable and enhance the product value of partners and customers, At the same time, the technology application makes consumers' life more convenient. The graffiti intelligent smart business SaaS provides intelligent solutions for rich vertical industries. Graffiti intelligence is the leading technology in the industry, and complies with strict data protection standards and security.
Pressure sensor is the most commonly used sensor in industrial practice. It is widely used in various industrial automatic control environments, including water conservancy and hydropower, railway transportation, intelligent building, production automatic control, aerospace, military industry, petrochemical, oil well, electric power, ship, machine tool, pipeline and many other industries.
At the same time, the pressure sensor can be applied to the electronic weighing system or sedentary system to realize the functions of weighing display, over limit alarm, calibration, adapting to various working environments, remote real-time monitoring and so on. It can be widely used in various weighing scenes.
This chapter mainly reports the sensor data to the graffiti module.

Graffiti function modification

Since the pressure sensor HX711 I use collects 0-20kg, it can be modified as follows.

Pressure value reporting

Since the main program executes a cycle every 100ms, frequent reporting will lead to excessive pressure on mcu and graffiti module, so it is set to report every 3s.

It can also be seen from the above figure that the sending command of pressure value needs to define a sending buff array.
Pay attention to the data length. 0x08 represents that there are 8 data after it, that is, the function instruction should be 0-0xffffff, but only 0-0x4e20 is valid.

/* USER CODE BEGIN PV */
uint32_t Reported_pressure=0 ;//Pressure value
uint32_t Reported_pressure_counter=0 ;//Pressure value reporting counter to prevent reporting too fast
uint8_t Buff8[15]={0x55,0xAA,0x00,0x07,0x00,0x08,0x02,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00};//Report pressure value
/* USER CODE END PV */

Add code in the main program. When the collected data is positive pressure value, it will be reported normally, and when the negative pressure value is 0, it will be reported once in 3s.

/***********Read pressure sensor value******************/		
		weight_shiji=ReadCount();
		if(weight_qupi>=weight_shiji)
		{
			weight_shiji=weight_qupi-weight_shiji;
			weight_shiji=weight_shiji/100;
//			printf("weight is:% dg",weight_shiji);
			Reported_pressure=weight_shiji;//Normal assignment of positive pressure value
		}
		else
		{
			weight_shiji=weight_shiji-weight_qupi;
			weight_shiji=weight_shiji/100;
//			printf("weight: -% dg",weight_shiji);
			Reported_pressure=0;//The negative pressure value is 0
		}	

		
		
		Reported_pressure_counter++;//Pressure value reporting counter to prevent reporting too fast
		if(Reported_pressure_counter==30)//Report once in 3s
		{
			Reported_pressure_counter=0;//Pressure value reporting counter to prevent reporting too fast
			Buff8[10]=0;//If it is not used, the value is 0
			Buff8[11]=0;//If it is not used, the value is 0
			Buff8[12]=Reported_pressure/256;
			Buff8[13]=Reported_pressure%256;
			Buff8[14]=0;//The checksum is assigned to 0
			for(int i=0;i<14;i++)
			{
				Buff8[14]=Buff8[14]+Buff8[i];		
			}
			for(int i=0;i<12;i++)
			{
				Buff8[12]=Buff8[12]+Buff8[i];		
			}
			HAL_UART_Transmit(&huart3,(uint8_t*)Buff8,15,0xFFFF);	//Report the pressure value and send it to the graffiti module
			HAL_UART_Transmit(&huart1,(uint8_t*)Buff8,15,0xFFFF);	//Report the pressure value and send it to the graffiti module		
		}

At the same time, the graffiti module may ask the mcu for the pressure value, so it needs to be in uart3_ Add judgment to the data() function to report.

					else if(RX_BUFF[3]==0x06&&RX_BUFF[6]==0x02)//Report pressure value               
					{
					
						HAL_UART_Transmit(&huart3,(uint8_t*)Buff8,13,0xFFFF);	//Report the pressure value and send it to the graffiti module
						HAL_UART_Transmit(&huart1,(uint8_t*)Buff8,13,0xFFFF);	//Report the pressure value and send it to the graffiti module	
					}	

Reporting pressure status

Since the main program executes a cycle every 100ms, frequent reporting will lead to excessive pressure on mcu and graffiti module, so it is set to report every 3s.
At the same time, set the pressure below 500g as alarm and above as normal.

It can also be seen from the above figure that the sending command of pressure value needs to define a sending buff array.

/* USER CODE BEGIN PV */
uint8_t Buff9[12]={0x55,0xAA,0x00,0x07,0x00,0x05,0x01,0x04,0x00,0x01,0x00,0x00};//Report pressure value

/* USER CODE END PV */

Add code in the main program. When the collected data is that the pressure value is less than 500g, report it normally, report it to the police when it is greater than 500g, and report it once in 3s.

/***********Read pressure sensor value******************/		
		weight_shiji=ReadCount();
		if(weight_qupi>=weight_shiji)
		{
			weight_shiji=weight_qupi-weight_shiji;
			weight_shiji=weight_shiji/100;
//			printf("weight is:% dg",weight_shiji);
			Reported_pressure=weight_shiji;//Normal assignment of positive pressure value
		}
		else
		{
			weight_shiji=weight_shiji-weight_qupi;
			weight_shiji=weight_shiji/100;
//			printf("weight: -% dg",weight_shiji);
			Reported_pressure=0;//The negative pressure value is 0
		}	

		
		
		Reported_pressure_counter++;//Pressure value reporting counter to prevent reporting too fast
		if(Reported_pressure_counter==30)//Report once in 3s
		{
			Reported_pressure_counter=0;//Pressure value reporting counter to prevent reporting too fast
			
			Buff8[10]=0;//If it is not used, the value is 0
			Buff8[11]=0;//If it is not used, the value is 0
			Buff8[12]=Reported_pressure/256;
			Buff8[13]=Reported_pressure%256;
			Buff8[14]=0;//The checksum is assigned to 0
			for(int i=0;i<14;i++)
			{
				Buff8[14]=Buff8[14]+Buff8[i];		
			}
			HAL_UART_Transmit(&huart3,(uint8_t*)Buff8,15,0xFFFF);	//Report the pressure value and send it to the graffiti module
			HAL_UART_Transmit(&huart1,(uint8_t*)Buff8,15,0xFFFF);	//Report the pressure value and send it to the graffiti module
			
			//If the set pressure value is less than 500g, it is alarm, and if it exceeds 500g, it is normal
			if(Reported_pressure>500)
				Buff9[10]=0;
			else
				Buff9[10]=1;
			Buff9[11]=0;//The checksum is assigned to 0
			for(int i=0;i<11;i++)
			{
				Buff9[11]=Buff9[11]+Buff9[i];		
			}
			HAL_UART_Transmit(&huart3,(uint8_t*)Buff9,12,0xFFFF);	//Report the pressure value and send it to the graffiti module
			HAL_UART_Transmit(&huart1,(uint8_t*)Buff9,12,0xFFFF);	//Report the pressure value and send it to the graffiti module
					
		}

At the same time, the graffiti module may ask the mcu about the pressure state, so it needs to be in uart3_ Add judgment to the data() function for reporting.

					else if(RX_BUFF[3]==0x06&&RX_BUFF[6]==0x02)//Report pressure value               
					{
					
						HAL_UART_Transmit(&huart3,(uint8_t*)Buff8,13,0xFFFF);	//Report the pressure value and send it to the graffiti module
						HAL_UART_Transmit(&huart1,(uint8_t*)Buff8,13,0xFFFF);	//Report the pressure value and send it to the graffiti module	
					}	

Value added services

SMS notification can be turned on in the setting, so that after triggering the pressure sensor, a SMS will be sent to the mobile phone.


At the same time, it will also send alarm information to the mobile phone.

last

The above code will be shared in Q group. QQ group: 615061293.
Or focus on WeChat's official account, keep updating articles and learning materials, and add WeChat's learning to the author.

Topics: Single-Chip Microcomputer