Announcement

Collapse
No announcement yet.

Click Modbus to Arduino

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Click Modbus to Arduino

    I have a customer trying to interface their Arduino to an Ethernet Click that I am programming. Using Modbus protocol. Does anyone have any experience, insight, references, etc. that might help?
    Thanks.!
    ADEN ENGINEERING
    Automation & Electronic Controls

    Design, Build, Repair, Training

  • #2
    Ive never done it, but I remember seeing other posts about a modbus library you can download and use in the Arduino. Beyond that IDK.

    Comment


    • #3
      Can I ask what the desired end result is? DAQ maybe?

      Comment


      • #4
        Like MikeN said, there is a library out there. I played with it years ago and got it to work, but never did much with it after proving the concept.
        If you have an urgent issue, please contact AutomationDirect's Technical Support team.

        AutomationDirect.com Technical Support: 1(800) 633-0405 or (770) 844-4200 Email Tech Support

        Comment


        • #5
          While I'm not at liberty to reveal too many details, a previous section of the machine is already using Arduino, and we are integrating that into the overall controls with the PLC.
          ADEN ENGINEERING
          Automation & Electronic Controls

          Design, Build, Repair, Training

          Comment


          • #6
            Here's some code for a direct logic PLC talking Modbus over ethernet to an Arduino. The code may take some tweaks to get working with Click and your specific Arduino setup, but it'll be a good starting place. You'll need the Arduino RS485 and Modbus libraries.

            Code:
            /*******************************************************************************************
            Note: Everything is an Octal value. You will be required to convert this to decimal
            
            V-Memory            Type: Holding Register    
            Modbus Address:     Convert to decimal
            
            Outputs(Y0)         Type: Coil    
            Starting Address:   2048
            Modbus Address:     Convert to decimal. Add the starting address range(see manual).
            
            Control Relays(C0)  Type: Coil
            Starting Address:   3072
            Modbus Address:     Convert to decimal. Add the starting address range(see manual).
            
            Inputs(X0)          Type: Input
            Starting Address:   2048
            Modbus Address:     Convert to decimal. Add the starting address range(see manual).
            
            
            By: Michael Scott
            
            *******************************************************************************************/
            
            #include <Ethernet.h>
            #include <ArduinoRS485.h>
            #include <ArduinoModbus.h>
            
            byte myMac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDD, 0xED};
            byte myIP[] = {192,168,0,177};
            
            byte modbusIP[] = {192,168,0,127}; // REPLACE WITH PLC IP ADDRESS
            
            EthernetClient client;
            ModbusTCPClient modbus(client);
            
            void setup() {
              Serial.begin(115200); // init serial
              while(!Serial){
                ;
              }
              Ethernet.init(5);          // MKR ETH Shield uses 5
              Ethernet.begin(myMac,myIP);    // init Ethernet Shield
            
              while(!modbus.begin(modbusIP)){  // try to connect
                ;
              }
              Serial.println("Modbus Connected");
            }
            
            int modbusAddress = 0;
            int getReading;
            
            void loop() {
            
              // Toggle Y15 ON and OFF ten times
            //  modbusAddress = 13 + 2048; // Octal value of 15 = 13. 2048 is the starting address
            //  for(int i = 0; i < 10; i++){
            //    modbus.coilWrite(modbusAddress, 1);
            //    delay(500);
            //    modbus.coilWrite(modbusAddress, 0);
            //    delay(500);  
            //  }
            
              // Read V-Memory V3100
              modbusAddress = 1600; // Octal value of 3100 = 1600
              getReading = modbus.holdingRegisterRead(modbusAddress);
              Serial.println(getReading);
              delay(1000);
            }
            Last edited by AdamC; 12-19-2019, 04:10 PM.

            Comment


            • #7
              Yeah, get their I/o Map and setup the read blocks in the Click.

              Comment

              Working...
              X