1

I have a Controllino Mega running a code that rotates a stepper one revolution CW, and one revoluction CCW. I need the program to run, just when a signal is received from an HMI that I have connected to the Controllino via ethernet. This is my first time using modbus. I have seen some examples using the modbus library, and I know I have to declare the variables in void setup, but don't know how many variables I need and if they have to be analog or digital. I don't know either how to read those variable within void loop.

    #include <SPI.h>
    #include <Controllino.h>
    #include <Ethernet.h>
    #include "MgsModbus.h"

    MgsModbus Mb;

    const int pul = 46;  // pin 46 to PUL -
    const int dir = 47;  // pin 47 to DIR -


    void setup () 
     {

        byte mac[] = {0x90, 0xA2, 0xDA, 0x0E, 0x94, 0xB5};
        IPAddress ip(10, 7, 4, 17);
        IPAddress gateway(10, 7, 4, 17);
        IPAddress subnet(255, 255, 255, 0);
        Ethernet.begin(mac, ip, gateway, subnet);
        delay(5000); // Time to open the terminal
        Serial.begin(9600);

        pinMode (pul, OUTPUT); 
        pinMode (dir, OUTPUT); 
     }

     void loop()
     {

 Mb.MbsRun();

   digitalWrite(dir, HIGH); 
  /*Turns the motor 400 steps*/
  for (int i = 0; i < 400; i++)
  {
    digitalWrite(pul, HIGH);
    delayMicroseconds(1000);
    digitalWrite(pul, LOW);
    delayMicroseconds(1000);
  }

 delay(1000); 

  digitalWrite(dir, LOW); 
/*Turns the motor 400 steps*/
  for (int i = 0; i < 400; i++)
  {
    digitalWrite(pul, HIGH);
    delayMicroseconds(1000);
    digitalWrite(pul, LOW);
    delayMicroseconds(1000);
  }

delay(1000);

 }
3
  • is Arduino slave or master? Commented May 2, 2020 at 8:27
  • Arduino is the slave. Commented May 2, 2020 at 12:03
  • then setup the registers. the library has examples Commented May 2, 2020 at 12:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.