rjd1234 (Customer) asked a question.

Communication between Click Plus PLC and Arduino Nano / Modbus RS-485

I'm trying to use an Arduino Nano to collect GPS speed data and then read that data on the Click PLC.

 

Equipment:

GPS module: GT-U7

Arduino Nano with a screw terminal breakout board

RS-485 module (MAX485 TTL to RS485)

Click Plus (C2-03CPU)

 

Arduino Nano Wiring:

Pins 10/11 --> GPS Module

Pin 7 --> DE and RE of MAX485 Module

Pin 8 --> RO of MAX485 Module

Pin 9 --> DI of MAX485 Module

 

Click Plus Wiring:

Port 3 (RS-485) + --> A of MAX485 Module

Port 3 (RS-485) - --> B of MAX485 Module

 

Using the Arduino Serial Monitor I am able to generate decent speed data. The issue is getting that data into the Click.

 

I have followed the example by Garry at ACC Automation (https://accautomation.ca/click-to-click-plc-communication-remote-io/) The sending instructions have the success flag staying on, but the receive instructions flash between sending and error.

 

In this article (https://circuitdigest.com/microcontroller-projects/rs485-modbus-serial-communication-using-arduino-uno-as-slave) the author uses the same MAX485 module to communicate using a PC as the master and an Arduino Uno as the slave.

 

I'm hoping someone has experience with these type of communications and will be able tell what I am doing wrong.

 

Thanks,

Rick


  • ADC TechnologyGroup_01 (AutomationDirect)

    What is your hardware setup for the CLICK Ladder project that is attached? That example is for communicating between two CLICK PLCs. Is that what you are testing? Or are you testing that Ladder while connected to the Arduino?

     

    The CLICK Project is setup for Modbus addresses which do not exist in your Arduino INO project. You will need to use the "modbus.configure()" functions to define the addresses which you want to make available to the modbus connection.

     

    Can you start with just the ModbusRTUSlaveExample and a CLICK project Reading 400001. If this is successful then the hardware is proven and you can move onto how you want to layout your Modbus map.

    Expand Post
  • rjd1234 (Customer)

    OK... I was finally able to get these to communicate by abandoning the SoftwareSerial for the modbus and just using the TX and RX pins on the Nano. After debugging using QModBus software and the USB to RS485 converter, it was easy to connect to the Click PLC. Thank you for the direction... It got me looking in the right places.

     

    Here is the code I'm running now if anyone is interested:

     

    1. #include <TinyGPS++.h>
    2. #include <ModbusRtu.h>
    3. #include <SoftwareSerial.h>
    4.  
    5. // GPS pins
    6. #define GPS_RX_PIN 10
    7. #define GPS_TX_PIN 11
    8.  
    9. // RS485 pins
    10. #define TXEN 7
    11.  
    12. // Modbus setup
    13. uint16_t inputRegisters[16] = {0}; // Array for input registers
    14.  
    15. TinyGPSPlus gps; // Create an instance of the TinyGPS++ library
    16. SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN); // RX, TX
    17.  
    18. // Modbus slave setup
    19. Modbus slave(1, Serial, TXEN); // Modbus slave ID 1
    20.  
    21. void setup() {
    22. // Initialize serial communication for debugging
    23. Serial.begin(9600);
    24. Serial.println("GPS Data:");
    25.  
    26. // Initialize GPS serial communication
    27. gpsSerial.begin(9600);
    28.  
    29. // Initialize Modbus communication
    30. slave.start();
    31. }
    32.  
    33. void loop() {
    34. // Read GPS data
    35. while (gpsSerial.available()) {
    36. if (gps.encode(gpsSerial.read())) { // Feed each character to the TinyGPS++ library
    37. if (gps.speed.isValid()) { // Check if the GPS speed data is valid
    38. // Store speed in the first input register (scaled to integer)
    39. inputRegisters[0] = gps.speed.mph() * 100; // Scale by 100 to preserve decimal places
    40.  
    41. // Debugging output
    42. Serial.print("Speed: ");
    43. Serial.print(gps.speed.mph());
    44. Serial.println(" mph");
    45. }
    46. }
    47. }
    48.  
    49. // Poll the Modbus slave to handle requests
    50. slave.poll(inputRegisters, 16);
    51. }

     

    Expand Post