upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
IMS Class Reference

API for the Catnip Electronics I2C moisture sensor. More...

Detailed Description

I2C sensor which can be used to read: moisture light temperature

This sensor must run at 100 kHz

ims.png
// Instantiate a IMS instance using i2c bus 0 and default address
upm::IMS sensor(0);
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
while (shouldRun)
{
std::cout << std::hex << "Version: 0x"
<< sensor.get_version()
<< " light: 0x"
<< sensor.get_light()
<< " moisture: 0x"
<< sensor.get_moisture()
<< " temp: "
<< sensor.get_temperature()
<< " C"
<< std::endl;
// Change the address and continue
if (i2c_addr_cur >= 128) i2c_addr_cur = 1;
std::cout << "Changing device address to 0x" << i2c_addr_cur
<< std::endl;
sensor.reset_i2c_address(i2c_addr_cur++);
sleep(1);
}

Public Member Functions

 IMS (int16_t i2c_bus, int16_t i2c_address=IMS_ADDRESS_DEFAULT)
 
virtual ~IMS ()
 
void write (IMS_WR_COMMAND cmd, uint8_t wr_data)
 
uint16_t read (IMS_RD_COMMAND cmd)
 
uint16_t get_version ()
 
uint16_t get_moisture ()
 
uint16_t get_light ()
 
float get_temperature ()
 
void reset ()
 
void reset_i2c_address (uint8_t address_new)
 
void sleep ()
 

Constructor & Destructor Documentation

IMS ( int16_t  i2c_bus,
int16_t  i2c_address = IMS_ADDRESS_DEFAULT 
)

I2C Moisture Sensor constructor

Initialize I2C Moisture Sensor

Parameters
i2c_busTarget I2C bus
i2c_addressTarget I2C address (default is 0x20)
Returns
sensor context pointer
Exceptions
std::runtime_errorif sensor initializate fails
virtual ~IMS ( )
inlinevirtual

IMS destructor

Member Function Documentation

void write ( IMS_WR_COMMAND  cmd,
uint8_t  wr_data 
)

Write I2C Moisture Sensor registers

Parameters
cmdWrite command
wr_dataTarget data to write (only used for IMS_SET_ADDRESS)
Exceptions
std::runtime_errorif I2C write command fails

Here is the call graph for this function:

uint16_t read ( IMS_RD_COMMAND  cmd)

Read I2C Moisture Sensor registers

Parameters
cmdRead command
Returns
Data returned from sensor (1 or 2 bytes depending on CMD)
Exceptions
std::runtime_errorif I2C read command fails

Here is the call graph for this function:

uint16_t get_version ( )

Get sensor version

Returns
Sensor version
Exceptions
std::runtime_errorif I2C read command fails

Here is the call graph for this function:

uint16_t get_moisture ( )

Get moisture reading from sensor

Returns
Unitless, relative capacitance value (moisture)
Exceptions
std::runtime_errorif I2C read command fails

Here is the call graph for this function:

uint16_t get_light ( )

Get light reading from LED on device. The technical data for the I2C moisture sensor specifies a 3 second wait. Loop for 3 seconds checking the GET_BUSY register. IF the sensor is NOT ready after 3 seconds, assume there is NO light and return a max uint16_t (dark) value.

Returns
rd_data Unitless, relative value for brightness dark (0xFFFF) —> light (0x0000)
Exceptions
std::runtime_errorif I2C write/read command fails

Here is the call graph for this function:

float get_temperature ( )

Get temperature reading from device

Returns
rd_data Temperature in degrees Celsius
Exceptions
std::runtime_errorif I2C read command fails

Here is the call graph for this function:

void reset ( )

Reset sensor

Exceptions
std::runtime_errorif I2C write command fails

Here is the call graph for this function:

void reset_i2c_address ( uint8_t  address_new)

Set I2C address AND reset sensor

Parameters
address_newNew I2C for device
Exceptions
std::runtime_errorif I2C write command fails

Here is the call graph for this function:

void sleep ( )

Put device into low-power mode. Device wakes on any I2C command.

Exceptions
std::runtime_errorif I2C write command fails

Here is the call graph for this function:


The documentation for this class was generated from the following files: