How to recibe data throught rs232 using Arduino uno with Modbus Serial protocol

greetings, I want to receive information by using Modbus Serial RTU protocol, i want to get the data from industrial sensors that cannot be simply connected to a computer but the device in charge of that sensors can speak Modbus protocol, so I want to receive that data from the sensors using a db9 rs232 adapter, that it will get for me that data, but i tested out, I still can not receive anything throw, I need to have that data from the sensors to the db9 adapter until it reaches the Arduino Uno and giving that information to the Serial Monitor, that way I can get the information by using a python program and then capture the information, I still studying the solutions but I don't know if anybody can help me.

1 Like

What sort of RS232 to TTL converter have you got between the Uno and the device outputting the data ?

Please post the sketch that you are using to test the interface

1 Like

While you are posting the schematic post links to the hardware items and your code, be sure to follow the forum guidelines.

are you sure with that?
For usual a sensor with Modbus RTU is using a RS485 bus, not a RS232 connection.

So I suspect you need to connect a RS485 adapter to your pc to be able to read a Modbus RTU sensor.

Please provide a link and/or a datasheet of your sensor.

i will have to ask for that becouse the sensores and the divice that manage all that are industrial , i was inform that it is able to transmit data throw modbus serial , specificly a db9 port , thats why i work in the assumption that i will use the rs232 adaptader

the adapter is a Serial Ttl to Rs232 Max3232:
Módulo Adaptador Serial Ttl A Rs232 Max3232, Arduino,pic | MercadoLibre

//this is the code i try to use for my arduino


#include <ModbusMaster.h>
#include <SoftwareSerial.h>
//Rx/Tx is hooked up to pins 5, 3
SoftwareSerial mySerial(5, 3); // RX, TX
ModbusMaster node;
void setup() {
  // Modbus communication runs at 9600 baudrate
  Serial.begin(9600);
  mySerial.begin(9600);
  // Modbus slave ID 1
  node.begin(1, mySerial);
}
void loop()
{
  uint8_t result;
  uint8_t j;
  uint16_t data[16];  
  // Read 16 registers starting at 0x3100, 05 quantities)
  result = node.readHoldingRegisters(0, 5);
  if (result == node.ku8MBSuccess)
   {
    Serial.print("ReadHoldingRegisters: ");
    Serial.println(node.getResponseBuffer(4));
    delay(1000);  
   }
  delay(1000);

}

a DB9 connector does not mean necessarily that it is RS232.
Get the datasheet of your sensor.

Regarding your schematic and your posted code:
if you want to use SoftSerial for Modbus, you should connect the right adapter to pins 5,3 and not 0,1 as in your schematic.


Moderator
Please don´t cross post threads!!
I have just closed spanish thread but rememeber that you will be banned next time.


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.