The easiest way to develop ESP8266 IoT small projects in history

 

 

       I have been learning ESP8266 for a long time, and I have also learned many methods from AT instruction set to SDK to lua development. There are roughly several parts needed to actually complete an IoT work: MCU control program + ESP8266 development + server selection and construction + app program design
       . Understand the design and programming of MCU, and the basic knowledge of servers and apps is 0. At this time, it becomes very difficult to quickly complete a small IoT product.
       So I'm going to provide you with one of the easiest methods I found during my studies, which only takes 3 hours. A simple IoT device can be completed.

 

First list the keywords  IOTECHN of this article

 

Ok, start the clock now, I will let you complete a small Internet of Things project in 3 hours

Step 1: Define project tasks

Here I use my project as an example! The task I want to accomplish is to make a remote temperature detection and alarm system.

The functions involved in the mcu are lighting, buzzer, and temperature measurement (here I am not using DS18B20, but a non-contact infrared temperature sensor MLX90614)


Step 2: Select and determine the hardware and development environment

Said to do the simplest, so I choose 51 single-chip MCU. The wifi module chooses ESP8266, and the service platform chooses iotechn.

Step 3: Log in to the IOTECHN website

IOTECHN website , after logging in, register an account first.

Then click Add Device

Enter the name and password of your device. The name should not appear in Chinese or use special characters. Just set the password according to your mood, and click OK. You'll find your device's name appear below.

It includes several important places,

1secretkey This is an important secret key for the connection between 8266 and your device;

2 Add/view commands Through this operation, the microcontroller can be operated 

3 Add/view parameters Through this operation the MCU can feed back the parameters to the 8266 and the server

 

Knowing this, let's start setting some parameters we want.

Do you still remember the task I want to complete, 1 switch light 2 switch buzzer 3 feedback temperature. There are actually two parts in this task. One is to let 8266 tell 51 MCU what to do, and the other is to let 51 MCU send the detected value to our lovely 8266. So we're going to add commands and parameters.

Click to add command

There will be three places where you can fill in the information. For example, if I want to complete the task of turning on the light, then I will enter the following

The command is sent to the microcontroller in the form of a hexadecimal message. Because there are frame headers and frame tails, try not to set the command too complicated. Here I use a character to represent it (note : this 1 It is the character 1 instead of the number 1, which can be realized when writing the MCU program later )

After entering all my commands one by one to confirm, you can click to view the commands

These are all the data information I want to send to the microcontroller O(∩_∩)O

 

Then add a parameter and check here. Note that name is used when programming. I will talk about it later.

Now the parameters of our server are set.

 

Step 4: Connect the phone

At the same time, this server is directly connected to WeChat, everyone opens WeChat to search the official account  iotechn controller

After paying attention, click Add Device, which will let you scan a QR code, open your iotechn webpage and find the QR code option, and your device will appear after scanning

Then enter your device and the command you set will appear

 

At this point, your mobile phone can already connect to the server through WeChat. Have you only spent half an hour so far? Okay, two and a half hours to go!

Step 5: Configure 8266

There are two tools to be used here, the firmware burning tool, the burning tool click to download and the serial port tool

At the same time, most students may have only used the AT instruction set for development, so they may not have noticed that the 8266 has a download mode, check the data sheet of the 8266

This download mode is used for firmware burning. What does the firmware do? As the name suggests, it is a program fixed in the 8266. The AT instruction set we used before is an AT firmware.

Because we want to burn a new firmware, everyone needs to solder a new circuit, which can control the state of gpio. Here is my circuit diagram

Next we have to develop the SDK. This is the download address of the SDK development package . For friends who don’t understand SDK development, don’t worry, the corresponding bin file has been configured in this package, we can burn the bin file directly. SDK development we can learn slowly in the future.

The corresponding bin file can be found in the following path

/iot-esp8266/ESP8266_NONOS_SDK/bin
/iot-esp8266/esp8266_mqtt/bin/upgrade

There will be a user1.1024.new.2.bin under the bin, which is the only file for the user, and the others use the official bin file. The configuration address is as follows

C:\develop\AiThinkerIDE_V0.5\cygwin\home\aithinker\project\ESP8266_NONOS_SDK\bin\boot_v1.6.bin       地址0x00000
C:\develop\AiThinkerIDE_V0.5\cygwin\home\aithinker\project\esp8266_mqtt\bin\upgrade\user1.1024.new.2.bin       地址0x01000
C:\develop\AiThinkerIDE_V0.5\cygwin\home\aithinker\project\ESP8266_NONOS_SDK\bin\esp_init_data_default.bin       地址 0xfc000
C:\develop\AiThinkerIDE_V0.5\cygwin\home\aithinker\project\ESP8266_NONOS_SDK\bin\blank.bin        地址 0xfe000

Open our downloaded firmware burning software 

There are several parts that we need to configure. First, the green part above needs to be ticked and the bin file address and burning address should be filled in according to my configuration address above.
Then there are three options in the middle part that are more important 1. The flash size needs to be adjusted according to the eso8266 model in your hand. Different models have different memory sizes. You can know the memory size of your model by looking at the data sheet. 2. The spimode is related to your computer driver. If you can’t burn it, you can try to adjust this option. 3. The second is your baud rate. Generally speaking, the newly acquired 8266 baud rate will have three types: 9600, 115200 or 144000. I have used it before. Students who use AT commands must not know their baud rate.

After the above options are set, click start directly to download, because we mentioned the download mode just now, so first pull down gpio0, and then click start to complete the firmware burning at this time.

At this point, half of the configuration of 8266 is completed. Next, we need to connect 8266 to our hotspots and devices.

At this time, we need to open the serial port assistant, and put the gpio in the air to enter the working mode.
Note: Our serial port assistant is best to use the function of inputting a new line, because we want to send a string with a carriage return. However, carriage return is not compatible under different systems. You should also pay attention to this point for the single-chip programming for a while. The specific difference can be found in my article The difference between serial port and sending new line under different systems

Here is my serial port tool  with the serial port assistant   extract code hqqe that sends a new line

Next, enter set wifi, your ssid, and your wifi password\r\n There can only be one space in between.

set mqtt "your secretKey" "name" "pwd"\r\n There can only be one space in between.

sretkey is the name automatically generated on the iotechn website just now and pwd is the device name you set

After completing these two steps, the configuration is complete. After restarting the module, we enter the show command

So far the setting of 8266 has been completed

An hour has passed here, don't worry, we still have two hours! So you can have a cup of tea and calm down. How many things did you do just now?

Step 6: Communication between esp8266 and MCU

My 51 single-chip microcomputer is 5v and 8266 is 3.3v, so it cannot be directly connected for communication. You can read my document 5v and 3.3v serial communication

Post my circuit schematic here

 

Step 7: Programming of MCU

I have reason to believe that everyone is very good at programming single-chip microcomputers.

I directly paste my program click here to download   the extraction code 2e16

 

Here I want to talk about the message format. According to the command parameters I just set, the return value I receive when I press each button on the mobile app is like this

So when I accepted the message, the program made the following adjustments

if(RI_flag)
		{
			
			for(i=0;i<15;i++)
			{
				if(UsartReceive[i]=='$'&&UsartReceive[i+4]=='}')
				{
					
					switch(UsartReceive[i+5])
					{
						case 0x31:P1=0;break;
						case 0x32:P1=0xff;break;
						case 0x33:P2_3=0;break;
						case 0x34:P2_3=1;break;
						case 0x35:TI_flag=1;break;
						case 0x36:TI_flag=0;break;
					}
				}

			}

Do you still remember that the command I just said is a character type? So the 1 set in my command here is officially its ascll code 0x31 or directly written as case '1':

everything is possible

At the same time, if you want the microcontroller to send temperature parameters, you need to send the following message

param tem text Here tem is the name of the parameter just set

For this, I only send it like this in my code

if(TI_flag)
		{
			TI_flag=0;
			temperature=temperature_read();
			ES=0;
			TI=1;
			printf("param tem %4.2f°C\n",temperature);
			while(!TI);
			TI=0;
			ES=1;
		}

It should be noted that a space must be added after tem after param. And as I said above, pay attention to the use of /r/n. Here we can use /n.

 

If you are proficient in the operation of single-chip microcomputer or your project is not very complicated, I think it may take only one hour for you to complete the single-chip microcomputer program. Looking at it now, you have learned an access method to the Internet of Things, right? O(∩_∩)O

 

Finally, I can control the led light buzzer and display the temperature data through the mobile phone

 

Finally, I would like to thank the platform developer IO traveler [email protected] for his open source dedication to provide us with a lot of convenience

 

 

Post my email here [email protected] I hope everyone can discuss and learn together

 

Guess you like

Origin blog.csdn.net/qq_34597963/article/details/86232357