Design a simple modbus ascii/rtu convertor using arduino uno board

Hi,I am a beginner in arduino and English is not my native language.Anyway i hope my description would not be confusing,here it goes.

I am working with an assignment which requires me to send message in ascii format from PC to UNO board,and convert the message into RTU format and finally return it to PC.So I can see the corresponding RTU message in serial monitor.This assignment aims to design a simple modbus protocol convertor that could transfer the ascii to rtu.I have no experience with modbus protocal before and the only required hardware in this assignment is an arduino UNO board.Is there anybody know how to deal with it?It would be helpful if some code could be demonstrated.

Thanks in advance for any help!

What software on the PC are you using to generate Modbus ASCII messages as a master and receive Modbus RTU messages as a slave?

Conceptually you need the Arduino to be a Modbus ASCII slave listening on one serial port and a Modbus RTU Master transmitting on another serial port.

It would also help to have a third serial port for debug messages.

Hi mikb55,thanks for your reply.The software I use is Arduino IDE.In this assignment my PC is master and the UNO Board is slave.My idea is that I type the message in the textbox of serial monitor of Arduino IDE and send it to arduino board.The uno board would read it in ascii format and return the corresponding RTU message to serial monitor.I find a similar code sketch to reach this goal,but there are still some places need to be modified.Here is my code,
String comdata = "";

void setup()

void loop()
while (Serial.available() > 0)
comdata += char(;

if (comdata.length() > 0)
comdata = "";
The ideal case is that I input the message in ascii format(like "hello"),and the UNO board returns the corresponding RTU message(like"01101000 01100101 01101100 01101100 01101111",since RTU data is binary).Currently I could only return the message in the same format(like the input is"hello",and the output is also "hello").Is there any advice for further improvements?Thanks in advance!

The Arduino serial monitor doesn’t understand binary data. You need RTU slave software running on the PC to decode the binary data stream.

Modbus is more than a data format. It is a bidirectional communications protocol.
Perhaps you should talk to your supervisor and ask them to suggest books or web pages for background reading.

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