MODBUS Protocol Help

Hello everyone! I am trying to communicate with a TUF-2000M ultrasonic flow meter using MODBUS RTU (RS485). I noticed that there is the a MODBUS-Master library available in Web IDE but I am having issues understanding the syntax.

TUF-2000M Manual:
Page 39 in the manual begins the section discussing the MODBUS communication protocol and configuration for the meter.

Here’s a diagram of what I am trying to do:

Do you any of you have suggestions or advice of where I should begin and any resources that might aid me? Thanks in advance!

Hi, here is the example code how to get flow rate:

// This #include statement was automatically added by the Particle IDE.
#include <ModbusMaster.h>

#define FLOW_DATA_SIZE 2

// instantiate ModbusMaster object as slave ID 1
ModbusMaster node(1);

void setup() {
	// initialize Modbus communication baud rate
	node.enableTXpin(D7); //D7 is the pin used to control the TX enable pin of RS485 driver
	//node.enableDebug();  //Print TX and RX frames out on Serial. Beware, enabling this messes up the timings for RS485 Transactions, causing them to fail.
	while(!Serial.available()) Particle.process();
	Serial.println("Starting Modbus Transaction:");

void readFlow() {
  uint8_t j, result;
  uint16_t buf[FLOW_DATA_SIZE];
  uint16_t temp;
  float flow;
  Serial.println("Reading registers");
  result = node.readHoldingRegisters(FLOW_REGISTER, FLOW_DATA_SIZE);
  if (result == node.ku8MBSuccess)
    Serial.println("Success! Processing...");
    for (j = 0; j < FLOW_DATA_SIZE; j++)
      buf[j] = node.getResponseBuffer(j);
      Serial.print(" ");
    Serial.println("<- done");
    // swap bytes because the data comes in Big Endian!
    temp = buf[1];
    // hand-assemble a single-precision float from the bytestream
    memcpy(&flow, &buf, sizeof(float));
    Serial.print("Flow is ");
    Serial.println(flow, 6);
  else {
    Serial.print("Failure. Code: ");

void loop() {

here is an original website from where I get the example which is useful:

Base on this example you can obtain the rest of your needs
and here is complete code that you can use for tests.
Is compiling fine under Boron V2.0.1 but not tested:

Hope this will help

1 Like

Firstly, thank you for your time. It is greatly appreciated.

I flashed the code correctly. I enabled “node.enableDebug();” and am now receiving the following serial message:

Reading registers
TX: 1 3 0 1 0 2 95 CB  
Failure. Code: 226

I wonder if I need to change which pins the ModbusMaster library is using for TX/RX. I have the converter connected to the Boron’s TX/RX pins, as shown below:

I see that D7 is set as a default pin for enabling the TX. But, I am not entirely certain what that means.


@dreamER, do you have any suggestions?


Firstly don’t enable this line as is messing with timing as described

2nd you have to swap your wires I mean TX ( Boron red wire) has to be connected to RX on your RS485 converter and RX ( Boron green wire ) has to be connected to TX on the converter make sure that GND on Boron and converter are also connected and then try again :wink: also setup your flow meter to Modbus RTU
Also make sure that flow meter communication is setup for 9600 baud
The error code that you are receiving is request timeout
And don’t worry about D7 is used with some converters for TX control

1 Like

You my friend… are freaking awesome!!! Thank you so much!

Another question for you: do you think it is possible to turn the flow meter on and off using the Boron? I am trying to figure out a way to conserve power.

Would anyone be willing to share their experience with the TUF-2000?
I’ve been looking for a cheap Ultrasonic Flow Meter, but this one seems very inexpensive.
Are the results stable in the long term ?

Thanks in advance !

@Michael-Maust , what’s the power source and Voltage ? That will help determine the best switching device with the lowest average consumption.

We are currently using an Xtreme Universal Soundbar Power Adapter that can be regulated from 12v-24v. The manual suggests a voltages between 8-24v for optimal performance. We currently researching into buying a battery for sake of portability.

Yes it’s possible :slight_smile: depends on your needs.
from meter manual:


not to much just 50mA :slight_smile:

Personal recommendations:

  1. SSR/optocoupler to turn on/of meter

optionally relay board

  1. CUI PDQE15-Q48-S5-D to power the Boron and have some current juice still available @5V

  1. some of this kind of battery to power meter directly and to CUI input

  1. solar panel some kind like this:

hope this help :stuck_out_tongue_winking_eye:

1 Like

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