当前位置:网站首页>Pet Feeder Based on stm32

Pet Feeder Based on stm32

2022-06-23 09:43:00 DS brother Bruce Lee

1. Preface

With the rapid development of Internet of things Technology , Smart home has entered people's daily life , In the context of policy support , Smart home enterprises pay more and more attention to the R & D and application of related technologies ; However, pet feeding devices on the market have been difficult to meet the needs of pet owners . The intelligent pet feeding device introduced in this paper is based on STM32 At the core , Multiple modules coordinate , Jointly complete the regular and quantitative feeding, real-time environmental monitoring and high temperature alarm for pets of different ages 、 And the owner can understand the pet's living environment through intelligent devices at any time 、 Functions such as feeding pets . The function of the system is perfect 、 The price is low , Easy to use , It solves the worries of pet breeders when they go out , It can also ensure that pets eat regularly .

Designed a pet feeder , Support manual control of grain feeding , Set the thermostatic threshold , Feed regularly 、 temperature 、 Real time humidity display 、 Remaining grain weight and other functions .

2. demand

Make one based on STM32 Pet feeder for , It can be mainly used to raise birds or small yellow ducks .

The main functions are :

1、 You can use your mobile phone wifi app Follow the button to control the feeding of grain . Feed regularly 、 Feeding amount per time ( If you haven't finished , Next time, supplement to the set amount , The replenishment amount does not need to be so accurate )

2、 Record how much your pet eats each day ( The weight of food already eaten )

3、 The screen shows the current box / The temperature in the birdcage , The weight of grain

4、 temperature control : When the temperature is below how many degrees ( Set by yourself ) Start the thermostat automatically ( Just a simple automatic switch ).

Demand split :

(1) mobile phone APP: Design a Android mobile phone APP, a windows The client is the upper computer , Manually control grain feeding , Set the thermostatic threshold , Feed regularly 、 temperature 、 Real time humidity display 、 Remaining grain weight and other functions .

mobile phone APP And STM32 Through between TCP Network protocol transmits data ,STM32 Use here ESP8266 As a wireless network card , establish WIFI hotspot , mobile phone APP Connect the hotspot and build a small LAN , Complete data communication .

(2) use DHT11 Check the current ambient temperature in the birdcage 、 humidity .

(3) use 0.96 " SPI Interface OLED display , Displays the current cage temperature 、 humidity 、 Grain weight .

(4) use LED Lamp analog thermostat , When the ambient temperature in the birdcage is lower than the set threshold , Start the thermostat to heat ( Lighten up LED simulation ).

(5) Pet feeding adopts 28BYJ4 4 phase 5 Line stepper motor +ULN2003 Drive plate Realization , The stepping motor rotates the specified number of turns or degrees to simulate the feeding of grain .

(6) The weight of the grain to be fed is HX711 Load cell electronic scale weighing module Complete the test .

image.png

image.png

3. Required components

3.1 ESP8266 WIFI

ESP8266 It's a wireless WIFI modular , Can be configured by , Communicate with the serial port on the single chip microcomputer , utilize WIFI To transmit data .

3.2 Scale sensor

img

img

img

HX711 It is specially designed for high-precision load cell 24 position A/D Converter chip .

3.3 DHT11 Temperature and humidity sensor

DHT11 It is a temperature and humidity sensor with calibrated digital signal output . Its precision humidity ±5%RH, temperature ±2℃, Range humidity 5~95%RH, temperature -20~+60℃.

3.4 Stepper motor

 Stepper motor 28BYJ-48 Meaning of name :

28: Indicates that the maximum effective outer diameter of the stepping motor is 28 mm 
B:  Indicates stepping motor “ Step ” The first letter of Chinese phonetic alphabet 
Y:  Indicates permanent magnet type “ forever ” The first letter of Chinese phonetic alphabet 
J:  Indicates deceleration type “ reduce ” The first letter of Chinese phonetic alphabet 
BYJ:  The combination is a permanent magnet decelerating stepping motor 
48: It means four phases and eight beats 
5V: Indicates that the rated voltage is 5V, And DC voltage 

 Step angle :5.625 degree , Namely 1 A pulse signal turns 5.625 degree ,64 A signal turns 360 degree .
 Reduction ratio :1/64, The motor inside the motor housing turns 64 circle , The part outside the motor housing turns 1 circle .
 Four phases :ABCD Four phases ( There are... On the motor stator 8 A tooth , Relative 2 Teeth yes 1 phase ),
 Eight shots :(A-AB-B-BC-C-CD-D-DA-A).
 A beat is a pulse signal , Complete a cycle 8 A pulse signal .
 When the change of power on state completes a cycle , The rotor turns a pitch . turn 8 One pitch is one circle ,8×8=64
64 pat ,64 A pulse signal turns around 360 degree .

3.6 STM32 Development board

STM32F103RCT6 The core specification is 32 position , The velocity is 72MHz, The capacity of program memory is 256KB, The type of program memory is FLASH,RAM Capacity is 48K.

3.7 DuPont line

4. Software host computer design

4.1 Introduction to development environment

The upper computer software adopts Qt framework design ,Qt It's a cross platform C++ GUI application framework .Qt It's a 1991 Year by year Qt Company Cross platform development C++ GUI application development framework . It can develop GUI Program , It can also be used to develop non GUI Program , For example, console tools and servers . Simply speaking ,QT It can easily help you make software with interface , It doesn't even require you to put a lot of energy .

QT Official website :https://www.qt.io/

4.2 Study the tutorial

QT Introductory practical column : https://blog.csdn.net/xiaolong1126626497/category_11400392.html

4.3 win10 Running effect

4.4 Android Running effect

4.5 Communication protocol

 Read ESP8266 Data sent 
$update,22,33,12
$update, temperature , humidity , Remaining grams 


 towards ESP8266 send out : 
 Manual feeding : $0
 Timing feeding time setting : $1,2
 Constant temperature setting : $2,22

5. STM32 Device side development

be based on STM32 Designed pet feeder

be based on STM32 Designed pet feeder _ PC source code :https://download.csdn.net/download/xiaolong1126626497/85736919
be based on STM32 Designed pet feeder _STM32 Source code https://download.csdn.net/download/xiaolong1126626497/85736953

5.1 Physical equipment

image.png

image.png

image-20220318095331645

5.2 Hardware wiring instructions

 Hardware connection mode :

1. ESP8266 WIFI connection 
ATK-ESP8266 A serial port WIFI Module and STM32 Serial port 2 Connect .
PA2(TX)--RXD  Module receiving pin 
PA3(RX)--TXD  Module sending pin 
GND---GND  The earth 
VCC---VCC  Power Supply (3.3V~5.0V)

2. TFT 1.44  Inch color screen wiring 
GND    Power ground 
VCC    Pick up 5V or 3.3v Power Supply 
SCL    Pick up PC8(SCL)
SDA    Pick up PC9(SDA)
RST    Pick up PC10
DC     Pick up PB7
CS     Pick up PB8
BL	   Pick up PB11

3. DHT11  Temperature and humidity 
VCC--VCC
GND---GND
DAT---PA5 

4.  Stepper motor 
ULN2003 control 28BYJ-48 Stepper motor wiring :

ULN2003 connection :
 IN-D: PB15   d
 IN-C: PB14   c
 IN-B: PB13   b
 IN-A: PB12   a
+  : 5V
-  : GND


5.  The weighing sensor 
VCC--->5V
SCK--->PB0    Timing control pin -- Yes STM32-- The output mode 
DT---->PB1    Output pin - Yes STM32-- The input mode 
GND--->GND

6.  On board LED Lamp wiring 
LED1---PA8
LED2---PD2


7.  On board key wiring 
K0---PA0 
K1---PC5 
K2---PA15

5.3 Project code framework

5.4 main.c Core code

#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
#include "key.h"
#include "usart.h"
#include <string.h>
#include "timer.h"
#include "esp8266.h"
#include "motor.h"
#include "oled.h"
#include "dht11.h"
#include "adc.h"
#include <string.h>
#include <stdlib.h>
#include "HX711.h"

//JTAG Mode setting , Used for setting up JTAG The pattern of 
//mode:jtag,swd Mode setting ;00, All enable ;01, Can make SWD;10, All closed ; 
#define JTAG_SWD_DISABLE 0X02
#define SWD_ENABLE 0X01
#define JTAG_SWD_ENABLE 0X00 
void JTAG_Set(u8 mode)
{
    
	u32 temp;
	temp=mode;
	temp<<=25;
	RCC->APB2ENR|=1<<0;     // Turn on the auxiliary clock  
	AFIO->MAPR&=0XF8FFFFFF; // eliminate MAPR Of [26:24]
	AFIO->MAPR|=temp;       // Set up jtag Pattern 
}


u8 temp;
u8 humidity;
u32 CurrentWeight=5; // Default weight value 
u8 timer_hour=1; // Timing feeding time 
u8 SetTemperature=0; // Set the constant temperature 

//WIFI Send data storage area 
char data_buff[300];

int main()
{
    
    u8 esp8266_state=0;
    u8 key;
    u8 i;
    u32 time_cnt=0;
    u32 timer_hour_cnt=0; // Record the timing 
    JTAG_Set(JTAG_SWD_DISABLE); // Release PA15
    LED_Init();
    KEY_Init();
    USART1_Init(115200);
    Moto_Init();  // Motor initialization 
    USART2_Init(115200);// A serial port -WIFI
    TIMER2_Init(72,20000); // Timeout time 20ms
    DHT11_Init();		// initialization DHT11
    Lcd_Init(); //LCD initialization 
    Lcd_Clear(0); // The screen is black 
    LCD_LED_SET;// adopt IO Control back light  
    Init_HX711pin(); // The weighing sensor 
    
    printf(" Initializing WIFI One moment please .\r\n");
    
    for(i=0;i<5;i++)
    {
    
        if(ESP8266_Init()==0)
        {
    
            esp8266_state=1;
            break;
        }
        else
        {
    
            esp8266_state=0;
            printf("ESP8266 Hardware detection error .\r\n");  
        }
    }
  
    if(esp8266_state)
    {
    
       printf(" Ready to create hotspot ....\r\n");
        
       // To configure ESP8266 Created WIFI Name and WIFI password , The mobile phone needs to be connected to this WIFI hotspot 
        printf("WIFI state :%d\r\n",ESP8266_AP_TCP_Server_Mode("esp8266_666","12345678",8089));
    }
    
    Get_Maopi();				// Weigh the fur 
	delay_ms(1000);
	delay_ms(1000);
	Get_Maopi();				// Regain fur weight 
    
	 while(1)
	 {
    
        // Press the key to test the feeding 
        key=KEY_Scan(0);
        if(key==2)
        {
    
            Motorcw_ring(1,300);   // The motor is turning forward 1 circle -- Simulated feeding of grain 
            printf(" Start the stepping motor to feed food ...\r\n");
        }
        else if(key==3)
        {
    
            Lcd_Clear(0); // The screen is black 
            LED2=!LED2;
        } 

        // Polling time arrives 
        if(time_cnt>=100)
        {
    
            time_cnt=0;
            LED1=!LED1;
            
            // Obtain the ambient temperature and humidity 
            if(DHT11_Read_Data(&temp,&humidity))
            {
    
                printf(" Temperature reading failed .\r\n");
            }
            printf(" ambient temperature :%d\r\n ambient humidity :%d\r\n",temp,humidity);
            
            // Get the weight fed back by the load cell 
            Get_Weight();
            printf(" Net weight  = %d g\r\n",Weight_Shiwu); // Print  
            
            //LCD The screen displays the temperature and humidity in real time 、 Weighing information 
            sprintf(data_buff,"H:%d",humidity);
            Gui_DrawFont_GBK16(0,16*1,RED,GRAY0,(u8*)data_buff);
            
            sprintf(data_buff,"T:%d",temp);
            Gui_DrawFont_GBK16(0,16*2,RED,GRAY0,(u8*)data_buff);
            
            sprintf(data_buff,"G:%d",Weight_Shiwu);
            Gui_DrawFont_GBK16(0,16*3,RED,GRAY0,(u8*)data_buff);
            
            // To the mobile phone APP real-time display 
            //$update,22,33,12 CurrentWeight
            //$update, temperature , humidity , Remaining grams 
            sprintf(data_buff,"$update,%d,%d,%d",temp,humidity,CurrentWeight);
            
            // send data 
            ESP8266_ServerSendData(0,(u8*)data_buff,strlen(data_buff));
        }
			 
        //  receive WIFI Returned data 
        if(USART2_RX_FLAG)
        {
    
            USART2_RX_BUFFER[USART2_RX_CNT]='\0';
            
		    printf("WIFI Receive the data :\r\n");
            // The data returned to the serial port print server 
            for(i=0;i<USART2_RX_CNT;i++)
            {
    
                printf("%c",USART2_RX_BUFFER[i]);
            }
            
            // If the attribute is distributed 
            if(USART2_RX_CNT>5)
            {
    
                // Use string lookup function 
                // If you need to feed food manually 
                if(strstr((char*)USART2_RX_BUFFER,"$0"))
                {
    
                    Motorcw_ring(1,300);   // The motor is turning forward 1 circle -- Simulated feeding of grain 
                }
                // If it is to set the timing feeding time ( Hours )
                // Format :  Timing feeding time setting : $1,2
                else if(strstr((char*)USART2_RX_BUFFER,"$1"))
                {
    
                    char *p=strstr((char*)USART2_RX_BUFFER,"$2");
                    // Turn to an integer 
                    timer_hour=atoi(p+3);
                    printf(" Timing feeding time :%d\r\n",timer_hour);
                }
                
                // If setting the temperature of the thermostat 
                // Format :  Constant temperature setting : $2,22
                else if(strstr((char*)USART2_RX_BUFFER,"$2"))
                {
    
                    char *p=strstr((char*)USART2_RX_BUFFER,"$2");
                    // Turn to an integer 
                    SetTemperature=atoi(p+3);
                    printf(" Set the constant temperature to :%d\r\n",SetTemperature);
                }
                USART2_RX_CNT=0;
                USART2_RX_FLAG=0;
            }
        }
        
        // Determine whether heating is required 
        // If the ambient temperature is lower than the set constant temperature, it will be heated 
        if(temp<SetTemperature)
        {
    
            // Code that executes the heating ----
        }
        
        // Judge whether the fixed time has arrived 
        if(timer_hour_cnt >=(100*60*60)*timer_hour)
        {
    
            timer_hour_cnt=0; // Count again 
            Motorcw_ring(1,300);  // The motor is turning forward 1 circle -- Simulated feeding of grain 
        }
        
        DelayMs(10);
        time_cnt++;
        timer_hour_cnt++;
	 }
}
原网站

版权声明
本文为[DS brother Bruce Lee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230936502301.html