Rusty_Gunn

Nano_Modbus_Pyranometer_Baud

Sep 6th, 2026
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 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 CURRENT_SLAVE_ID 2 // Now communicating with ID 2
  8. #define CURRENT_BAUD_RATE 4800
  9.  
  10. #define RENKE_REG_BAUD 0x07D1 // Baud rate EEPROM register
  11. #define BAUD_CODE_9600 2 // 0=2400, 1=4800, 2=9600
  12.  
  13. SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
  14. ModbusMaster node;
  15.  
  16. void setup()
  17. {
  18. Serial.begin(9600);
  19. while (!Serial);
  20. delay(1000);
  21.  
  22. Serial.println("Renke Baud Rate Updater (Targeting ID 2)");
  23. Serial.println("----------------------------------------");
  24.  
  25. modbusSerial.begin(CURRENT_BAUD_RATE);
  26. node.begin(CURRENT_SLAVE_ID, modbusSerial);
  27.  
  28. delay(500);
  29.  
  30. Serial.print("Writing Baud 9600 (Value: 2) to register 0x07D1... ");
  31. uint8_t result = node.writeSingleRegister(RENKE_REG_BAUD, BAUD_CODE_9600);
  32.  
  33. if (result == node.ku8MBSuccess) {
  34. Serial.println("SUCCESS!");
  35. } else {
  36. // If the sensor switches its UART speed immediately, a timeout response is expected
  37. Serial.print("Response Code: 0x");
  38. Serial.print(result, HEX);
  39. Serial.println(" (Timeout is normal if UART switched instantly)");
  40. }
  41.  
  42. Serial.println("----------------------------------------");
  43. Serial.println("Power cycle the 12V supply to finalize the 9600 baud setting.");
  44. }
  45.  
  46. void loop() {}
Advertisement
Add Comment
Please, Sign In to add comment