Skip to content

6. Using more than one SDI 12 object.

Sara Damiano edited this page Aug 13, 2024 · 3 revisions

Overview

This library is allows for multiple instances of itself running on different pins, however, you should use care. The instances DO NOT share a buffer, as they do in the multi-instance case for SoftwareSerial, so it will consume more RAM than you might expect.

SDI-12 can support up to 62 sensors on a single pin/bus, so it is not necessary to use an instance for each sensor.

Because we are using pin change interrupts there can only be one active object at a time (since this is the only reliable way to determine which pin the interrupt occurred on). The active object is the only object that will respond properly to interrupts. However promoting another instance to Active status does not automatically remove the interrupts on the other pin. For proper behavior it is recommended to use this pattern:

   mySDI12.forceHold();
   myOtherSDI12.setActive();

Other notes: Promoting an object into the Active state will set it as HOLDING. See 6.1 for more information.

Calling mySDI12.begin() will assert mySDI12 as the new active object, until another instance calls myOtherSDI12.begin() or myOtherSDI12.setActive().

Calling mySDI12.end() does NOT hand-off active status to another SDI-12 instance.

You can check on the active object by calling mySDI12.isActive(), which will return a boolean value TRUE if active or FALSE if inactive.

6.1 setActive()

  • a method for setting the current object as the active object.
  • returns TRUE if the object was not formerly the active object and now is.

Promoting an inactive to the active instance will start it in the HOLDING state and return TRUE.

Otherwise, if the object is currently the active instance, it will remain unchanged and return FALSE.

bool SDI12::setActive()
{
  if (_activeObject != this)
  {
    setState(HOLDING);
    _activeObject = this;
    return true;
  }
  return false;
}

6.2 isActive()

isActive() is a method for checking if the object is the active object. It returns true if the object is currently the active object, false otherwise.

bool SDI12::isActive() { return this == _activeObject; }