BayEOSArduino Library
Functions | Variables
Constructor, Destructor, Begins, and Setters

These functions set up the SDI-12 object and prepare it for use. More...

Functions

 SDI12::SDI12 ()
 Construct a new SDI12 instance with no data pin set. More...
 
 SDI12::SDI12 (int8_t dataPin)
 Construct a new SDI12 with the data pin set. More...
 
 SDI12::~SDI12 ()
 Destroy the SDI12 object. More...
 
void SDI12::begin ()
 Begin the SDI-12 object. More...
 
void SDI12::begin (int8_t dataPin)
 Set the SDI12::_datapin and begin the SDI-12 object. More...
 
void SDI12::end ()
 Disable the SDI-12 object (but do not destroy it). More...
 
void SDI12::setTimeoutValue (int16_t value)
 Set the value to return if a parse int or parse float times out with no return from the sensor. More...
 
int8_t SDI12::getDataPin ()
 Get the data pin for the current SDI-12 instance. More...
 
void SDI12::setDataPin (int8_t dataPin)
 Set the data pin for the current SDI-12 instance. More...
 

Variables

int16_t SDI12::TIMEOUT
 The value to return if a parse or read times out with no return from the sensor. More...
 

Detailed Description

These functions set up the SDI-12 object and prepare it for use.

Function Documentation

◆ begin() [1/2]

void SDI12::begin ( void  )

Begin the SDI-12 object.

This is called to begin the functionality of the SDI-12 object. It sets the object as the active object, sets the stream timeout to 150ms to match SDI-12 specs, sets the timeout return value to SDI12::TIMEOUT, and configures the timer prescaler.

◆ begin() [2/2]

void SDI12::begin ( int8_t  dataPin)

Set the SDI12::_datapin and begin the SDI-12 object.

This is called to begin the functionality of the SDI-12 object. It sets the object as the active object, sets the stream timeout to 150ms to match SDI-12 specs, sets the timeout return value to SDI12::TIMEOUT, and configures the timer prescaler. If the SDI-12 instance is created using the empty constuctor, this must be used to set the data pin.

Parameters
dataPinThe data pin's digital pin number

◆ end()

void SDI12::end ( void  )

Disable the SDI-12 object (but do not destroy it).

Set the SDI-12 state to disabled, set the pointer to the current active instance to null, and then, for AVR boards, unset the timer prescaler.

This can be called to temporarily cease all functionality of the SDI-12 object. It is not as harsh as destroying the object with the destructor, as it will maintain the memory buffer.

◆ getDataPin()

int8_t SDI12::getDataPin ( )

Get the data pin for the current SDI-12 instance.

Returns
int8_t the data pin number

◆ SDI12() [1/2]

SDI12::SDI12 ( )

Construct a new SDI12 instance with no data pin set.

Before using the SDI-12 instance, the data pin must be set with SDI12::setDataPin(dataPin) or SDI12::begin(dataPin). This empty constructor is provided for easier integration with other Arduino libraries.

When the constructor is called it resets the buffer overflow status to FALSE.

◆ SDI12() [2/2]

SDI12::SDI12 ( int8_t  dataPin)
explicit

Construct a new SDI12 with the data pin set.

Parameters
dataPinThe data pin's digital pin number

When the constructor is called it resets the buffer overflow status to FALSE and assigns the pin number "dataPin" to the private variable "_dataPin".

◆ setDataPin()

void SDI12::setDataPin ( int8_t  dataPin)

Set the data pin for the current SDI-12 instance.

Parameters
dataPinThe data pin's digital pin number

◆ setTimeoutValue()

void SDI12::setTimeoutValue ( int16_t  value)

Set the value to return if a parse int or parse float times out with no return from the sensor.

The "standard" timeout return for an Arduino stream object when no character is available in the Rx buffer is "0." For enviromental sensors (the typical SDI-12 users) 0 is a common result value. To better distinguish between a timeout because of no sensor response and a true zero return, the timeout should be set to some value that is NOT a possible return from that sensor. If the timeout is not set, -9999 is used.

Parameters
valuethe value to return on timeout

◆ ~SDI12()

SDI12::~SDI12 ( )

Destroy the SDI12 object.

When the destructor is called, it's main task is to disable any interrupts that had been previously assigned to the pin, so that the pin will behave as expected when used for other purposes. This is achieved by putting the SDI-12 object in the SDI12_DISABLED state. After disabling interrupts, the pointer to the current active SDI-12 instance is set to null if it had pointed to the destroyed object. Finally, for AVR board, the timer prescaler is set back to whatever it had been prior to creating the SDI-12 object.

Variable Documentation

◆ TIMEOUT

int16_t SDI12::TIMEOUT

The value to return if a parse or read times out with no return from the sensor.

The timeout return for an Arduino stream object when no character is available in the Rx buffer is "0." For enviromental sensors (the typical SDI-12 users) 0 is a common result value. To better distinguish between a timeout because of no sensor response and a true zero return, the timeout should be set to some value that is NOT a possible return from that sensor. If the timeout is not set, -9999 is used.