Troubleshooting

Recovering a potentially firmware bricked RS485 Soil NPK Sensor

userHead derethan 2025-12-30 22:27:11 11 Views0 Replies

Hello,

 

I have an RS485 Soil NPK Sensor that i purchased from DF robot over a year ago. The sensor has been built into an Arduino based device taking sensor readings consistently for the past years growing season.

Here is the sensor: 
SEN0605
RS485 MODBUS-RTU Soil NPK Measure Sensor for Efficient Agricultural (IP68, 5-30V)

Wiki: https://wiki.dfrobot.com/RS485_Soil_Sensor_N_P_K_SKU_SEN0605

 

This past week i decided to work on some upgrades so that i could add an additional RS485 sensor to the system. In order to accomplish this i had to change the Device address so i could read from multiple RS485 Devices on the same Max 485 Chip.

For some context:

- I did NOT change any wiring or any of the code used to read the sensors or check for a device on a specific modbus address.

- The device was working as expected when i started that morning.


------
Here is what i did:

I ran the following to verify the device at the address, in this case address 1:

uint16_t NPKSensor::readCurrentAddress()

{

   uint8_t result;

   uint16_t currentAddress = 0;


 

   // start sensor

   startSensor();

   delay(3000); // Wait for sensor to stabilize


 

   // Log

   Serial.println("Reading Current Modbus Address...");


 

   // Read register at specified address

   result = npkModBusNode.readHoldingRegisters(0x07D0, 1);

   if (result == npkModBusNode.ku8MBSuccess)

   {

       currentAddress = npkModBusNode.getResponseBuffer(0x0);

       Serial.print("Current Address: ");

       Serial.println(currentAddress);

   }

   else

   {

       Serial.println("Failed to read current address! Check wiring.");

       printModbusError(result);

   }


 

   // stop sensor

   stopSensor();


 

   return currentAddress;

}


This worked as expected and returned the device address of 1.

----


Then i used this function to try and change the device address (i supplies 2 as the parameter for the new address):

bool NPKSensor::changeSensorAddress(uint16_t newAddress)

{

   uint8_t result;


 

   // start sensor

   startSensor();

   delay(1000); // Wait for sensor to stabilize


 

   Serial.println("Changing Modbus Address to 2...");

   result = npkModBusNode.writeSingleRegister(0x07D0, newAddress); // Write new address (2)


 

   if (result == npkModBusNode.ku8MBSuccess)

   {

       Serial.print("Sensor address changed to: ");

       Serial.println(newAddress);


 

       // stop sensor

       stopSensor();

       return true;

   }

   else

   {

       Serial.println("Failed to change sensor address! Check wiring.");

       printModbusError(result);


 

       // stop sensor

       stopSensor();

       return false;

   }

}

After this, the Serial printed out that it had changed the address to 2.

-----

 

Now it would appear i cannot read from the device at all. I have changed the device/slave address when setting up the modbus to to use the new address. I even tested a looping function to check and try and read the current address from all modbus ID's and got no response/timeout.

The only thing i can think of is that the stopSensor(); call (which turns off the mosfet powering the NPK sensor) not having a long enough delay after changing the address immediately cut the power to the NKP sensor before it had a chance to properly assign the new address to its EEPROM and now the sensor has a corrupt address.

Is there any knows recover methods for this sensor or a way to set it back to its factory defaults?