Display values from sensors connected via Modbus
Hello, I ask for your help in writing a sketch using your ModbusMaster library to display temperature and humidity values in the Serial port monitor. [Arduino IDE version: 1.8.8] [Board: Arduino Nano]
Scheme:
Module settings:

Module polling:

log_report 15:17:36-> 15:17 :: [ 01 04 00 00 00 08 F1 CC ]; [ 01 04 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 2C ]; [ 46 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 00 00 01 31 CA ]; [ 01 04 02 00 00 B9 30 ]; [ 47 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 01 00 01 60 0A ]; [ 01 04 02 00 00 B9 30 ]; [ 31 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 02 00 01 90 0A ]; [ 01 04 02 00 00 B9 30 ]; [ 47 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 03 00 01 C1 CA ]; [ 01 04 02 00 00 B9 30 ]; [ 32 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 04 00 01 70 0B ]; [ 01 04 02 00 00 B9 30 ]; [ 31 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 05 00 01 21 CB ]; [ 01 04 02 00 00 B9 30 ]; [ 47 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 06 00 01 D1 CB ]; [ 01 04 02 00 00 B9 30 ]; [ 47 ms]==>OK 15:17:36-> 15:17 :: [ 01 04 00 07 00 01 80 0B ]; [ 01 04 02 00 00 B9 30 ]; [ 31 ms]==>OK
I-7017, I-7018, I-7019, M-7017, M-7018, M-7019 User Manual Modbus Register Map
Sketch( https://pastebin.com/VZvcTkBW ):
1. #include <ModbusMaster.h>
2. #define MAX485_DE 3
3. #define MAX485_RE_NEG 2
4. ModbusMaster node;
5. void preTransmission()
6. {
7. digitalWrite(MAX485_RE_NEG, 1);
8. digitalWrite(MAX485_DE, 1);
9. }
10. void postTransmission()
11. {
12. digitalWrite(MAX485_RE_NEG, 0);
13. digitalWrite(MAX485_DE, 0);
14. }
15. void setup()
16. {
17. pinMode(MAX485_RE_NEG, OUTPUT);
18. pinMode(MAX485_DE, OUTPUT);
19. digitalWrite(MAX485_RE_NEG, 0);
20. digitalWrite(MAX485_DE, 0);
21. Serial.begin(19200);
22. node.begin(1, Serial);
23. node.preTransmission(preTransmission);
24. node.postTransmission(postTransmission);
25. }
26. bool state = true;
27. void loop()
28. {
29. uint8_t result;
30. uint16_t data[6];
31. result = node.readInputRegisters(0x40001, 8);
32. if (result == node.ku8MBSuccess)
33. {
34 //Here I need to display the values of 8 registers.
40. }
41. delay(1000);
42. }
How in line 34 to get and display the values of all 8 registers?
Looks like you are intending to start at decimal register 40001. But this line .....node.readInputRegisters(0x40001, 8); is looking for hex 40001. Which is Dec 262145!! Try removing the 0x.