I'm trying to use a Nano connected to a GPS module to send speed data to a Click PLC from Automation Direct (C2-03CPU).
I have the GPS Module connected to D10 and D11 and am able to view good data in the serial monitor.
After getting that to work, I turned my attention to getting communication between the Arduino and Click PLC. I couldn't read anything on the PLC so I decided to see what I can read using the computer first as the Master.
I have an Arduino Nano connected to a Max 485 module, which is connected to a Waveshare USB to RS-485 converter.
My connections are as follows:
RE / DE on the max 485 --> Pin 7 on the arduino
RO on the Max 485 --> Pin 9 on the arduino
DI on the Max 485 --> Pin 8 on the arduino
A on the Max 485 ---> A on the Waveshare USB to 485 converter
B on the Max 485 ---> B on the Waveshare USB to 485 converter
I loaded the following code and viewed it in Putty... and it successfully spit out "Hello From Arduino" every second. I'm hoping that means that my wiring is correct?
#include <SoftwareSerial.h>
#define MAX485_DE_RE 7
#define MAX485_RO 9
#define MAX485_DI 8
SoftwareSerial rs485Serial(MAX485_RO, MAX485_DI);
void setup() {
pinMode(MAX485_DE_RE, OUTPUT);
digitalWrite(MAX485_DE_RE, HIGH);
rs485Serial.begin(9600);
}
void loop() {
rs485Serial.println("Hello from Arduino!");
delay(1000);
}
So then I loaded the ModbusRtu library and tried running some of the examples with some modifications for my setup. Then I tried to use QModBus to communicate with the Nano, but I keep getting an error
Here is the latest version of the code that hasn't worked:
#include <ModbusRtu.h>
#include <SoftwareSerial.h>
// Define the pins used by the MAX485
#define MAX485_DE_RE_PIN 7 // Connected to RE / DE pins on the MAX485
#define MAX485_DI_PIN 8 // Connected to DI pin on the MAX485
#define MAX485_RO_PIN 9 // Connected to RO pin on the MAX485
// Create a SoftwareSerial object for communication with the MAX485
SoftwareSerial rs485Serial(MAX485_DI_PIN, MAX485_RO_PIN); // RX, TX
// Data array for Modbus network sharing
uint16_t au16data[16] = {
3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1
};
// Modbus object declaration
Modbus slave(1, rs485Serial, MAX485_DE_RE_PIN); // Slave ID 1, using SoftwareSerial and DE/RE control
void setup() {
// Initialize serial communication with baud rate 19200
Serial.begin(19200);
// Initialize SoftwareSerial for communication with the MAX485
rs485Serial.begin(9600);
// Setup the Modbus slave
slave.start();
}
void loop() {
// Poll the Modbus slave to handle incoming requests
slave.poll(au16data, 16);
}
I have double checked all the wiring... after spending a few days and fighting the urge to throw the computer against the wall, I am reaching out for help.
My goal is to transfer the speed value from the GPS module to the Click PLC.
Attached is my GPS sketch if someone is interested.
GPS_Testing.ino (1.4 KB)