upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for ecezo.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include <upm_utilities.h>
#include <ecezo.h>
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
ecezo_context sensor = ecezo_uart_init(0, 9600);
// For I2C, assuming the device is configured for address 0x64 on
// I2C bus 0, you could use something like:
//
// ecezo_context sensor = ecezo_i2c_init(0, 0x64);
if (!sensor)
{
printf("ecezo_init() failed.\n");
return 1;
}
while (shouldRun)
{
// this will take about 1 second to complete
if (ecezo_update(sensor))
{
printf("ecezo_update() failed\n");
}
else
{
printf("EC %f uS/cm, TDS %f mg/L, Salinity %f PSS-78, SG %f\n",
ecezo_get_ec(sensor),
ecezo_get_tds(sensor),
ecezo_get_sg(sensor));
}
upm_delay(5);
}
printf("Exiting\n");
ecezo_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _ecezo_context
 

Functions

ecezo_context ecezo_uart_init (unsigned int uart, unsigned int baudrate)
 
ecezo_context ecezo_i2c_init (unsigned int bus, uint8_t addr)
 
void ecezo_close (ecezo_context dev)
 
upm_result_t ecezo_update (const ecezo_context dev)
 
upm_result_t ecezo_set_temperature (const ecezo_context dev, float temp)
 
upm_result_t ecezo_set_k_value (const ecezo_context dev, float k)
 
upm_result_t ecezo_set_sleep (const ecezo_context dev, bool enable)
 
float ecezo_get_ec (const ecezo_context dev)
 
float ecezo_get_tds (const ecezo_context dev)
 
float ecezo_get_salinity (const ecezo_context dev)
 
float ecezo_get_sg (const ecezo_context dev)
 
upm_result_t ecezo_calibrate (const ecezo_context dev, ECEZO_CALIBRATION_T cal, float ec)
 
upm_result_t ecezo_set_continuous (const ecezo_context dev, bool enable)
 
int ecezo_send_command (const ecezo_context dev, char *cmd, char *buffer, int len)
 
int ecezo_read (const ecezo_context dev, char *buffer, size_t len)
 
upm_result_t ecezo_write (const ecezo_context dev, char *buffer, size_t len)
 

Typedefs

typedef struct _ecezo_contextecezo_context
 

Function Documentation

ecezo_context ecezo_uart_init ( unsigned int  uart,
unsigned int  baudrate 
)

ECEZO Initializer for UART operation

Parameters
uartSpecify which uart to use.
baudrateSpecify the baudrate to use. The device defaults to 9600 baud, though the datasheet implies the default is 38400.
Returns
an initialized device context on success, NULL on error.

Here is the call graph for this function:

Here is the caller graph for this function:

ecezo_context ecezo_i2c_init ( unsigned int  bus,
uint8_t  addr 
)

ECEZO Initializer for I2C operation

Parameters
busSpecify which the I2C bus to use.
addrSpecify the I2C address to use. This is configurable on the device, so there is no default.
Returns
an initialized device context on success, NULL on error.

Here is the call graph for this function:

Here is the caller graph for this function:

void ecezo_close ( ecezo_context  dev)

ECEZO sensor close function

Here is the caller graph for this function:

upm_result_t ecezo_update ( const ecezo_context  dev)

Query the device for a reading, parse the response, and store the read values into the device context. This function must be called prior to calling any function that returns the data, like ecezo_get_ec().

Parameters
devDevice context
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t ecezo_set_temperature ( const ecezo_context  dev,
float  temp 
)

For accurate readings, the temperature of the liquid being measured should be known. This function allows you to specify the liquid's temperature (in Celsius) so that proper compensation can take place. How you measure this temperature is up to you. By default, the device will assume a temperature of 25C.

Parameters
devDevice context
tempThe temperature of the liquid being measured
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t ecezo_set_k_value ( const ecezo_context  dev,
float  k 
)

Set the K value of the probe being used. By default, this is 1.0. Valid values are between 0.1 and 10.0.

Parameters
devDevice context
kThe K value of the probe
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t ecezo_set_sleep ( const ecezo_context  dev,
bool  enable 
)

Enable or disable Sleep mode.

Parameters
devDevice context
enableTrue to enable sleep mode, false to wake up
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

float ecezo_get_ec ( const ecezo_context  dev)

Retrieve the last measured Electrical Conductivity (EC) value in microsiemens. ecezo_update() must have been called before calling this function.

Parameters
devDevice context
Returns
EC value in microsiemens

Here is the caller graph for this function:

float ecezo_get_tds ( const ecezo_context  dev)

Retrieve the last measured Total Dissolved solids (TDS) value. ecezo_update() must have been called before calling this function.

Parameters
devDevice context
Returns
TDS value

Here is the caller graph for this function:

float ecezo_get_salinity ( const ecezo_context  dev)

Retrieve the last measured Salinity value. ecezo_update() must have been called before calling this function.

Parameters
devDevice context
Returns
Salinity value

Here is the caller graph for this function:

float ecezo_get_sg ( const ecezo_context  dev)

Retrieve the last measured Specific Gravity (SG) value. ecezo_update() must have been called before calling this function.

Parameters
devDevice context
Returns
SG value

Here is the caller graph for this function:

upm_result_t ecezo_calibrate ( const ecezo_context  dev,
ECEZO_CALIBRATION_T  cal,
float  ec 
)

Specify calibration data for calibrating the device. See the datasheet for details on how calibration is performed. This function provides a mechanism for clearing out, and setting calibration data.

A simple one point calibration might work as follows:

  1. CLEAR the calibration data
  2. with a dry probe, set the DRY point.
  3. with the probe immersed in a standardized solution, set the ONE parameter to the solution's known EC value in microsiemens.

A two point calibration might work as follows:

  1. CLEAR the calibration data
  2. with a dry probe, set the DRY point.
  3. with the probe immersed in the lowest EC standardized solution, set the LOW parameter to the solution's known EC value in microsiemens.
  4. with the probe immersed in the highest EC standardized solution, set the HIGH parameter to the solution's known EC value in microsiemens.
Parameters
devDevice context
calOne of the ECEZO_CALIBRATION_T values
ecThe EC value of the calibration fluid. This parameter is ignored when cal is either ECEZO_CALIBRATE_CLEAR or ECEZO_CALIBRATE_DRY.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t ecezo_set_continuous ( const ecezo_context  dev,
bool  enable 
)

Enable or disable "continuous" operation. In continuous operation, the device will sample and emit readings every second. The driver disables this mode by default. If you wish to use continuous mode, you will be responsible for reading and parsing the returned data yourself.

The functionality of this driver depends on continuous mode being disabled. When disabled, the driver will manually request a reading when desired via ecezo_update().

Parameters
devDevice context
enabletrue to enable continuous mode, false to disable.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

int ecezo_send_command ( const ecezo_context  dev,
char *  cmd,
char *  buffer,
int  len 
)

Directly send a command to the device and optionally get a response. This is a low level function and should not be called unless you know what you are doing.

Parameters
devDevice context
cmdcommand to send to the device. See the datasheet for valid commands.
bufferOptional buffer in which to return any data. NULL if you are not interested in any returned data.
lenLength of the buffer, or 0 if you are not interested in returned data
Returns
Number of characters read back, 0 if a timeout or no data, -1 if an error

Here is the call graph for this function:

Here is the caller graph for this function:

int ecezo_read ( const ecezo_context  dev,
char *  buffer,
size_t  len 
)

Read character data from the device. This is a low level function and should not be called unless you know what you are doing.

Parameters
devsensor context
bufferThe character buffer to read data into.
lenThe maximum size of the buffer
Returns
The number of bytes successfully read, or -1 on error

Here is the caller graph for this function:

upm_result_t ecezo_write ( const ecezo_context  dev,
char *  buffer,
size_t  len 
)

Write character data to the device. This is a low level function and should not be called unless you know what you are doing.

Parameters
devsensor context
bufferThe character buffer containing data to write.
lenThe number of bytes to write.
Returns
The number of bytes successfully written, or -1 on error.

Here is the caller graph for this function:

Typedef Documentation

typedef struct _ecezo_context * ecezo_context

Device context