Тёмный
No video :(

RS485 with NodeMCU, ESP8266, ESP32, Arduino | RS485 Protocol | Implementation | Urdu | Hindi 

JP Learning
Подписаться 2,3 тыс.
Просмотров 9 тыс.
50% 1

In this tutorial, we will take a deep dive into the RS-485 protocol, a widely used communication standard for serial data transmission in industrial and automation applications. We'll cover the basics of RS-485, including its electrical characteristics, signal levels, and physical layer specifications. We'll also discuss the differences between RS-485 and other serial communication protocols and explore some of the common challenges that arise when implementing RS-485 networks. By the end of this tutorial, you'll have a solid understanding of RS-485 and be equipped with the knowledge to design, troubleshoot, and optimize RS-485 networks.
#rs485 #serial #communication #industrialautomation #communicationprotocol #nodemcu #esp8266 #esp32 #arduino #iiot #industrialiot #urdu #hindi
My last video link
• IIoT Communication Pro...
Software Serial video link
• Software Serial in ESP...
Follow us on Facebook
/ jiyepakistanlearning
Follow us on LinkedIn
/ jplearning
Follow us on Instagram
/ jiyepakistanlearning
Follow us on TikTok
/ jplearning

Опубликовано:

 

25 мар 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 105   
@mastramhack8255
@mastramhack8255 Год назад
Sir please tell me how I store data in any holdring resistor come by gpio pin in esp32 or esp8266 or arduino nano. And via modscan by rs485 I see that data on modscan32
@JPLearning
@JPLearning Год назад
Dear you need to use write single/multiple register function to write data in holding registers. Please check sample code for Library which you are using.
@mastramhack8255
@mastramhack8255 Год назад
So Sir can you tell me by which library I do this
@mastramhack8255
@mastramhack8255 Год назад
Or In which library sample code is given
@JPLearning
@JPLearning Год назад
You can follow this video so you can understand. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kFeTM5xicU8.html
@Learningontop
@Learningontop Год назад
Sir by this tutorial I does not understand anything. Please make seperate tutorial on it or give me another option to do this work
@praveenkumaru5507
@praveenkumaru5507 4 месяца назад
Hello sir, can we read and write value if we use pid controller( selec pid500) for heater. it have rs485 communication, if yes how to read and write plz guide sir.
@JPLearning
@JPLearning 4 месяца назад
Hi Parveen, Yes, we can read and write if your pid controller support modbus protocol and for that you need read manual of modbus communication of your pid controller.
@iklasadichandra3003
@iklasadichandra3003 Месяц назад
hllo sir , youre code is not working , can you explan to me how to fixed ?
@JPLearning
@JPLearning Месяц назад
What are you doing in your code?
@iklasadichandra3003
@iklasadichandra3003 Месяц назад
@@JPLearning i have 2 arduino and i intend for communicate via RS485 . i use software serial in arduino connect to rs485
@JPLearning
@JPLearning Месяц назад
@@iklasadichandra3003 tell me your connections and share code with me.
@iklasadichandra3003
@iklasadichandra3003 Месяц назад
@@JPLearning can i send by email ?
@JPLearning
@JPLearning Месяц назад
@@iklasadichandra3003 sure
@MT_IOT
@MT_IOT 4 месяца назад
help me. I want to transmit any data to 2 esp using RS485 TxRx version
@JPLearning
@JPLearning 4 месяца назад
What is the issue you are facing?
@MT_IOT
@MT_IOT 4 месяца назад
I can't receive transmitted data from ESP32 master@@JPLearning
@JPLearning
@JPLearning 4 месяца назад
Why and what is the issue ? Share your code so I can check the issue
@MT_IOT
@MT_IOT 4 месяца назад
code master #include #define TEMPERATURE_REGISTER 0x00 // Địa chỉ register cho nhiệt độ #define Slave_ID 0 ModbusMaster node; void setup() { Serial.begin(9600); node.begin(0,Serial); } void loop() { int temperature = random(0, 100); // Giả lập nhiệt độ node.writeSingleRegister(TEMPERATURE_REGISTER, temperature); // Gửi dữ liệu nhiệt độ Serial.println("transmission temperature:"); Serial.println(temperature); delay(1000); } code slave #include #define TEMPERATURE_REGISTER 0x00 // adresse register temperature #define Slave_ID 1 ModbusMaster node; void setup() { Serial.begin(9600); node.begin(1,Serial); } void loop() { int temperature; int a; uint8_t vfdonoff= node.readHoldingRegisters(TEMPERATURE_REGISTER, 1); delay(25); // nếu đọc trạng thái thành công if(vfdonoff == node.ku8MBSuccess) { a = node.getResponseBuffer(vfdonoff); Serial.println("data temperature"); Serial.print(a); } else{ Serial.print("ERROL"); Serial.println(a); } delay(1000); } I use RS485 version 2 TxRx circuit but cannot transmit data. Please help me thank you @@JPLearning
@MT_IOT
@MT_IOT 4 месяца назад
@@JPLearning I cannot read the data received from the transmitting master and I use the RS485 V2 TxRx version. Please help me thank you Code master #include #define TEMPERATURE_REGISTER 0x00 // Địa chỉ register cho nhiệt độ #define Slave_ID 0 ModbusMaster node; void setup() { Serial.begin(9600); node.begin(0,Serial); } void loop() { int temperature = random(0, 100); // Giả lập nhiệt độ node.writeSingleRegister(TEMPERATURE_REGISTER, temperature); // Gửi dữ liệu nhiệt độ Serial.println("transmission temperature:"); Serial.println(temperature); delay(1000); } code slave #include #define TEMPERATURE_REGISTER 0x00 // adresse register temperat #define Slave_ID 1 ModbusSlave node; void setup() { Serial.begin(9600); node.begin(SLAVE_ID, Serial); // Khởi tạo node Modbus với ID là SLAVE_ID và sử dụng Serial để giao tiếp } void loop() { int temperature; int a; uint8_t vfdonoff= node.readHoldingRegisters(TEMPERATURE_REGISTER, 1); delay(25); // nếu đọc trạng thái thành công if(vfdonoff == node.ku8MBSuccess) { a = node.getResponseBuffer(vfdonoff); Serial.println("data temperature"); Serial.print(a); } else{ Serial.print("ERROL"); Serial.println(a); } delay(1000); }
@aligul4035
@aligul4035 8 месяцев назад
how to change the address of the sensor
@JPLearning
@JPLearning 8 месяцев назад
You need to check your sensor datasheet the way you will find
@shahidmahmood7252
@shahidmahmood7252 Год назад
Thank you. Good informative video. Can you please make another video with one master and multi (2 or 3) slaves based on MAX485 with Arduino.
@JPLearning
@JPLearning Год назад
Thank you for support. Sure, Next uploaded video will be 1 master and multi salves.
@JPLearning
@JPLearning Год назад
Dear Shahid here is your requested video. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-X8VxQ7lCWKc.html
@ashishadhikari5461
@ashishadhikari5461 4 месяца назад
lekin sir slave id or holding register kaha mention kiya hai code mai or agar data modscab software mai dekhna ho toh ( mera mtlb ki abhi aapka data serial monitor pe show ho raha hai lekin agar data muje modscan mai dekhna hai jo aapne sender banaya hai ttl- rs485 se ) mene koshish ki thi lekin sir mera code error de raha hai 226 ka. please ek sjhma dijiye
@JPLearning
@JPLearning 4 месяца назад
Modscan me option hota hai ID and register type select krny ka
@ashishadhikari5461
@ashishadhikari5461 4 месяца назад
@@JPLearning thank you for reply sir. lekin sir code error 226 kyu de raha hai jab mai value integer mai send kr raha hu or slave (node id) bhi bana rakhi hai mene 1 or holding register bhi banaya hai phir bhi error aa raha hai
@JPLearning
@JPLearning 4 месяца назад
Dekhna hoga aesy samjh nahi araha mjhy.
@0124akash
@0124akash Год назад
Sir RS485 ka use samjh nahi aaya.....sensor ko to directly esp32 se connect kar sakte the aur uska data blynk jaise kisi web application par dekh lete.
@JPLearning
@JPLearning Год назад
Jese har sensor ka koi hardware interface hota hai example (Digital, Analog, I2C, SPI Protocols) isi tarha se RS-485 ek hardware protocol hai jisky benefits alag hen or Industrial me zyadatar use hota hai.
@adepudurgasree
@adepudurgasree 5 месяцев назад
Sir can you give the code that can read the data from lg2599p energy meter and give it to the max 485 transceiver and esp32
@JPLearning
@JPLearning 5 месяцев назад
I can only guide you to do this.
@adepudurgasree
@adepudurgasree 5 месяцев назад
@@JPLearning thank you sir
@youssefbentahra
@youssefbentahra 11 месяцев назад
Hi sir! I have a problem trying to read data from an Variable frequency drive (inverter). I am using the module MAX485 with RO and DI pins. With arduino all work good but when I try to do the same with ESP32, nothing is working. Please, do you have any example or suggestion? Thank you. Please help me.
@JPLearning
@JPLearning 11 месяцев назад
You need to just change your pins configurations or may be you need to use Serial2 OR HardwareSerial library in ESP32
@youssefbentahra
@youssefbentahra 11 месяцев назад
Thank you for your answer. I tried a lot of things for one month and its not working. I dont know what to try more. I have this example that didn't work on ESP32 but it's working on Arduino perfectly. I try to search another example with library ModbusRTU.h but it's not working at all on ESP32 and in Arduino I can see some data. I attach the code: #include #define baud 9600 #define timeout 1000 #define polling 200 #define retry_count 10 #define TxEnablePin 15 enum { PACKET1, TOTAL_NO_OF_PACKETS }; Packet packets[TOTAL_NO_OF_PACKETS]; packetPointer packet1 = &packets[PACKET1]; unsigned int volt[2]; long time_past=0; void setup() { pinMode(7,INPUT); Serial.begin(9600); Serial2.begin(9600, SERIAL_8N1, 27, 26); modbus_construct(packet1, 2, READ_HOLDING_REGISTERS, 3846, 1, volt); modbus_configure(&Serial2, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS); time_past = millis(); } void loop() { modbus_update(); if((millis()-time_past) >= 500) { Serial.print("Voltage: "); Serial.print(volt[0] / 10.0f); Serial.println(" V"); Serial.println(); time_past = millis(); } } And the other code is with different library is: #include #include float InttoFloat(uint16_t Data0,uint16_t Data1) { float x; unsigned long *p; p = (unsigned long*)&x; *p = (unsigned long)Data0
@JPLearning
@JPLearning 11 месяцев назад
Just try this code it's 100% working code with my VFD on ESP32. Change pins, addresses and settings accordingly. Note: You need to install ModbusMaster.h library first. #include #include HardwareSerial hardwareSerial(1); ModbusMaster node; #define MAX485_DE_RE 14 #define RXD2 16 #define TXD2 17 void preTransmission() { digitalWrite(MAX485_DE_RE, 1); } void postTransmission() { digitalWrite(MAX485_DE_RE, 0); } // VFD Parameters #define ID_meter 1 // Trip Information #define Reg_TripInfo 0x2100 // Output Frequency #define Reg_F 0x2103 // Output Current #define Reg_I 0x2104 // Output Voltage #define Reg_V 0x2106 // Inverter status #define Reg_InverterStatus 0x2101 #define Total_of_Reg 5 uint16_t Reg_addr [Total_of_Reg] = { Reg_TripInfo, Reg_F, Reg_I, Reg_V, Reg_InverterStatus, }; double All_DATA [Total_of_Reg]; bool statusRead = false, voltageRead = false; void setup() { Serial.begin(9600); Serial.println(" ESP Start."); hardwareSerial.begin(9600, SERIAL_8N2, RXD2, TXD2); node.begin(ID_meter, hardwareSerial); node.preTransmission(preTransmission); node.postTransmission(postTransmission); pinMode(MAX485_DE_RE, OUTPUT); delay(5000); } void loop() { GET_All_DATA(); String data = "Data_" + String(All_DATA[4]) + "_" + String(All_DATA[1]) + "_" + String(All_DATA[2]) + "_" + String(All_DATA[3]) + "_" + String(All_DATA[0]); Serial.println(data); } double Read_Data(uint16_t REG) { uint8_t result, j; double value = 0; byte dataReadLength = 1; uint16_t data[dataReadLength]; // result = node.readInputRegisters(REG, dataReadLength); result = node.readHoldingRegisters(REG, dataReadLength); ///< Modbus function 0x04 Read Input Registers //Serial.println("result: " + String(result, HEX) + ", " + String(result)); if (result == node.ku8MBSuccess) { for (j = 0; j < dataReadLength; j++) data[j] = node.getResponseBuffer(j); value = data[0]; Serial.println("value: " + String(value, HEX) + ", " + String(value)); return value; } else { Serial.println("Read data fail and address: " + String(REG, HEX) + ", " + String(REG)); return -1; } } void GET_All_DATA() { Serial.println(); for (byte i = 0; i < Total_of_Reg ; i++) { //Serial.println(" Reg_addr[" + String(i) + "]: " + String(Reg_addr[i], HEX) + ", " + String(Reg_addr[i])); All_DATA[i] = Read_Data(Reg_addr[i]); //Serial.println("All_DATA[" + String(i) + "]: " + String(All_DATA[i], HEX) + ", " + String(All_DATA[i])); delay(100); } Serial.println(); }
@youssefbentahra
@youssefbentahra 11 месяцев назад
THANK YOU SO SO MUCH SIR!!! It worked perfectly.@@JPLearning
@youssefbentahra
@youssefbentahra 11 месяцев назад
@@JPLearning Sir I have another cuestion. Please if I want to write a register, I have only to execute this line "node.writeSingleRegister(address,lenght)"? And where I put my value to write it in my device? Thank you for your help.
@user-pj2zx8uv8x
@user-pj2zx8uv8x 11 месяцев назад
Thank you!!!! :-)
@JPLearning
@JPLearning 11 месяцев назад
You're welcome!
@smarthome1441
@smarthome1441 6 месяцев назад
Sir, how to program code for rs485 2 pin communication rx tx ?
@JPLearning
@JPLearning 6 месяцев назад
I already showed how you can code for RX TX. if you have specific issue let me know then I can help you.
@smarthome1441
@smarthome1441 5 месяцев назад
I want to send 3 temperatures from sleeve 1,2,3 to the master. It's better to use max485 which has 2 pin rx tx or 4 pin which has de re pin@@JPLearning
@JPLearning
@JPLearning 5 месяцев назад
First you need to set unique slaveID for all 3 sensors like(1,2,3) and then you can read all 3 sensors from 1 max485 module. Please watch this video and you can better understand Video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-X8VxQ7lCWKc.html
@PrashantKumar-oh3fi
@PrashantKumar-oh3fi 9 месяцев назад
Please share arduino float data through modbus
@JPLearning
@JPLearning 9 месяцев назад
Sorry I don't understand what you are asking?
@khetimachineryindia
@khetimachineryindia Год назад
Nice video...please share the code file also....
@JPLearning
@JPLearning Год назад
This video is just showing simple demo to share data with RS-485 modules. You can see my another videos on RS-485 and Modbus.
@Prashant-wj9jk
@Prashant-wj9jk Год назад
Thanks sir , I have one problem with my rs485 leafwetness sensor jxbs-3001-YMSD which I purchased one month ago it's not showing output value show response zero , I use your code for temperature sensor rs485 with my leafwetness sensor inquire frame but it not show output value show zero 0⃣ can you solve issue
@JPLearning
@JPLearning Год назад
Please share more info of communication parameters like communication configurations, Modbus information.
@Prashant-wj9jk
@Prashant-wj9jk Год назад
@@JPLearning it's leafwetness sensor manufactured by chaines company jxct it provided user manual with inquire frame 0x01 0x03 0x00,0x20 0x00,0x02 0xC5 0xC1 for temperature and humidity four wire connector vcc, GND, A,B I am using arduino uno with rs485 to ttl converter
@JPLearning
@JPLearning Год назад
Use this whole code just change TX, RX, DE and RE pins according to your H/W connections. #include #include // GPIO Pins byte TX_PIN = D2, RX_PIN = D1; byte DE_PIN = D6, RE_PIN = D5; SoftwareSerial Soft_Serial(RX_PIN, TX_PIN); ModbusMaster node; // Variables #define Sensor_ID 1 #define Reg_Address 0x0020 // for Humidity and Temperature float Humidity, Temperature; void preTransmission() { digitalWrite(DE_PIN, HIGH); digitalWrite(RE_PIN, HIGH); } void postTransmission() { digitalWrite(DE_PIN, LOW); digitalWrite(RE_PIN, LOW); } void setup() { Serial.begin(115200); Soft_Serial.begin(9600); pinMode(DE_PIN, OUTPUT); pinMode(RE_PIN, OUTPUT); node.begin(Sensor_ID, Soft_Serial); node.preTransmission(preTransmission); node.postTransmission(postTransmission); delay(1000); Serial.println(" Welcome to JP Learning "); } void loop() { Read_Data(Reg_Address); Serial.println(" Leaf Humidity = " + String(Humidity, 2) + " %"); delay(100); Serial.println("Leaf Temperature = " + String(Temperature, 2) + " °C "); delay(2000); } void Read_Data(int Reg_Addr) { uint8_t result, j; long value = 0; byte dataReadLength = 2; uint16_t data[dataReadLength]; // Disable watchdog reset ESP.wdtDisable(); result = node.readHoldingRegisters(Reg_Addr, dataReadLength); Serial.println("result: " + String(result, HEX) + ", " + String(result)); // Enable watchdog reset ESP.wdtEnable(1); if (result == node.ku8MBSuccess) { for (j = 0; j < dataReadLength; j++) { data[j] = (node.getResponseBuffer(j)); Serial.println("data[" + String(j) + "]: " + String(data[j], HEX) + " " + String(data[j])); } String dataTemp = String(data[0], HEX); Serial.println(" dataTemp = " + dataTemp); int value = hexToDec(dataTemp); Serial.println(" value = " + String(value)); Humidity = float(value) / 10; dataTemp = String(data[1], HEX); Serial.println("dataTemp = " + dataTemp); value = hexToDec(dataTemp); Serial.println("value = " + String(value)); Temperature = float(value) / 100; } else { Serial.print("Connect modbus fail. REG >>> "); Serial.println(Reg_Addr); // Debug delay(1000); } } int hexToDec(String hexString) { int decValue = 0, nextInt; for (int i = 0; i < hexString.length(); i++) { nextInt = int(hexString.charAt(i)); if (nextInt >= 48 && nextInt = 65 && nextInt = 97 && nextInt
@Prashant-wj9jk
@Prashant-wj9jk Год назад
@@JPLearning thanks for help I will use this code again thank you very much
@JPLearning
@JPLearning Год назад
Most welcome and keep supporting me.
@Prashant-wj9jk
@Prashant-wj9jk Год назад
Sir any solution you find
@JPLearning
@JPLearning Год назад
For what?
@Prashant-wj9jk
@Prashant-wj9jk Год назад
@@JPLearning leafwetness sensor
@JPLearning
@JPLearning Год назад
Please try this code #include // GPIO Pins byte TX_PIN = D2, RX_PIN = D1; byte DE_PIN = D6, RE_PIN = D5; SoftwareSerial Soft_Serial(RX_PIN, TX_PIN); // Variables byte no_Byte, incomingByte[9] = { 0 }; byte sendBuffer[] = { 0x01, 0x03, 0x00, 0x20, 0x00, 0x02, 0xC5, 0xC1 }; float humidity, temperature; void setup() { Serial.begin(115200); Soft_Serial.begin(9600); pinMode(DE_PIN, OUTPUT); pinMode(RE_PIN, OUTPUT); delay(1000); Serial.println(" Leaf Humidity and Temperature Monitor "); } void loop() { read_Modbus(); if (no_Byte >= 9) { String incomingBytesInString[no_Byte]; // Serial.println(" no_Byte = " + String(no_Byte)); for (int i = 0; i < no_Byte; i++) { // Serial.print("incomingByte[" + String(i) + "] = "); // Serial.println(String(incomingByte[i]) + " " + String(incomingByte[i], HEX)); if (String(incomingByte[i]).length() == 1) incomingBytesInString[i] = "0" + String(incomingByte[i], HEX); else incomingBytesInString[i] = String(incomingByte[i], HEX); } String dataTemp = incomingBytesInString[3] + incomingBytesInString[4]; Serial.println(" dataTemp = " + dataTemp); int value = hexToDec(dataTemp); Serial.println("value = " + String(value)); humidity = float(value) / 10; dataTemp = incomingBytesInString[5] + incomingBytesInString[6]; Serial.println("dataTemp = " + dataTemp); value = hexToDec(dataTemp); Serial.println("value = " + String(value)); temperature = float(value) / 100; Serial.println(" Humidity = " + String(humidity, 2) + " %"); Serial.println("Temperature = " + String(temperature, 2) + " °C "); no_Byte = 0; } delay(5000); } void read_Modbus() { // Transmition Enable digitalWrite(DE_PIN, HIGH); digitalWrite(RE_PIN, HIGH); // Serial.println(" sizeof(sendBuffer): " + String(sizeof(sendBuffer))); // for (byte i = 0; i < sizeof(sendBuffer); i++) { // Serial.println("Request: " + String(sendBuffer[i], DEC) + " " + String(sendBuffer[i], HEX)); // } // Serial.println(); Soft_Serial.write(sendBuffer, sizeof(sendBuffer)); // Receiving Enable digitalWrite(DE_PIN, LOW); digitalWrite(RE_PIN, LOW); while (Soft_Serial.available() > 0) { // Serial.println(Soft_Serial.read(), HEX); byte temp = Soft_Serial.read(); Serial.println("Response: " + String(temp, DEC) + " " + String(temp, HEX)); incomingByte[no_Byte] = temp; no_Byte++; } } int hexToDec(String hexString) { int decValue = 0, nextInt; for (int i = 0; i < hexString.length(); i++) { nextInt = int(hexString.charAt(i)); if (nextInt >= 48 && nextInt = 65 && nextInt = 97 && nextInt
@Prashant-wj9jk
@Prashant-wj9jk Год назад
@@JPLearning ok sir I will try
@Mechaworld.
@Mechaworld. 11 месяцев назад
ESP 32 with PLC by RS 485
@JPLearning
@JPLearning 11 месяцев назад
Are you facing any issues with ESP2?
Далее
UART To RS-485 Interface  / Pro Mini / LoRa Interface
9:51
These Illusions Fool Almost Everyone
24:55
Просмотров 1,8 млн