tag:blogger.com,1999:blog-677700539096386766.post3847729649102841074..comments2023-04-03T22:24:10.153+02:00Comments on Arduino Experience: Another Modbus slave examplesubyhttp://www.blogger.com/profile/16564867150960697026noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-677700539096386766.post-50489536332635840742018-03-17T07:52:07.280+01:002018-03-17T07:52:07.280+01:00Just ask for it! Just ask for it! subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-37928381917361473392018-03-16T22:04:20.591+01:002018-03-16T22:04:20.591+01:00Your code is very useful and as a newbie to MODbus...Your code is very useful and as a newbie to MODbus most manuals that i have read don't use codes to explain the how to configure master and slave for arduino. i have found videos explaining basics, but as we all do it and cut and paste to build a code to create one. I hope i wont ask for too much, but if i have question may I ask for your assistance?Anonymoushttps://www.blogger.com/profile/04237969976492287996noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-5313161486006422282017-08-18T20:49:43.548+02:002017-08-18T20:49:43.548+02:00Hi, How can I change the address registers, for ex...Hi, How can I change the address registers, for example my holding registers should start at 4000 and coil register should start at 3001, Is there a way to do it.Anonymoushttps://www.blogger.com/profile/11745090006761087810noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-62657922702023331112017-07-12T21:23:37.599+02:002017-07-12T21:23:37.599+02:00sorry i have forgetten to mention i am using ardui...sorry i have forgetten to mention i am using arduino mega 2560mahihttps://www.blogger.com/profile/11945430626898918729noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-10658265790166133412017-07-12T21:21:04.244+02:002017-07-12T21:21:04.244+02:00Hai SUBY,
really it is great support froom you ...Hai SUBY,<br /><br /> really it is great support froom you can .<br /><br />i have copied the code and it is working fine with arduino port but with rs 485 it is not working fine <br /><br />i have used rs485 to usb convertor and connected pin 18,19 to convertor .<br /><br />can you give me details of wiring .mahihttps://www.blogger.com/profile/11945430626898918729noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-64572675190787548132016-06-14T13:58:55.410+02:002016-06-14T13:58:55.410+02:00Hey guys!
am trying to build a Seriall communiati...Hey guys! <br />am trying to build a Seriall communiation between a few Arduinos by using RS485 Serial communication and Modbus RTU Protocoll! I am using an Arduino Uno as a Master and 4 Arduino Uno as Salves.<br />I was searching on internet to find a proper Library for my Modbus rtu Communication, undortunately, i couldn't find any! Could someone help me out?<br /><br />Cheers,<br />WalkieeeAnonymoushttps://www.blogger.com/profile/18166432650998615736noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-89373552194497476942015-10-19T22:21:11.432+02:002015-10-19T22:21:11.432+02:00Hello Manjunath,
I'm afraid that my library i...Hello Manjunath,<br /><br />I'm afraid that my library isn't completely compatible with the software serial library. You must be careful because any "delay" instance interferes whenever there is a Modbus pooling. This is particularly critical with the Modbus slave, where you can miss some telegram. <br /><br />In your case, you are using it as a Master. Therefore you must make sure that you aren't using the software serial port while there is a pending query at the Modbus side. <br /><br />You need to perform a au16reg[] "serial.print" to your Hercules terminal. Have you tried to make "serial.print" for a set of values?<br /><br />Cheers, subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-73666366000717799222015-10-16T16:33:50.388+02:002015-10-16T16:33:50.388+02:00Hai I am Manjunath for 3 week am searching for mod...Hai I am Manjunath for 3 week am searching for mod-bus library and finally got success by using your library.<br />My arduino with Rs485 is communicating well. com LED also blink continuously,<br /><br />Here my Question is how can I read particular holding register say for example 40157 is frequency parameter and all Register floating point data from 40101 to 40125 from my Energy meter to arduino and show at soft serial port say pin(10,11). to Serial terminal(Hercules)<br /><br /> These are the <br /> Arduino - Duemilenove -->(Master)<br /> Energy Meter - EN8400 Navigator made by Elmearsure. --> (Slave)<br /> Protocol - Mod bus RTU via RS485.<br /> Com port - 9600 8 bit no-parity 1- stop bit.<br /> Devie ID - 4.<br /> <br />Anonymoushttps://www.blogger.com/profile/05263526865206956142noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-32957785770899460542015-02-16T17:49:07.590+01:002015-02-16T17:49:07.590+01:00I'm afraid that you missunderstood the way to ...I'm afraid that you missunderstood the way to implement these methods. The "setup" section is only called once during the initialisation of your program. You need to refresh your node address while working. Thus you must call them in the "loop":<br /><br />void loop {<br />int Device_ID=ID_Check();<br />if (Device_ID>oldID )<br />{<br />slave.setId( Device_ID);<br />oldID = Device_ID;<br />}<br />slave.poll( au16data, 16 );<br />}subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-65358411992535216032015-02-10T05:18:33.010+01:002015-02-10T05:18:33.010+01:00yes suby i tried Set ID function calling in setup ...yes suby i tried Set ID function calling in setup function before<br /><br />int oldID =1;<br />int Device_ID=1;<br />void setup<br />{<br /> int Device_ID=ID_Check();<br /> if (Device_ID>oldID )<br /> {<br /> slave.setId( Device_ID);<br /> oldID = Device_ID;<br /> } <br />Modbus slave(Device_ID,0,0);<br />}ajithttps://www.blogger.com/profile/05141435743150981272noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-28130421744734135142015-02-09T22:51:50.965+01:002015-02-09T22:51:50.965+01:00Dear Ajit,
The library provides two methods to cha...Dear Ajit,<br />The library provides two methods to change the slave address (other than 0) and to read it. These are. "setID"and "getID". I haven't still tried them.<br />Just implement in the loop section an statement to check if the slave ID has changed since the last time like this:<br /><br />If (ID_value <> oldID) {<br /> slave.setId( ID_value);<br /> oldID = ID_value; } subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-52531335813979714312015-02-09T12:00:07.542+01:002015-02-09T12:00:07.542+01:00How can i assign slave ID here.i am using 8:1 mux...How can i assign slave ID here.i am using 8:1 mux & 16 PIN Dip switch. depend on status of digital value calcualte device ID. Serially i checked, device variable changes with postion of DIp switch. when i check in qmodbus.it wont work. Let me know how can i resolve this. or let me know we should configure slave ID for indivuall device in code itself/<br />#include <br />#define Slave_ID 1<br />uint16_t au16data[16] = {<br /> 3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };<br /><br />Modbus slave(Slave_ID,0,0); // this is slave @1 and RS-232 or USB-FTDI<br /><br />void setup() {<br /> slave.begin( 9600 ); // baud-rate at 19200<br />}<br /><br />void loop() {<br /> slave.poll( au16data, 16 );<br />}<br /><br />int ID_Check() {<br /> int ID_value;<br /> for(int row=0;row<8;row++)<br /> {<br /> digitalWrite(SO_enable,array[row][0]);<br /> digitalWrite(S1_enable,array[row][1]);<br /> digitalWrite(S2_enable,array[row][2]);<br /> Status_Out[row]=digitalRead(Output_Read);<br /><br /> }<br /> <br /> ID_value = 1 * Status_Out[0] + 2 * Status_Out[1] + 4 * Status_Out[2] + 8 * Status_Out[3] + 16 * Status_Out[4] + 32 * Status_Out[5] + 64 * Status_Out[6] + 128 * Status_Out[7];<br /> return(ID_value);<br />}<br /><br />I would like to assign the return value to slave ID. Let me Know how can i assign it. i tried to call function in setup & assign value. The Serially i check slave ID changes as DIp switch changes<br /><br />ajithttps://www.blogger.com/profile/05141435743150981272noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-47476654059313495142014-07-07T21:41:49.692+02:002014-07-07T21:41:49.692+02:00Yes, here it is:
http://arduino-experience.blogsp...Yes, here it is: <br />http://arduino-experience.blogspot.com.es/2014/07/broken-link-to-my-modbus-slave-example.html<br />You will see that this is a simplier sketch. You can extend it to behave as this post, if you copy the contents of setup() and loop() instances. <br />I hope this helps you!subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-52979536122551705062014-07-07T19:05:37.427+02:002014-07-07T19:05:37.427+02:00The dropbox link appears to be down, could you ple...The dropbox link appears to be down, could you please publish it again?Anonymoushttps://www.blogger.com/profile/14979731114286164291noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-38723043222133445942014-05-29T22:26:14.321+02:002014-05-29T22:26:14.321+02:00There is a link to a dropbox .zip file in this sam...There is a link to a dropbox .zip file in this same post. The library is written as a project module. It is fully functional, but I'm still moving it to a .h file.<br /><br />Regardssubyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-6870402489620608122014-05-26T16:52:50.728+02:002014-05-26T16:52:50.728+02:00Hi Where can i download the library?Hi Where can i download the library?Anonymoushttps://www.blogger.com/profile/17521909574649255811noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-36861689600097589922014-04-21T18:00:27.143+02:002014-04-21T18:00:27.143+02:00There is nothing to do in the code itself. All thi...There is nothing to do in the code itself. All this must be done in the Master, who throws all the queries. The Slave just answers the incoming queries. If it doesn't understand them, then it throws an exception.<br /><br />With QModbus, just try:<br /><br /><br />- to write coils between 16 and 19 with function 15 (for instance, put 0x1001);<br />- to write coil 18 with 0x00 or 0xff, so it would become a 0 or a 1.subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-35002495305487665662014-04-15T13:26:53.113+02:002014-04-15T13:26:53.113+02:00How to call write function code 6 & 15 in your...How to call write function code 6 & 15 in your example code.Suppose i want to write au16data[6] using function code 6 . How could i write .Can share small example.ajithttps://www.blogger.com/profile/05141435743150981272noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-75923309316036460272014-04-09T22:51:14.287+02:002014-04-09T22:51:14.287+02:00Refer to this topic:
http://forum.arduino.cc/index...Refer to this topic:<br />http://forum.arduino.cc/index.php?topic=213432.msg1587070#msg1587070subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-64555039133075805832014-04-09T22:46:54.441+02:002014-04-09T22:46:54.441+02:00I don't give this sort of support. :-)
As I ha...I don't give this sort of support. :-)<br />As I have browsed, it's an RS485 shield, so just look at the wiring between your Master and this slave:<br />- if both are using RS485<br />- if terminals A(-), B(+) and GND are wired together<br />- if the cable is long, remember to put 120 ohm terminal resistors on both sides between A and B<br />Before starting to work with RS485, I would try USB and mount a virtual port on the PC and run a Modbus Master program. Afterwards you can start with RS485.subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-5511778188603705252014-04-09T22:40:49.867+02:002014-04-09T22:40:49.867+02:00Dear Ajit,
Regarding to these 3 points:
1) The sla...Dear Ajit,<br />Regarding to these 3 points:<br />1) The slave address is changed with the ID definition. Anyway I think that I wrote a method called "setID", which can be called anytime to this value. For example, you could associate it to a DIP switch.<br />2) Just refer to Arduino Rerence available here:<br />http://arduino.cc/en/Reference/HomePage<br />You shall find how to work with words and fill their low and high bytes or how to split them into two bytes.<br />3) Have you really measured the voltage at your analog input 3? Maybe your potentiometer is wiring somewhere else or not supplied with 5 V.<br />Good Luck!subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-10143959246158252062014-04-09T07:24:31.152+02:002014-04-09T07:24:31.152+02:00I have finally made it work.I have few question he...I have finally made it work.I have few question here. <br />1) Is it possible to change address of slave. What is no i can changed it to, where to change it.<br />2)How to assign value in word format in your code.<br />3) i have connected an potentiometer output to A0 port even through it is not varying i found values get updated in modbus master.<br /><br />My code:<br /><br />#define ID 3<br /><br />Modbus slave(ID, 0, 0);<br />boolean led;<br />int8_t state = 0;<br />unsigned long tempus;<br />// data array for modbus network sharing<br />uint16_t au16data[9];<br /><br />float latitude=13.08;<br />void setup() {<br /> // define i/o<br /> pinMode(2, INPUT);<br /> pinMode(3, INPUT);<br /> pinMode(4, INPUT);<br /> pinMode(5, INPUT);<br /> pinMode(6, OUTPUT);<br /> pinMode(7, OUTPUT);<br /> pinMode(8, OUTPUT);<br /> pinMode(9, OUTPUT);<br /> pinMode(10, OUTPUT);<br /> pinMode(11, OUTPUT);<br /> pinMode(13, OUTPUT);<br /><br /> digitalWrite(6, LOW );<br /> digitalWrite(7, LOW );<br /> digitalWrite(8, LOW );<br /> digitalWrite(9, LOW );<br /> digitalWrite(13, HIGH );<br /> <br /><br /> // start communication<br /> slave.begin( 9600 );<br /> tempus = millis() + 100;<br /> digitalWrite(13, HIGH );<br />}<br /><br /><br />void loop() {<br /> // poll messages<br /> // blink led pin on each valid message<br /> state = slave.poll( au16data, 9 );<br /> if (state > 4) {<br /> tempus = millis() + 50;<br /> digitalWrite(13, HIGH);<br /> }<br /> if (millis() > tempus) digitalWrite(13, LOW );<br /><br /> <br /> // read analog inputs<br /> au16data[0] = analogRead(3);<br /> au16data[1]=latitude;<br /><br /> // diagnose communication<br /> au16data[6] = slave.getInCnt();<br /> au16data[7] = slave.getOutCnt();<br /> au16data[8] = slave.getErrCnt();<br />} <br /> <br />ajithttps://www.blogger.com/profile/05141435743150981272noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-63674063655445843822014-04-08T12:40:25.592+02:002014-04-08T12:40:25.592+02:00https://www.sparkfun.com/products/11959
i have pur...https://www.sparkfun.com/products/11959<br />i have purchased the above product now. I have succefully uploaded the code . I am getting slave through expection Invalid CRC implimentedajithttps://www.blogger.com/profile/05141435743150981272noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-53730136529127775282014-04-08T07:28:50.111+02:002014-04-08T07:28:50.111+02:00If I do correctly understand you, you only need to...If I do correctly understand you, you only need to refer to address 5 in irder to read Latitude degrees or addresses from 5 to 6 to read the full Latitude.subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.comtag:blogger.com,1999:blog-677700539096386766.post-61605332299689041922014-04-07T22:12:20.849+02:002014-04-07T22:12:20.849+02:00Dear Ajit,
1) The problem with the time is quite c...Dear Ajit,<br />1) The problem with the time is quite common and you could split it into several words, such as:<br />word 1.L = day in BCD (01..31)<br />word 1.H = month in BCD (01..12)<br />word 2 = year in BCD (0001..9999)<br />word 3.L = minute in BCD (00..59)<br />word 3.H = hour in BCD (00..23)<br />word 4.H = seconds in BCD (00..59)<br /><br />2) Something similar for the latitude, but consider to write it as degrees, minutes and seconds:<br /><br />word 5 = latitude in degrees<br />word 6.H = minutes (00..59)<br />word 6.L = seconds (00..59)<br /><br />Your 13.08ยบ becomes 13 degrees plus 3 minutes and 0 seconds. I guess that this may be enough accurate for most applications. These conversions are quite simple, isn't it?<br /><br />3) These are different errors:<br /><br />- INVALID CRC means that the slave has generated a wrong CRC field. The only way to check it properly consists on getting the outcoming message from your Modbus Master and the answer coming from the Arduino.<br /><br />- I/O ERROR DID NOT RECEIVE DATA FROM SLAVE means that the Modbus Master has sent a query message and there has been no answer from the Arduino. It is difficult to guess why it has happened so.<br /><br />I did several tests:<br />- between two Arduinos with RS-485, where one is the Master and the second one is an Slave. They were linked for more than 2 hours without any error.<br />- between an Arduino Duemilianove as Modbus Slave and QModbus (as Master).<br />- between an Arduino Mini-pro and an ABB AC500 PLC.<br /><br />Regards,subyhttps://www.blogger.com/profile/16564867150960697026noreply@blogger.com