📜 ⬆️ ⬇️

FLProg - New implementation of Modbus RTU exchange



Earlier, at Habré, I talked about the implementation of the support for the Modbus protocol in the FLProg program. Unfortunately, as the practice of its use has shown, the implementation was not very successful. If Slave worked even more or less confidently, then the master was very unstable. In addition, the assignment of register addresses was possible only as a continuous array, and there was no division into memory areas. The master in that implementation could only apply to Holding Registers of slaves, which greatly limited the possibilities of its use. For a long time, I was looking for a normally implemented Modbus RTU library for Arduino, but searches did not lead to success. Therefore, it was decided to write the implementation of the exchange on Modbus RTU independently. And in the recently released version of the FLProg program with the number 1.12, this is done. What changed:
  1. The implementation of Modbus RTU is fully compatible with industry standard.
  2. Implemented four variable tables - Coils, Discrete Inputs, Input Registers, Holding Registers. For each variable, you can set any address (not necessarily sequentially).
  3. Implemented the ability to set the slave address, port speed and disable / enable polling of a particular slave by the master programmatically with storing this data in the EEProm.
  4. The possibility of simultaneous work of the master and the slave on one controller (on different ports) is implemented.
  5. Implemented the ability to use SoftwareSerial as a port
  6. Thanks to the dynamically generated code, simultaneous operation of the master and the slave is possible even on the Pro-Mini board.
  7. Implemented direct compatibility with older versions - previously created projects will work on the new version without rework.


In this lesson I decided to do what may be really useful. Having run through the online stores, I found the victim - we will duplicate the sensors and actuators on the RS-485 bus sold in the Wiren Board store . Why they? Yes, I just killed their prices. Especially outraged by the price of sensors DS18B20 . On the site, they honestly talk about their Chinese origin, and at the same time they request 400 rubles. Although in China, even at retail, their price is 102 rubles . And when wholesale is certainly much cheaper. Interesting - the margin of more than 300% - this is a trip to the mail?

To begin with, we will try to repeat “ Modbus-RTU Relay Module Module (WB-MRM2-mini) ” - the price is 2000 rubles.
')


Description of the module .



Components to create a module:
  1. Arduino Nano - 145 rubles
  2. Two-channel relay module - 114 rubles
  3. RS-485 module - 48 rubles

Total - 307 rubles. As it is cheaper than two thousand rubles. I think out of distribution at wholesale prices on their board, the cost will be even less.
Schematic diagram:



Archive with project FLProg and sketch

We work further:

Sensor WB-MS-THLS - Measures humidity, temperature, light, sound pressure . - 4900 rubles.



Description not found. We will invent ourselves.



Components to create a module:
  1. Arduino Nano - 145 rubles.
  2. RS-485 module - 48 rubles
  3. Sensor DHT-22 -202 rubles
  4. Light sensor - 66 rubles
  5. Sound sensor - 66 rubles


Total: 527 rubles. Feel the difference? Dear body is really very good, but beautiful.
Schematic diagram:



Archive with project FLProg and sketch

Well, now, finally, we will assemble a device that will collect data and manage these blocks. To display information and control, we will use a smartphone on Android. The connection will be made via Bluetooth, and the software will be the HMI-KaScada software . On the Arduino board, Modbus Master (for collecting information from the blocks) and Modbus Slave (for working with the HMI-KaScada program) will be organized simultaneously.



Components to create a module:
  1. Arduino Nano - 145 rubles.
  2. RS-485 module - 48 rubles
  3. Module HC-05 -234 rubles.


Total: 427 rubles.
Schematic diagram:



Archive with project FLProg and sketch

What to say in the end? If you have direct hands, then a lot of things that are sold for big money can be done on your own and much cheaper.

Source: https://habr.com/ru/post/394613/


All Articles