Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <ModbusMaster.h>
- // Pin definitions (RX = D2 to RO, TX = D3 to DI)
- #define RX_PIN 2
- #define TX_PIN 3
- // Communication settings
- #define CURRENT_SLAVE_ID 1 // The address the sensor currently responds to
- #define NEW_SLAVE_ID 2 // The new address you want to assign (1 - 247)
- #define BUS_BAUD_RATE 4800 // Current bus baud rate (4800 or 9600)
- // Renke EEPROM Address Register
- #define RENKE_REG_ADDR 0x07D0
- SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
- ModbusMaster node;
- void setup() {
- Serial.begin(9600);
- while (!Serial);
- delay(500);
- Serial.println("--- Renke Slave ID Configurator ---");
- modbusSerial.begin(BUS_BAUD_RATE);
- node.begin(CURRENT_SLAVE_ID, modbusSerial);
- delay(200);
- Serial.print("Changing Slave ID from ");
- Serial.print(CURRENT_SLAVE_ID);
- Serial.print(" to ");
- Serial.print(NEW_SLAVE_ID);
- Serial.print("... ");
- uint8_t result = node.writeSingleRegister(RENKE_REG_ADDR, NEW_SLAVE_ID);
- if (result == node.ku8MBSuccess) {
- Serial.println("SUCCESS!");
- Serial.println("Power cycle the 12V supply to finalize the address change.");
- } else {
- Serial.print("FAILED - Error: 0x");
- Serial.println(result, HEX);
- }
- }
- void loop() {
- // Setup runs once
- }
Advertisement
Add Comment
Please, Sign In to add comment