I am trying to connect JXCT RS485 Soil PH sensor to Arduino Due using RS485 to TTL Converter (Two Way Converter) Transceiver XY-485 and I am stuck I assume that I am sending the inquiry frame as the TX led is blinking but I am not receiving anything.
#define SENSOR_ADDRESS 0x01
#define BAUD_RATE 9600
#define RX_PIN 19 // RX1 on Arduino DUE
#define TX_PIN 18 // TX1 on Arduino DUE
byte sendData[] = {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0B};
byte receivedData[8]; // Buffer to store received data
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
// Start Modbus communication
Serial1.begin(BAUD_RATE); // Serial1 uses RX1 and TX1 pins
}
void loop() {
// Send the inquiry frame
Serial1.write(sendData, sizeof(sendData));
delay(500); // Wait for the sensor to process and respond
// Read the response
int i = 0;
while (Serial1.available()) {
receivedData[i] = Serial1.read();
i++;
delay(10); // Give some time for the next byte to arrive
}
if (i > 4) { // Check if enough data is received
int pHData = receivedData[4];
float pHValue = pHData * 0.01;
Serial.print("pH Value: ");
Serial.println(pHValue, 2);
} else {
Serial.println("Failed to read from sensor!");
}
delay(1000); // Wait for 1 second before the next reading
}
The connections:
Common ground between the sensor and the RS485 wing in the module
Blue wire of the sensor connected to B- in RS485 wing in the module
Yellow wire of the sensor connected to A+ in RS485 wing in the module
VCC in TTL wing of the module connected to 5V of the DUE
TXD to RX1, RXD to TX1
GND of the module to GND of the DUE
I am trying to connect JXCT RS485 Soil PH sensor to Arduino Due using RS485 to TTL Converter (Two Way Converter) Transceiver XY-485 and I am stuck I assume that I am sending the inquiry frame as the TX led is blinking but I am not receiving anything.
#define SENSOR_ADDRESS 0x01
#define BAUD_RATE 9600
#define RX_PIN 19 // RX1 on Arduino DUE
#define TX_PIN 18 // TX1 on Arduino DUE
byte sendData[] = {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0B};
byte receivedData[8]; // Buffer to store received data
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
// Start Modbus communication
Serial1.begin(BAUD_RATE); // Serial1 uses RX1 and TX1 pins
}
void loop() {
// Send the inquiry frame
Serial1.write(sendData, sizeof(sendData));
delay(500); // Wait for the sensor to process and respond
// Read the response
int i = 0;
while (Serial1.available()) {
receivedData[i] = Serial1.read();
i++;
delay(10); // Give some time for the next byte to arrive
}
if (i > 4) { // Check if enough data is received
int pHData = receivedData[4];
float pHValue = pHData * 0.01;
Serial.print("pH Value: ");
Serial.println(pHValue, 2);
} else {
Serial.println("Failed to read from sensor!");
}
delay(1000); // Wait for 1 second before the next reading
}
The connections:
Common ground between the sensor and the RS485 wing in the module
Blue wire of the sensor connected to B- in RS485 wing in the module
Yellow wire of the sensor connected to A+ in RS485 wing in the module
VCC in TTL wing of the module connected to 5V of the DUE
TXD to RX1, RXD to TX1
GND of the module to GND of the DUE
Your two topics on the same or similar subject have been merged.
Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum. It will help you get the best out of the forum in the future.
Ok, so I assume that if you have tried it with a PC application, that you have a USB-RS485 dongle?
If you have, then you can use that same dongle to listen in to the messages hopefully being sent by your Arduino.
The first step is to determine if your Arduino is sending out the message correctly. Once that is established, you can then see if the sensor is responding to that message, and then try and read in that response.
You need to figure out where in the sequence the problem lies and the USB-RS485 dongle should be able to help you there.