ESP8266 – ESP8266 UART COMMUNICATION #ElecrowMaker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello iud magicians welcome uh in today's interesting session let me first share my screen and let me check if i'm lying looks like i'm like now welcome let me close this and i'm live now so every positions today well we are here for a testing session where we'll be doing uh uart communication between two esps so as you can see my screen this is the camera and this is the first esp esp8266 and i have a push button here and this is second esp connected with the display four digit seven segment display so in this case i have attached one esp to another esp using the tx and rx and we'll be doing uart communication and we understand it how do we achieve it so just uh let's see first the result that what we're gonna achieve at the end of the day and then we'll proceed with the session so this is the push button let me open the com port so this is the serial monitors com4 for the sender esp and let me open the another com port this is com5 which is for the receiver esp and this is the display over there so when you press this button you see that it has the sender has sent some number zero double five which is received at uh the receiver esp and at the same time you can see the number on the display one zero five five the same number so let's try to uh push one more time so when i will push this button so you will see that uh the sender has sent a number 0 to 8 4 which is being received by the receiver 0 to 8 4 and you can see the same number 0 2 8 4 which is displayed by the receiver let's do it one more time so from the sender i will push a button the receiver will receive the number and it will show the same number on the display let's try it one more time so i click it so you are seeing that the sender sent six five six eight which is received by the receiver the same number six five six eight and if you will see the display six five six eight has been displayed on the display means uh the sender is sending some number receiver is receiving it and at the same time it is showing on the display using the uart communication so okay magician so this is what we are gonna achieve today hope uh this will be useful for you if you are doing a you are communication or if you need to do a uart communication in some of your projects and so you can use this uh project or the lesson okay so let me open the document that we are going to explain today so this is the document which i am going to cover today okay so this is uh eight uh pages of document and if you need document and the code uh which i have used in this session if you need that let me know in the comments section or ask me my whatsapp or you can directly ask me in my facebook group also my whatsapp number is already there in the description of this video okay so without making any further delay let's get started for the before the session so in this uart communication between two esps our aim is to connect to esp8266 using uart protocol the first esp will send some random number on pressing the push button so when you will press the button it will send some number the first esp will send some number now which will be this should be shown on the display tm1637 display connected to the second esp as you as you see here this is the second esp which is connected to the display so when we press this button here the number the number which first esp will send to second esp that number should be displayed on our display so this is our aim and we are going to see how do we achieve it so before explaining or before going to the session or the code uh i have uh explained in this document what is the uart and how this is what works if you are interested you can go deep into this and you can understand it and then now i am just uh going uh for the brief introduction for the uart and what are the uart communication and how does this work but for the detailed explanation you can read in this document you can ask me about this document i will send it to you ask me in my whatsapp group so what first of all let's write one lesson what is uart the you are the full form of what is universal asynchronous receiver and transmitter and it is the inbuilt ic within the microcontroller but not like a communication protocol like i2c and spi if you remember uh in our i2c or spi uh communication uh it is more or like a software kind of software or the software pins we have for that but in case of uart uh we have a hardware peripheral for that which is present inside the microcontroller so you are seeing that it means it is a hardware peripheral uart is the hardware peripheral which is present inside the microcontroller asynchronous means not synchronous means there is no clock exist between the transmitter and the receiver so uh like the i2c or the spi where we have a clock which manages the truss transmitter and the receiver and it creates the synchronization between the transmitter and the receiver as we know the clock between the sender and the receiver maintains the synchronization during data transmission so that the receiver exactly knows when to sample the incoming data and when to sit idle so this is the uh use of the clock so whenever sender is sending some data yeah if there is a clock which is maintaining the synchronization between the sender and the receiver the receiver will exactly know when to sample the incoming data or when to sit idle so this is uh this is the purpose of the clock but if there is no such clock exist between the transmitter and receiver as in the case of uart in uart communication there is no such clock between sender and receiver then it is called asynchronous data communication you might be thinking at this point that if there is no clause exist between the sender and the receiver then how a receiver will know when to sample the incoming data and when to sit idle okay to solve this issue another kind of mechanism is used in uart uh we will discuss that soon in details please stay tuned so now how the data communication happens between you are if there is no clock synchronization happens between the sender and the receiver so i have detailed out that communication or the method which happens for you are in this document if you are interested in reading in details let me know or connect me to my whatsapp i will send this document to you and you can understand that in details and if you need the code that i have used in this session that also you can ask me i can i give that to you the main function of uh uart is the serial data let's try to see why uart is used at a very high level and explaining it protocols like spi and the usb protocols they and they are used for fast communication when the high speed data transfer is not required then in that case uart can be used it is a cheap communication device with a single transmitter and receiver it requires a single wire for transmitting the data and another wire for receiving it can be interfaced with pc personal computer using ttl converter or the usb ttl converter the common thing between so this uh this is just about uh the different kind of converters that that are used in uart the communication between two devices can be done in two ways if you are seeing the uart communication between two device it happens in two ways one is the serial communication and another is the parallel communication now let's try to understand uh at a very high level what is the serial data communication uh in the serial data communication the data can be transferred through a single cable or line in a bit by bit form and it required just two cables so as you are seeing here there is a cable transmit cable from the tx px side the data is transferred and at the rx side the data is received through a single wire it requires very less circuitry as well as wires as you are seeing that there is only single wire is required for transmitting the data and the data is transferred bit by bit in case of serial communication thus this communication is very useful in compound circuits so this is a block diagram for how serial data communication works while in the case of parallel data communication here you are seeing that the sender has different pins for different pins for uh for for for each bit of data like this d02 d7 in parallel data communication the data is transferred through multiple cables at once parallel data communication expensive as well as very fast as it requires additional hardware and cables and you are seeing that for parallel communication we need these many extra wires to transmit a single byte uh the best example for this communication are old printers pci there so in that case in those cases we will be we are using our parallel data communication so here i have shown the uart block diagram also so from this and i have explained in details how uart communication happens between the sender and the receiver i'm not going to explain in this in detail here how this uart is uh sending data uh between the sender and the receiver because um mainly i am focusing uh to communicate between two esps using uart and i assume that we are already having a good idea about or a little bit idea about the uart communication uh the important thing to understand uh is uh how you are communicating in how your communication works there are a couple of uh parameters that are used for communication one is the baud rate this is the rate at which the transmitter will send the data and receiver must be aligned with the same rates as as we saw uh there is no clock exist between the transmitter and the receiver so in that case the there should be some mechanism that allows sending and receiving or that allows the smooth sending and receiving of the data so these are couple of parameters which make sure that the data transfer is smooth so one of that is baud rate uh in that case the transmitter and the receiver must be aligning the same baud rate another is the data size if transmitter is about to send eight bit of data the receiver must know this in advance uh you are usually uart follows eight bit data transmission in case of parity mechanism the data length can be nine bit uh but again if the sender is going to use the parity mechanism in the case receiver must know in advance that yeah the mechanism will be the parity mechanism and nine and it will expect the nine bits of data coming from the transmitter so this kind of information that the receiver must knowing and once from the center side so here i have given uh details how data is transferred what how is the packet size of data what should be the data frame and what are the start with what is the parity bit and what is the stop bit and i have explained detail about start bet stop bit parity bit and data bits what are all these uh in this document so this is all about art that i had explained in this document so that it would be useful for you before uh moving to the real project you should be having a little bit idea about how you art is working okay so now our main focus is to interface uh this project and connecting two esps or rather esp8266 using uart manner and the same standing and receiving data successfully so how do we do that let's try to interface it first connecting to esp8206 along with the push button and tm 1637 display let me show you the screen also so that it will be easier for you okay so here uh in this case you are seeing that uh [Music] we have two esps this is the sender esp esp8266 along with the push button and another second esp esp8266 again now with the display so how do we connect it let's try to follow our connection scheme the button and this push button the first leg the first leg of this put push button will be connected to 3.3 volt of first esp8266 and and the second leg of this button will be connected to a 10k ohm resistor and again the same leg of the button will be connected to the gpio 15 or b8 of the first esp8266 and of course the second leg of our 10 km register will be connected to the ground so this is a simple connection scheme uh between push button the register i am using the register and the esp8266 so this connection scheme we have used many times in our uh push button uh sessions or push button project so that that's not uh that should not be difficult for us to interface the push button with our esp8266 using uh the 10k ohm resistor next uh thing comes at the interfacing of display with esp8266 so this uh display tm1637 display it's a four digit seven segment display and it has four pins one is the vcc pin another is the ground pin another pin is uh the dio the data data pin and the last is the clock pin clk so it has four pins so how do we connect all these four pins to our esp this is also pretty straightforward and i have mentioned uh how do we connect it so let's try to see that so the vcc pin of tm 163 the vcc pin of the display will be connected to 3.3 volt to the second esp so this is our second esp so the vcz pin will be connected to 3.3 volt the ground of this will be connected to the ground of our second esp this is also okay the dio pin so it's third pin is dio pin and you can see the naming convention the name is written um behind the sensors so you can easily see that behind this display you can see that the dio pin you will connect to the d2 or the gpio4 of second esp so you will connect to d2 the dio pin will be connected to the d2 pin of our second esp and the clock pin of tm1637 will be connected to the d1 or gpio5 of our second esp so this connection is also pretty straightforward there is nothing much difficulty on that if still you have any issue any problem let me know i can help you on that and finally uh we will connect our both the esps uh esp1 and esp2 using uart so how do we connect it the gpio14 or which we call d5 of first esp the d5 pin of first esp will be connected to the d6 of cycling esp so d5 pin of first esp will be connected to d6 pin of the second esp if you will see here the green pin here is my d5 pin if you see that this is the green pin now the green wire is the d5 so it is connected to the d5 here and here it is connected to d6 if you see that this screen this screen is connected to b6 similarly this brown wire here brown wire i have connected to the d6 the d6 pin or first esp will be connected to d5 of our second espn you are seeing that this brown pin is connected to the d5 here which is connected to d6 on the first esp so this is a simple uh tx and rx connection between two esp's hope uh this connection scheme is clear to you this is not that difficult and it should be easy for you to connect in this manner if you want to uh look at the phrase diagram i have drawn that also for you so that it will be easier for you to connect like this so here this is the first esp where i have connected a push button along with a resistor and for the second esp this is the second esp where i have connected the display module and you are seeing that these two esps are connected using uh tx and rx pin like this two pins so d5 of first node is connected to the d6 and d6 of the first uh esp is connected to the d5 to the second esp so this is how we connect you are right we use you are communication or you are connection between two esps and if you want to see the physical diagram this is our physical connection okay magician so now hope you are able to connect in this manner and you are ready to do the uart communication now once you have connected all the components as described above let's follow the below steps to execute this project so what you need to do now you need to connect first you need to connect the first esp to the laptop and identify its component let me open uh let me show you the camera also so that you can see that now what that means so this is the first esp first you need to connect your first esp to your laptop i have connected this to the laptop and i have identified the com port so for the first esp my com port is com4 and then you need to copy this code esp8266 tx software serial button dot io so this is the code which i have used for the first esp8266 if you need this code let me know in the comments or ask me in my whatsapp or in the facebook my whatsapp number is already there in the description of this video i will provide you this code so this is the code which you have to upload in the first esp so let me show you the code so this is the code uh esp8266 tx software serial underscore button so you need to just copy paste and there is no change required in this code once you have copy pasted and saved the code you need to upload this into your first esp8266 so you had open the arduino ide copied the code esp8266 tx software serial underscore button this is the code you have copied then you just need to upload this to your first esp so when you will click on the upload button you are seeing that it is compiling the sketch and the compilation is almost finished now it is uploading uh this first code tx is the transmit code ah to our first esp8266 we are seeing that it is writing and it's already almost written 70 of the code is uploaded and almost it is done 100 percent upload so we are seeing that uh upload is done so once uh the code has been uploaded in the first esp now what do we do now we need to do the same thing with our second esp but in this case we will upload some different code so let's see what that code is so now what you will do ah now you will connect the second esp to the laptop and identify its com port so i have connected the second esp also to my computer or the laptop and the com code which it has received in this case it is com file uh for me it's com5 or it could be anything for you um at the time of writing this document it was com9 so you can see that it is comment but now today when i am connecting it it is giving me the com5 so it could be anything for you but make sure that you connect to the correct port so then you have to open another instance of the arduino ide don't do on the same instance like if you had opened this instance sorry now you have if you have opened this instance um for dx don't file don't do like this file and open don't do like this you need to open another instance another instance means you need to go to your arduino icon and you need to click it in order to launch another instance of your arduino ide so this way you will be opening a new instance of the arduino ide then you need from there you need to select the board and the com port as com5 or com9 or whatever your comport is and then you need to copy our code so this will be our code in this case esp8266rx software serial four underscore seven segment display dot i know and you need to save it so when you will open the arduino ide and you will copy this code so your code will look like this so this is the code for receiving site for the receiver esp there is no change required in the code you just need to copy and paste as is and just need to save it and after that once you have done that you need to now directly upload this code to your second esp now you will as you have already selected the com port so you are seeing that for me it's the com 5 for this and make sure that you have connected to the correct com port and then you will click on the upload button so when you will click on upload you know first it will compile the sketch as you are seeing here and the compiling it is compiling a sketch and compilation is already done and now it is uploading this code to the second esp so we are seeing that now the code is being uploaded in our second esp where we have connected our display so once the upload is uh done so you are seeing that now upload process is done and the receiver site [Music] and the code has been uploaded on the receiver side so now we have uploaded both the course so we will open the serial monitor let me close all the serial monitors which i have opened earlier so uh here now we will open the first code here px for the first esp and i will open the serial monitor for that so you are seeing that i have opened the com4 serial monitor make sure that the baud rate you have selected is nine zero nine six double zero because in the code uh we have used the baud rate as nine six double zero so so the same already you need to select so this is uh the serial monitor for the first psp and similarly you will open the serial monitor for the second esp which will open for com5 okay so now you are seeing that this is the com4 the first one is com4 serial monitor for the first esp and below that we have com5 for the serial monitor of our second esp and let me open the camera view also so that you can see uh both the esp's display and the button all together so now we are seeing clearly here two serial monitors are there com4 com5 and you are seeing both the esps with the display and the button so now we are here to ready to execute the project or uh we are ready here for clicking the push button so let's try to uh push the button here and see the results what we what we get here so as soon as i press this button on the first esp you are seeing that a message but compressed and we will as soon as we will release it uh it will transmit the data and when we will release the when we had released the button it will transmit the data it has transmitted and the data which it is sending is 2950 separated by a carrot character so you are seeing that the number which the first esp is sending is 2 9 5 0 and i am separating the number with a carrot character and if you will observe the receiver serial monitor here you are seeing that it has received the same data 2950 once the receiver esp has received the same data inside the code and we are removing all the carrot signs and we are simply displaying the number which is being sent by the sender which is 2950 on our display so if you will see here the display the display is correctly showing two nine five zero so now let's try to push the button again so when i will push this button one more time so you will see that it is sending 0 5 7 4 and at the same time it is the receiver module or the receiver esp also received the same number 0 5 7 4 using the uart module and it is showing the same number zero five seven four so let me try to push it again and so i will show you when i will push it and at the same time you just observe the display also so when i press this you are seeing a display 4 9 3 1 and on the serial monitor also you can see the number 4931 is being sent and the received at the same time let me do it one more time i'll push this button and when i will release it then only it will send the data so it has sent seven two one seven when you will push the button and when you will release the button then you will receive the data four one two seven so you're seeing here using uart communication you are able to send and receive data between two esps uh i am using a tx and rx pins and you are able to show that data on your display nicely so magicians hope this session was useful for you and you got something new today how do we do the uart communication between two esps and you can use this in in some of your future projects if it is required if you have any doubt any confusion or any issues doing this uh project let me know uh in my whatsapp or my facebook group or you can ask me in the comment section i'll reply you and if you need this document and if you need the code which i have used for this let me know for that i will send you that codes okay magicians so take care of yourself and have a nice time let me stop sharing my screen and let me close the meeting so stay tuned with me for such new sessions and such new learnings till then bye bye and take care
Info
Channel: IMH Videos
Views: 79
Rating: undefined out of 5
Keywords: IOT, Raspberry Pi, IOT Course, Online IOT projects, Amazon AWS IOT, MQTT IOT, Wireless IOT, XBEE, Home Automation, Learn IOT Online, firebase, Realtime database, ESP8266, ESP32, Micropython, IoT Core, Webserver, ESP Webserver, Telegram, BOT, Telegram Bot, Amazon Voice Service, Smart Home Skill, Amazon Alexa, SPIFFS, ESP Filesystem, ESP FileSystem Uploader, ESP32FS, Interrupts, PIR Sensor Motion, PIR, ESP NOW, ESP 2 Way communication, CloudWatch, IoT Rule Engine, WiFiManager
Id: juOO3zWDqtQ
Channel Id: undefined
Length: 28min 52sec (1732 seconds)
Published: Tue Sep 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.