Rusty_Gunn

Nano_Modbus_Pyranometer_ID

Sep 6th, 2026
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <ModbusMaster.h>
  3.  
  4. // Pin definitions (RX = D2 to RO, TX = D3 to DI)
  5. #define RX_PIN 2
  6. #define TX_PIN 3
  7.  
  8. // Communication settings
  9. #define CURRENT_SLAVE_ID 1 // The address the sensor currently responds to
  10. #define NEW_SLAVE_ID 2 // The new address you want to assign (1 - 247)
  11. #define BUS_BAUD_RATE 4800 // Current bus baud rate (4800 or 9600)
  12.  
  13. // Renke EEPROM Address Register
  14. #define RENKE_REG_ADDR 0x07D0
  15.  
  16. SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
  17. ModbusMaster node;
  18.  
  19. void setup() {
  20. Serial.begin(9600);
  21. while (!Serial);
  22. delay(500);
  23.  
  24. Serial.println("--- Renke Slave ID Configurator ---");
  25.  
  26. modbusSerial.begin(BUS_BAUD_RATE);
  27. node.begin(CURRENT_SLAVE_ID, modbusSerial);
  28.  
  29. delay(200);
  30.  
  31. Serial.print("Changing Slave ID from ");
  32. Serial.print(CURRENT_SLAVE_ID);
  33. Serial.print(" to ");
  34. Serial.print(NEW_SLAVE_ID);
  35. Serial.print("... ");
  36.  
  37. uint8_t result = node.writeSingleRegister(RENKE_REG_ADDR, NEW_SLAVE_ID);
  38.  
  39. if (result == node.ku8MBSuccess) {
  40. Serial.println("SUCCESS!");
  41. Serial.println("Power cycle the 12V supply to finalize the address change.");
  42. } else {
  43. Serial.print("FAILED - Error: 0x");
  44. Serial.println(result, HEX);
  45. }
  46. }
  47.  
  48. void loop() {
  49. // Setup runs once
  50. }
Advertisement
Add Comment
Please, Sign In to add comment