Data acqusition from pyrometer using MAX485 and Arduino MEGA

Hello guys, I'm trying to collect temperature reading from a Pyrometer connected via RS232 to RS485 converter which in turn connected to MAX485 (This method is used to increase the number of the sensors in future). This MAX485 module is connected to MEGA. I have the sample code but I'm getting junk output. Thank you.


#define MAX485_DE_RE 2 
#define SENSOR_ADDRESS 1
#define TEMP_REGISTER 0x01 // from the protocol

ModbusMaster sensor;

void preTransmission() {
  digitalWrite(MAX485_DE_RE, HIGH); 
}

void postTransmission() {
  digitalWrite(MAX485_DE_RE, LOW); 
}

void setup() {
  Serial.begin(115200);  
  Serial1.begin(9600, SERIAL_8N1); 

  pinMode(MAX485_DE_RE, OUTPUT);
  digitalWrite(MAX485_DE_RE, LOW); 

  sensor.begin(SENSOR_ADDRESS, Serial1);
  sensor.preTransmission(preTransmission);
  sensor.postTransmission(postTransmission);
}

void loop() {
  uint8_t result;
  float temperature = 0.0;

  result = sensor.readHoldingRegisters(TEMP_REGISTER, 2); 
   
   if (result == sensor.ku8MBSuccess) {
    uint16_t rawData = sensor.getResponseBuffer(0);
    temperature = ((rawData * 256) + sensor.getResponseBuffer(1) - 1000) / 10.0;

    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" °C");
  } 
  else {
    Serial.println("Failed to read sensor data!");
  }

  delay(1000);
}

(I couldn't upload sensor protocol. Apparently new users cannot upload files!!)

Good. Go on and welcome to report the progress.

You seems .. surprised. Why don't you link to the protocol instead?

Interesting. Do you have a link to that product?

Does that convertor have the concept of addresses or some other way of determining what data to pass out of the RS232 side to the pyrometer?

It appears you are missing a lot of hardware. Post an annotated schematic showing exactly how YOU have wired this. Show all connections, power, ground, power sources etc. Post links to the technical information on the hardware items.

Heres the website link, where you can find the product details.

A brief read of that user manual suggests that the sensor (or one specific variant of the sensor) outputs TTL serial data - they call it serial digital - see page 10. Page 11 has note #3 which says:

inverted RS232, TTL, 9,6 kBaud

If that is correct, and it looks like it is based on other images in the document that show a USB (serial?) adapter with bare wires, then you will need a TTL-RS232 adapter board as well.

That will convert your TTL serial data into RS232 voltage levels which you can then connect to your RS232-RS485 adapter.

Going back to my previous question:

What product are you going to use for this conversion?

As I previously mentioned, does that RS232-RS485 converter understand the concept of some form of addressing so that individual converters respond to unique addresses.

I suspect the converter may simply convert between RS232 and RS485 signals. In which case how will you configure your setup so that only 1 sensor responds when you have several connected to the RS485 bus?

If you don't #include your modbus library, I doubt it compiles...

@wilson_kishore1 just a thought but does your sensory understand / support modbus Comms?

Here is the link for RS232 to RS485 converter,

TTL to RS233 works but I still don't know if the addressing of each sensor will work later.

Company said it supports RS485 but its optional. I thought my variant has RS232 communication thats why I used direct converter to RS485.

But as you have mentioned, I think I have to use TTL converter. I'll try that.

What about the code, Is it correct to use ModbusMaster?

I also want to directly connect the sensor to my laptop and try to get raw data from it.

The user manual suggested that it is TTL serial - see my post #7. That's why they mention a USB adapter that would take TTL serial and convert to a USB serial port so your PC can communicate with it.

If it is TTL serial, then you should be able to connect the sensor Tx and Rx wires directly to your Mega on, say, Serial1 and communicate with it.

No, it's not correct since your sensor doesn't support the Modbus protocol.

Page 46 of the user manual has this table:


It looks like you send a single byte to the sensor and it responds with 1 or 2 bytes depending on the command byte sent.

Looking at your overall goal of having several of these sensors in the future, it might be worth considering using some Arduino Pro Minis - 1 per sensor.

A possible scenario: your Mega serial port #1 would connect to one of the standard RS485 modules. That module would then connect to standard RS485 module connected to the hardware serial port of a Pro Mini. Your Pro Mini would then have use a software serial port implementation to connect direct to one sensor. Each sensor would need its own Pro Mini and RS485 module.

You could then query each sensor individually using any protocol you like, even Modbus. But, as what you are trying to do is so simple, you could simply send out an address byte from the Mega and each Pro Mini would check if that was its address and if its a match, simply respond with the latest temperature reading.

That's where the manufacturer wants to sell you a USB-Serial adapter.

In theory, you don't need that as your Mega could do the same job with a very simple sketch that simply copied any data received over its USB-Serial port to its Serial1 and similarly any data received on Serial1 is copied over to the USB-Serial port. Your PC would then interact with the sensor as if it were directly connected to the PC.

How did you test that?

Thank you for this information. So if I want to collect data from one sensor, I can directly connect it to the Rx and Tx of MEGA. I'll work on this on Monday. Do you have any suggestion for a piece of code or any references from this forum?
Could you also please explain a little bit more command signal and how to access the data for one sensor at the moment?

I haven't tested this, I'll buy this component after testing the current sensor and want to check if this is feasible for an industrial application.

I don't understand you claim it works but you have not tested it.
So exactly how do you know it works?

If the datasheet is correct in that the serial is TTL, then you can connect to either Serial1, Serial2 or Serial3 on your MEGA2560. I'm assuming that as you only refer to your board as "MEGA" that you have an Arduino MEGA2560 board with 4 serial ports?

If you were to connect to Serial1 (pins TX1 and RX1) and configure Serial1 for 9600 baud, the a simple piece of code like this should suffice:

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  char c;

  if (Serial.available()) {
    c = Serial.read();
    Serial1.print(c);
  }
  if (Serial1.available()) {
    c = Serial1.read();
    Serial.print(c);
  }
}

Are you referring to how you would go about addressing a single device on an RS485 bus?

Have a read of:

It's worth reading from the start to get an idea of what RS485 is. The sections that Nick titles Master and Slave show an example sketch of the master addressing a slave device and the slave device checking the address in the message.

Sorry for the miscommunication, it was a question that "Will TTL to RS232 conver ter works?". Currently I have a sensor->RS232 to RS485 converter->MAX485->Arduino MEGA.

Yes it's MEGA 2560 and I'll try this code and get back to on Monday. I will read that and see if I have any doubts. Thank you for your support.

Well I see no point in using RS485 since you can only connect ONE sensor to the Mega