modbus master/slave with arduino and MAX485 / RS485 TTL?

hello!
i am looking for some help with a project,
i need to control a sensor that has a modbus communication, from the datasheet it says:

*MODBUS serial communication via serial interfaces such
as RS232, RS485
*MODBUS ASCII codes the data using ASC-II character
set in the form of legible character chains

i need to send some parametters to the sensor in codes like:"000602000001F7"
and request the measured data with codes like:"0003018000106c"

and after the measure ( it measure 1500 points)
I want to recover the data measured.

which is the easiest way to do this? from what i read one option would be something like this Module 5V MAX485 / RS485 TTL à carte de développement RS-485 MCU, no?(https://www.amazon.fr/dp/B06XHHWLMW/ref=cm_sw_em_r_mt_dp_U_-rhkDbTX5G2M1)
the sensor has a female connection usb mini. (normally I connect the sensor to the computer with a Male/Male usb mini/usb cable)

the idea is to be able to open an open/close electrovalve and when it goes from close to open at the same time the sensor begins the measurement.

would apretiate any help, and any link to any similar project. if need it i can search for more information in the data sheet of the sensor.
if there is any other and easier way i could buy a shield or something else.
thanks,
best regards, franco

I'm not aware of any Modbus ASCII library for the Arduino.

the sensor has a female connection usb mini. (normally I connect the sensor to the computer with a Male/Male usb mini/usb cable)

For the Modbus connection (RS485) there must be another connector.

i need to control a sensor that has a modbus communication, from the datasheet it says:

Why don't you post that datasheet (or a link to it)?

pylon:
I'm not aware of any Modbus ASCII library for the Arduino.

well, not necessarily a ascii library but anyway to be able to recover the information in the computer to be able to exploit it.

pylon:
For the Modbus connection (RS485) there must be another connector.

I didn't understand what you mean, I have communicated with it connecting it directly to the computer and using the software of the sensor (the thing is I need to be able to do the measure at the same time that I open the valve so I cant use their software. and from Wireshark (and the datasheet is a Modbus communication). I have no problem in buying another type of connector, but physically the sensor has a female mini USB

pylon:
Why don't you post that datasheet (or a link to it)?

I don't know if it would be legal to post it as it was given by the fabricant of it, the thing is they don't support any outside control for the sensor, so it is problematic for my application and I am looking a way to be able to do it myself.
is not the project itself (the project is doing the experiences where I need to control the valve and the sensor at the same time) but I need to unlock this to be able to do them....
*edit, from what i look it in internet i could find it online, so here it is https://www.cypress.com/file/364121/download

only detail, from the datasheet maybe they didnt change it in the hardware section but the one i have does not have a 10way flex connector it has the mini usb (i would say that the the converter to USB interface named in section 7.1 is inside the sensor and can not acces....) either way, from the exterior it has a female usb mini

anyway if there is anything i can help to make it easier for you guys to help me with this i would gladdly do.

thanks :slight_smile:

well, not necessarily a ascii library but anyway to be able to recover the information in the computer to be able to exploit it.

You didn't understand me. There are three main Modbus types: Modbus RTU (kind of the original), Modbus TCP (over IP networks, gaining more attention) and Modbus ASCII which works over serial connections too but does only send printable characters in the ASCII range. The first two types are quite common and there are libraries available for the Arduino world. But as I wrote above, I'm not aware of any Arduino library that would support the Modbus ASCII type of the protocol.

I didn't understand what you mean, I have communicated with it connecting it directly to the computer and using the software of the sensor (the thing is I need to be able to do the measure at the same time that I open the valve so I cant use their software. and from Wireshark (and the datasheet is a Modbus communication). I have no problem in buying another type of connector, but physically the sensor has a female mini USB

It's possible that they use Modbus ASCII over a serial emulation over USB although this combination makes little sense. Post a link to the datasheet of this device!

I don't know if it would be legal to post it as it was given by the fabricant of it,

Did you sign a non-disclosure agreement? Documentation for hardware is usually not confidential.

*edit, from what i look it in internet i could find it online, so here it is https://www.cypress.com/file/364121/download

That device doesn't have a USB connector but a 10pin connector for a flexible print type cable.
On that interface you have a simple TTL-level serial interface (UART-style).

only detail, from the datasheet maybe they didnt change it in the hardware section but the one i have does not have a 10way flex connector it has the mini usb (i would say that the the converter to USB interface named in section 7.1 is inside the sensor and can not acces....) either way, from the exterior it has a female usb mini

In that case you may better use a Raspberry Pi (or a similar Linux based board) for the job. It will connect easily to the USB and have drivers for virtually all USB2serial chips out there. You still have the problem that the only library for Modbus I know doesn't support the Modbus ASCII variant, so the implementation would need more time.

pylon:
You didn't understand me. There are three main Modbus types: Modbus RTU (kind of the original), Modbus TCP (over IP networks, gaining more attention) and Modbus ASCII which works over serial connections too but does only send printable characters in the ASCII range. The first two types are quite common and there are libraries available for the Arduino world. But as I wrote above, I'm not aware of any Arduino library that would support the Modbus ASCII type of the protocol.

Thanks! it is supper hard to understand everything at the same time, from what i read from the datasheet, it is modbus ASCII. thanks for the clarification.

pylon:
It's possible that they use Modbus ASCII over a serial emulation over USB although this combination makes little sense. Post a link to the datasheet of this device!

Did you sign a non-disclosure agreement? Documentation for hardware is usually not confidential.

That device doesn't have a USB connector but a 10pin connector for a flexible print type cable.
On that interface you have a simple TTL-level serial interface (UART-style).

the one I post it is the datasheet that they gave me (and they told me that there were not any new revision...)

pylon:
In that case you may better use a Raspberry Pi (or a similar Linux based board) for the job. It will connect easily to the USB and have drivers for virtually all USB2serial chips out there. You still have the problem that the only library for Modbus I know doesn't support the Modbus ASCII variant, so the implementation would need more time.

so maybe the best would be to go with a python microcontroler? (that has the pymodbus library that supports modbus ascii)? no?
for arduino i found this Arduino/MODBUS/ASCII/libraries at master · pepsilla/Arduino · GitHub not sure how difficult would be to implement...
thanks for the help :slight_smile:

There is a modbus library for the arduino DUE:

https://forum.arduino.cc/index.php?PHPSESSID=g6v5o996e1pvre53n9fdofipe5&topic=580961.0

so maybe the best would be to go with a python microcontroler? (that has the pymodbus library that supports modbus ascii)? no?

That would be an option, pymodbus claims to support Modbus ASCII.

for arduino i found this Arduino/MODBUS/ASCII/libraries at master · pepsilla/Arduino · GitHub not sure how difficult would be to implement...

I wasn't aware of that library, you might give it a try. But to use it with the Due you have to find out which USB2serial chip your version of the sensor uses. If you don't find a driver for that chip on the Due it still might be better to use a Raspberry Pi or similar.