-
Notifications
You must be signed in to change notification settings - Fork 129
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
Conversation
Added ModbusRTUTemperatureSensor example to the library ArduinoModbus
- Z \/\/ Y set to OFF | ||
|
||
created 16 July 2018 | ||
by Sandeep Mistry |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
a5b51ad
to
aa7f841
Compare
Added a comment on the example ModbusRTUTemperatureSensor.ino
a5b51ad
to
9a9f276
Compare
Serial.println(ModbusRTUClient.lastError()); | ||
} else { | ||
|
||
// If the request goes fine, the sensor sent the readings as bytes packet, |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
Added ModbusRTUTemperatureSensor example to the library ArduinoModbus