5 Replies Latest reply on Aug 21, 2015 2:11 PM by DiegoV_Intel

    Anyone using ModBus RTU on Galileo gen 2?

    Aldo

      Hi everyone, I'm trying to communicate with some industrial hardware, on ModBusRTU, from my Intel Galileo Gen2 board.

      I use this board to convert UART to RS485 http://linksprite.com/wiki/index.php5?title=RS485_Shield_V2.1_for_Arduino and I can talk serially between Arduino (with SoftwareSerial on pin 2/3) and Galileo (with Serial1 on pin 0/1). So I know the RS485's link is working.

       

      With Arduino Uno I can talk with my devices using ModBusRTU, thanks to this library https://github.com/4-20ma/ModbusMaster

       

      On galileo gen2 I receveid this warning "WARNING: library ModbusMaster claims to run on [avr, sam] architecture(s) and may be incompatible with your current board which runs on [i586] architecture(s).

      " because of the different architecture.

       

       

      Now I'm trying to use the examples of this tutorial https://www.cooking-hacks.com/documentation/tutorials/modbus-module-shield-tutorial-for-arduino-raspberry-pi-intel-galileo/

      but I can't make it works for me. I receveid tons of compiling errors.

       

      Did someone has got ModBus working on Galileo Gen2?

       

      Thank you,

      Aldo

        • 1. Re: Anyone using ModBus RTU on Galileo gen 2?
          DiegoV_Intel

          Hello Aldo,

           

          The error message you got is because the library used is based on the AVR architecture which is the one used by the Arduino boards. Those libraries can’t be used with Galileo because Galileo has a different architecture. The library should be completely ported to work with the Galileo architecture. However, this is not a simple task and can take several weeks to be done.

           

          On the other hand, I've checked the last site you posted since it seems to be Galileo compatible. At the end, there is a code for Galileo (below the tag Arduino / Intel Galileo). After copying the libraries provided in the site I was able to compile the sample code, but I had an error the first time I tried to compile it. The error was about the SPI.h library location. I solved it by changing the line 30 in the file RS485.cpp. The modification I did was the following:

           

          //#include "../SPI/SPI.h"
          #include "SPI.h"
          

           

          Then I tried to compile the code again and it worked. I couldn't test it because I don't have the module you are using but you can give it a try. Did you get the same error?

           

          Regards,

          Diego.

          • 2. Re: Anyone using ModBus RTU on Galileo gen 2?
            Aldo

            Hi Diego, thanks for your answer.

             

            I tried your suggestion but the library doesn't work for me. It's telling me "Communication error". I suppose the reason is the different nature of the shields we're talking about, mine is a simple MAX485 and it converts data from TTL to RS485, the cooking hacks's one is a SPI module. The library ModBusMaster485 is basically the same library that I use with Arduino, with some modification to use the library RS485.h to talk with SPI to the shield. I tried to modify the library to hardcode the use of Serial1 (pin 0&1 of Galileo) but without success.

             

            I tried also to use this library https://www.npmjs.com/package/modbus but without success.

            I think I should use /dev/ttyS0 to use pin 0&1 to communicate with my RS485 shield and with my hardware, but it gives me always "Connection timeout".

             

            The only way I find is to use Arduino Uno as a interface between hardware and Galileo, but it isn't a real solution (but in the end it's working).

             

            Thank you,

            Aldo

            • 3. Re: Anyone using ModBus RTU on Galileo gen 2?
              DiegoV_Intel

              Hello Aldo,

               

              I've checked the library 4-20ma/ModbusMaster · GitHub and it looks like it is AVR and SAM compatible. Actually there is a message stating the following:

              "This library only supports boards with an AVR or SAM processor. Please open an issue at https://github.com/4-20ma/ModbusMaster/issues and indicate which processor/platform you're using."

               

              On the other hand, I did a little change to see if the library can compile for Galileo Gen2. It worked. The change I did was in the file ModbusMaster.cpp where the global variables are defined. The change is shown below:

               

              /* _____GLOBAL VARIABLES_____________________________________________________ */
              #if defined(ARDUINO_ARCH_AVR)
                HardwareSerial* MBSerial = &Serial; ///< Pointer to Serial class object
              #elif defined(ARDUINO_ARCH_SAM)
                UARTClass* MBSerial = &Serial; ///< Pointer to Serial class object
              #else
                // Lets suppose it's a GalileoGen2 board
                HardwareSerial* MBSerial = &Serial;
                //#error "This library only supports boards with an AVR or SAM processor. Please open an issue at https://github.com/4-20ma/ModbusMaster/issues and indicate which processor/platform you're using."
              #endif
              

               

              Then I opened the Basic example and it compiled successfully for Galileo Gen2. As I mentioned in my previous post, I don't have the shield to test if the library is actually working. You could try the modification I explained above, hopefully it works. If it doesn’t, I’d say it’s because of the architecture differences.

               

              Regards,

              Diego.

              • 4. Re: Anyone using ModBus RTU on Galileo gen 2?
                Aldo

                Hi Diego, I made the same modification but the sketch compiles but doesn't work. I think it could work 'cause the cooking hack's library is essentially the same with the use of another library to talk with the rs485 shield. Maybe it's just a problem with the line 8 of the code? I use the pointer to &Serial1, because it's the one linked to digital pin 0 and 1, is it right?

                 

                Thank you very much for your time and for your answer!

                Aldo

                • 5. Re: Anyone using ModBus RTU on Galileo gen 2?
                  DiegoV_Intel

                  Hello Aldo,

                   

                  Yes, Serial1 is the one linked to the pins 0 and 1. I've just realized that I wrote &Serial instead of &Serial1, thanks for notice it. On the other hand, I did the modification just to make sure the code can be compiled. It doesn't mean that the code is going to work, especially because the code was written for AVR/SAM architecture.

                   

                  Regards,

                  Diego.