Skip to content

Added Example ModbusRTUTemperatureSensor #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 21, 2018

Conversation

Rocketct
Copy link
Contributor

@Rocketct Rocketct commented Aug 7, 2018

Added ModbusRTUTemperatureSensor example to the library ArduinoModbus

Added ModbusRTUTemperatureSensor example to the library ArduinoModbus
- Z \/\/ Y set to OFF

created 16 July 2018
by Sandeep Mistry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I made this sketch :)

Please update the date and name accordingly.

/*
Modbus RTU Temeperature Sensor

This sketch show how to use the modbus library, in in order to sent a request to a slave RTU sensor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This sketch shows you how to interact with a Modbus RTU temperature and humidity sensor. It reads the temperature and humidity values every 5 seconds and outputs them to the serial monitor.


Circuit:
- MKR board
- TModbus RS485 Temperature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is extra "T" at the start, we should add the product URL to I think

- Z connected to B/Z of the Modbus RTU sensor
- Jumper positions
- FULL set to OFF
- Z \/\/ Y set to OFF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the termination should be set to ON

- Jumper positions
- FULL set to OFF
- Z \/\/ Y set to OFF

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't mention the VCC connection for the sensor.


#include <ArduinoModbus.h>

float temperature, humidity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put the variables on one line each please.

}

void loop() {
//send a reading request to the RTU slave with id=1, type=HOLDING_REGISTERS address=0, number of values to read, nb=2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to:

// send a Holding registers read request to (slave) id 1, for 2 registers

also make sure if a comment is too long to split it to multiple lines.

Serial.println(ModbusRTUClient.lastError());
} else {
//if the request goes fine read the value with the read() function
short rawtemperature = ModbusRTUClient.read();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need an explanation of what the sensor returns and why we need to divide by 10.0.

added some comments to the ModbusRTUTemperatureSensor example
@Rocketct Rocketct force-pushed the master branch 2 times, most recently from a5b51ad to aa7f841 Compare August 8, 2018 14:38
Added a comment on the example ModbusRTUTemperatureSensor.ino
@Rocketct Rocketct force-pushed the master branch 2 times, most recently from a5b51ad to 9a9f276 Compare August 10, 2018 14:02
Serial.println(ModbusRTUClient.lastError());
} else {

// If the request goes fine, the sensor sent the readings as bytes packet,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

holding registers are actually 16-bits in size.

} else {

// If the request goes fine, the sensor sent the readings as bytes packet,
// through the read() function is possible read the measurments.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read the raw values


// If the request goes fine, the sensor sent the readings as bytes packet,
// through the read() function is possible read the measurments.
// the readings is parsed as a short integer from the packets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing is parsed

short rawtemperature = ModbusRTUClient.read();
short rawhumidity = ModbusRTUClient.read();

// Is required divide by 10.0 the value readed, because the sensor sent the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readed -> read, sent -> sends

short rawhumidity = ModbusRTUClient.read();

// Is required divide by 10.0 the value readed, because the sensor sent the
// readings as an integer obtained multipling the float value readed by 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a divide not multiply :)

the raw values need to be divided by 10 to get the temperature in Celsius and the humidity reading as a percentage.

Changed comment in ModbusRTUTemperatureSensor example.
Copy link
Contributor

@sandeepmistry sandeepmistry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, i made some minor suggestions we should consider.

- MKR board
- Winners® Modbus RS485 Temperature and Humidity:
https://www.banggood.com/Modbus-RS485-Temperature-and-Humidity-Transmitter-Sensor-High-Precision-Monitoring-p-1159961.html?cur_warehouse=CN
- External power Supply
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What voltage and current is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rocketct from the product page "Working voltage: 9-36V"

Serial.println(ModbusRTUClient.lastError());
} else {

// If the request goes fine, the sensor sends the readings, this are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this -> that

} else {

// If the request goes fine, the sensor sends the readings, this are
// stored in the holding register and through the read() function is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is => it is

short rawtemperature = ModbusRTUClient.read();
short rawhumidity = ModbusRTUClient.read();

// Is required divide by 10.0 the raw value to get the temperature in Celsius
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the order here:

To get the temperature in Celsius and the humidity reading as a percentage, divide the raw value by 10.0.

Changed comments in the example ModbusRTUTemperatureSensor.ino
Added a comment on the example ModbusRTUTemperatureSensor.ino
- Power supply V+ connected to V+ sensor
- The Working voltage range of the sensor, from product page, is 9-36 V
- Set the Power supply's voltage to a value between 9 - 36 V
- Set the Power supply's current limit to 1 A
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doesn't the current need to be limited? Could someone use a fixed 9v 5A supply?

@sandeepmistry sandeepmistry merged commit ce49c07 into arduino-libraries:master Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants