What is RS485 serial communication? How to use RS-485 MODBUS to design Arduino point-point network.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome again in this tutorial so today we will talk about the modbus module or the rs 8485 module okay so this module the one we can see here let me activate my my pointer highlighter first okay so this is the module okay that will work on today this module actually is a converter it will convert from ttl logic transducer logic which is can be connected to any embedded system like pic arduino any other mcu and it can give us a connectivity to rs 485 or modbus okay in this tutorial we will talk about point-to-point network okay we will cover no point-to-point network in the next tutorial we will cover more complex uh networks okay so this this module again it's based on the max 485 chipset this is the one that's located here in the middle okay and since we're working with point-to-point so our network will be something like this okay where we have only two nodes the first node or what we call uh master and the second is slave or sometime they call it transmitter and receiver or what they call it in the modbus the driver the driver and the receiver okay so this is what we discuss in this tutorial okay so this is the construction of the module let me change to pen okay this is the construction of this module this is the main chip the max 485 this is the main chip that we are using now okay and this main chip it will connect to an mcu using this four bin okay receiver output is available uh driver enable driver inputs okay and from this side we need to supply the vcc and ground and also a and b a and b is the two wires that will be connected to another module that we use to transmit and receive the data these two wires okay these resistors the rest of the resistor these pull our resistors and this also here we have pull down resistor and also we have termination resistor these all already implemented in the module so no need to worry about these already implemented okay so we just need to connect our wire connect this side to an mcu and ceo okay and here we connect to our next network then we will have our network established okay so why we are focusing on the modbus or the rs 485 well there are uh a lot of benefits behind this module but the main points are it's provide a digital communication system whereas communicate the information over the twisted pair wire okay and this twisted paper a wire can be uh go for a very long distance can go up to 1 000 something meter which is more than one kilometer okay uh also can support up to 32 transceiver more than 32 transceivers mean more 32 not more than 32 nodes then we might need a repeater we will discuss about this later but maximum can support uh 32 node or points on the network but so far we will talk about only two uh two points which is point to point and also the communication rate can go up to 10 mega bit per second which is quite high okay and by the way it's utilized a balanced output and differential inputs this this two terms mean it has very high immunity against the noise okay because it's utilized balanced output and differential inputs it will be very immune against the noise and also uh it will be very robust compared to a normal communication system such as rs232 okay one more thing it's also has the ability to set the note into uh what they call uh disconnected or uh disabled mode okay why because we have three mods we have twice state capabilities uh which is enable the transmitter and or enable the receiver or disable it okay so that's make it compatible for multiple transceiver to be connected at the same network okay again because we support or this model support tri-state tri-state's mean has three states which is uh set the not as transmitter send the node as a receiver or set the node as disabled especially if you let's say you have more than one node and you want to talk to only between two of them let's say you have node number one node number two and node number three okay we want to talk only from this node to this node but the wire will be connected like this so definitely this node need to be disable the receiver on transmitter so it can directly talk only to this node so that's why we have three state this means either you can say it as a receiver or transmitter or disable so it can be have multiple transceiver for example here we have three transceivers okay to be connected with only two wires with multi-drop points okay so these are the main features that uh push me to make a tutorial about this module which is very very important and very famous in the industry uh applications okay so now we come to the connection between the arduino and the rs4a5 modules okay so here we have two nodes node a node b so this is the first node this is the second node so now in order to connect them i will connect the re with the e and connect it to pin number 12. by the way this module it's read the data as a serial you can just treat it as a serial output then it will convert the output to uh what they call the differential output so it can be linked to the next network so from here we can connect b to b and a to a let's say we convert to zero say black and a we connect to a okay so from here we need serial only and here also we need serial to talk to this module and this model will talk to each other using the differential output uh just using two uh these twisted as we said just now okay so again i will talk i will connect the r e d e to p number 12 here also same where's the pointer in the red again r e d e i'll connect to bin number 12. this is for the enable then let me change the ink again check this color then di the driver input i'll connect it to pin number 11 this one will be going to be number 11. this one will go to be number 11. check again let's say blue and the r ro or receiver out will be connect to number 10 okay so this is our network and for sure by the way before we forgot we need the ground and we need the ground and vcc for sure let me take this color so ground need to go to the ground and the vcc need to go to vcc you need to go to 5v vcc it support five volt vcc vcc and ground go to ground okay so this is our network i cut it from here so this is node number one this is not number two so the distance here this one can go up to one kilometer okay the distance between node one node two can go up to one columns and this is the beauty of this module without very i mean without the without suffering from any effect of noise or any disturbance of the signal okay so this is the the connection more proper connection is the same as what we discussed just now r e d e connect to open number 12 the i connect to pin number 11 ro number 10 same goes to here vcc ground also to the to each node and these are the network cable the twisted pair cable that might go up to one kilometer yes guys one kilometer is very very beautiful module okay especially in industry it's very famous model okay so now we have finished with this so let's go to see how we can connect this in the breadboard and also we start to develop the code for this module okay let's go okay so here we already connect our module to the arduino on the breadboard this is the first node or the master connected to the arduino uno this is another one connected to arduino nano and this is a and b wires connected from node one to node two for sure this one the real application we will use uh the twisted pair but here we're just using these single wires for testing okay and here again we just use same as we discussed before okay we use the di connect to pin number 10 and also d-e-r-e we shorted out the and how do we shut it out then take one wire to the number 12 on vcc crown and are also connected for both okay so this is the breadboard's connection later we will go to developer software okay okay guys so we have reached to the software part of this tutorial okay so [Music] uh first of all i'll go with the master code the master node so this is the master node okay so for the master first of all we need to include the soft cl because we will link it to the soft serial library so we need to include the software [Music] serial.h okay uh what else we need let's declare our variable so we can say define we have the rs ro pin ro we connected to pin number 10 and also rs di pin number 11 and also rs in d e and r e we short them out and connect them to p number 12. okay let's check should be okay converter happy now we define these variables we will use it later okay so now we need to define the software serial object so software serial software serial i will call it my r s master of here we should put rx and tx if you remember here need to be rx pin and tx so the rx will be the rs ro and rx sorry rs di okay rx pin connected to r0 pushes me number 10 tx di pin 11 okay so now we come to the uh setup so the function we need to initialize the serial and the software serial okay because we will use them serial begin 9600 just standard one and also i need my rs master dot pin and also 9600 okay uh what else i need to declare my enable bin okay this is the enable bin so i need to declare it has output so i'll use pin mode rs d e r e as output okay so let's compile it for sure we done very little things so i believe that compiler will be happy no issues okay so now since we are uh we have master and slave nodes and also is a half half duplex connection so we need to declare our enable to high always high for that for the master so master need to activate this one two pi to start the transition okay so we need to set this to high so digital right this one need to be high okay this one should be always high to activate the transmission okay and now we come to the loop that's all for the that's all for the one for the setup so in the loop uh how we send to the slave for sure we use the rs master which is a soft serial and for sure we will take the data from the soft from the serial or the hardware serial or the normal serial we take from the serial then we write to the software serial okay so we can see here if the serial is available the serial is available because when we type in in something in the serial if we type in in the serial then we need to do we need to send it to the uh software serial or the rs master we just need to rs sorry rs master dot right we need to write what we need to write the [Music] serial dot read we need to write whatever we read in the soft series okay so okay so my master will be com9 so the master code is done okay master code is done that's all i connect arduino to com number nine let's upload okay it's uploading and done good so now as we can see nothing happened let's add something here and we say serial dot serial open line master node is ready this one just to show that the master is ready and uh totally initialized successfully okay so see here we go master is ready so now whenever we should type in something we should see it in the slave but we didn't uh write the slave code yet so for sure we cannot see anything okay so now let's move on to the slave code okay guys so now we have reached to the slave code so that's that's command this is the slave node okay so again we need to include the software serial include so for syria then we need to define our variable defined rs ro which is on number 10 and also define rs [Music] driver input 11 hash define rs driver enable and also receiver enable pin number 12 as we saw it in the schematics okay now we need to declare the softseal object so we can say soft syria so not software syria we can call it rs slave and here we need the rs receiver output and also rs driver input okay this is our object uh what next that should be all now we need to go to the setup function in the setup function for sure we need to initialize and begin the software serials because you have software on the hardware serial so we start with the hardware serial got begin 9600 the power rates and also same to the rs slave by the way for the rs slave if they should match the frequency or the baud rate of the master if you sit there is 9600 here should be also 9 000 600 if you just change the frequency or the voltage on the master slave should be match okay so here also need to be begin and again 9600 uh now we need to initialize the driver output or driver enabled to output so we need to use pin mode the rs driver enable receiver enable as output okay and now since this one is slave okay since this one is slave the the enable pin should be low because the slave will be only received since this slave mode which is always receive the enable pin need to be low okay so digital right we need to set the enable pin into lock always okay so now we finish with the finish with the setup now we come to the [Music] loop so in the loop we need to check if the software serial is available here if the rs slave is available for sure forgot to new bracket here if this is available we just need to write on the serial or the hardware serial so we can say hardware serial or serial dot right whatever we can read from the surface here or rs slave number okay so if we get any information is ready to be read on the chauffeurs here or the slave then we directly will be write it to the soft or the hardware serial okay so i believe that's all let's add something to display some comments on the serial so serial dot print line we can say the slave node is ready yeah that's all so the slave i use arduino nano com number five that's all let's send it and see if everything goes well okay it's updating and done beautiful so now five the slave is ready let me let me open the the master there we go this is the master and this is the sleeve let's me bring this one here so now if we send from the master say hi you see we receive it at the sleeve this is the sleeve but if we send from the slave cannot be sent so we send any data here let's say one two three you see we receive it one one two two three three okay we see but anything from here cannot bcy because it's a one-way communication okay so this is the first tutorial done we can say for master we can send data for example we can send temperature this then from here when we receive t equal 10 we can split the the receive string piece on the equal then we take the first one as identifier or the uh special character that can recognize what is the data for grantees temperature and after the equal will be the value of that variable which is the temperature okay this one will do it in the next example but now how we can do both way for example now i can send from here go to the slave but how if this they want to respond how they slave if slave need to respond to the uh master so we need to do some changes okay we need to do some changes uh first of all the change will be uh here so the change will be not only if the rs available then we send but we have another condition [Music] we have another condition if the cereal is available if the sale is available what we need to do okay if now the master need to reply okay sorry the slave need to reply okay if it is available first of all we need to enable the transmitter for the slave itself so we need to use this and enable it how to enable it we just set this to hi okay now i want to reply i need to enable this after i enable it then i need to send the data first i need to enable the driver then send the data how to send the data i use the rs slave tried and write whatever in the serial okay after i send the data need to disable the driver how to disable the driver by just using this command again okay now i can reply to the master by using this code all these small changes okay let's upload to the slave and test again okay done okay so this is the slave this is the master okay now from master we send okay we sent to the slave to the master we can say nothing yet why we cannot receive anything because the master code is still permanently uh activate the the the driver as transmitter not receiver we always the master always if we go to the master code okay guys so as we said just now we can send from master to slave no problem but from slave still even though we update the code but still got no effect why if we double check the master code again this is the master code we can notice that the master always activate the driver enable or receiver enable to hide which is preventing it from receiving any information from outsiders where but only sending the data so we need to change this a bit okay so how to change this we can say here in the master if the serial is available if this one available then we will set this to high or we can say activate the transmitter because we have more than one comment after this we need a bracket so activate the transmitter then we send the data then we need to disable [Music] this one set too low or we need to say uh the receiver okay please click this one as well now now after we finish this now we can check if we got any information received or the rs master is available if this one is available we got any information received by the rs master from the slave okay we need to send it to where syria or the hardware series so serial don't write we write what we write the data we read it from the master so we can say rs master dot grid we sent this data okay so now we already and the arduino 1099 is my master and look okay so now after we finish these small changes i i expect them to uh communicate with each other as usual okay so now i say from slave [Music] but this one oh no okay yeah because we need to restart the full uh unit so now if i send one to three back to the master no problem so now from here for example i can request the temperature then they say oh they request the temperature then i can say temperature equal to 100 celsius like this okay so i can send request and return with the information okay so with this we have finished the first tutorial we can say is very straightforward okay this is the master and the slave code also so we need to define our [Music] bins that we use to communicate or to interface with the rs uh module then we use the soft serial uh this library also we define our power rate power rate master and step should be same this one need to be matched and then you know to make it one-way communication we need to always set this to high if you want to make it two-way communications then we need to um alternate the enable pin or the transmitter receiver by using this method same goes to the uh what they call the sleeve okay this is the sleeve same this is the ios pin that we use library soft serial and also we declare our power rate this is the pin that we use to set whether send or receive and there is the code very straightforward okay so i hope you have learned something from this tutorial uh thanks a lot for your time and let me know if you need more explanation thank you
Info
Channel: Challenger Tech.
Views: 56,932
Rating: undefined out of 5
Keywords: RS485, RS-485, MODBUS, serial communication, RS485 TTL module, WSN, wireless sensor node, wireless sensor netword, arduino, network addressing, wsn programming, EPDD, embedded system, c coding, wireless programing, Advanced Wireless Sensor Node Addressing: Arduino, Wireless Sensor Node Addressing, addressing techniqes, wireless signals, wireless trigger, wireless data routing, wireless data addressing, arduino string, node addressing, network identificatin, WSN coding, serial
Id: XicxOsAhCv0
Channel Id: undefined
Length: 40min 29sec (2429 seconds)
Published: Fri Aug 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.