Rusty_Gunn

Nano_Modbus_Pyranometer_Test

Sep 6th, 2026
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <ModbusMaster.h>
  3.  
  4. #define RX_PIN 2
  5. #define TX_PIN 3
  6.  
  7. #define SLAVE_ID 2
  8. #define BAUD_RATE 9600
  9.  
  10. SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
  11. ModbusMaster node;
  12.  
  13. void setup() {
  14. Serial.begin(9600);
  15. while (!Serial);
  16.  
  17. modbusSerial.begin(BAUD_RATE);
  18. node.begin(SLAVE_ID, modbusSerial);
  19.  
  20. Serial.println("--- Renke Live Radiation Monitor ---");
  21. }
  22.  
  23. void loop() {
  24. // Read 6 registers starting at 0x0000
  25. uint8_t result = node.readHoldingRegisters(0x0000, 6);
  26.  
  27. if (result == node.ku8MBSuccess) {
  28. Serial.print("Reg[0]="); Serial.print(node.getResponseBuffer(0));
  29. Serial.print(" | Reg[1]="); Serial.print(node.getResponseBuffer(1));
  30. Serial.print(" | Reg[2]="); Serial.print(node.getResponseBuffer(2));
  31. Serial.print(" | Reg[3]="); Serial.print(node.getResponseBuffer(3));
  32. Serial.print(" | Reg[4]="); Serial.print(node.getResponseBuffer(4));
  33. Serial.print(" | Reg[5]="); Serial.println(node.getResponseBuffer(5));
  34. } else {
  35. Serial.print("Read Failed. Error: 0x");
  36. Serial.println(result, HEX);
  37. }
  38.  
  39. delay(1000);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment