API for the Catnip Electronics I2C moisture sensor.  
 More...
I2C sensor which can be used to read: moisture light temperature
This sensor must run at 100 kHz
 
    
    while (shouldRun)
    {
        std::cout << "Version: "
            << sensor.get_version()
            << " light: "
            << sensor.get_light()
            << " moisture: "
            << sensor.get_moisture()
            << " temp: "
            << sensor.get_temperature()
            << " C"
            << std::endl;
    }
  
      
        
          | IMS  | 
          ( | 
          int16_t  | 
          i2c_bus,  | 
        
        
           | 
           | 
          int16_t  | 
          i2c_address = IMS_ADDRESS_DEFAULT  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
I2C Moisture Sensor constructor
Initialize I2C Moisture Sensor 
- Parameters
 - 
  
    | i2c_bus | Target I2C bus  | 
    | i2c_address | Target I2C address (default is 0x20)  | 
  
   
- Returns
 - sensor context pointer 
 
- Exceptions
 - 
  
    | std::runtime_error | if sensor initializate fails  | 
  
   
 
 
      
        
          | void write  | 
          ( | 
          IMS_WR_COMMAND  | 
          cmd,  | 
        
        
           | 
           | 
          uint8_t  | 
          wr_data  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Write I2C Moisture Sensor registers 
- Parameters
 - 
  
    | cmd | Write command  | 
    | wr_data | Target data to write (only used for IMS_SET_ADDRESS)  | 
  
   
- Exceptions
 - 
  
    | std::runtime_error | if I2C write command fails  | 
  
   
 
 
      
        
          | uint16_t read  | 
          ( | 
          IMS_RD_COMMAND  | 
          cmd | ) | 
           | 
        
      
 
Read I2C Moisture Sensor registers 
- Parameters
 - 
  
  
 
- Returns
 - Data returned from sensor (1 or 2 bytes depending on CMD) 
 
- Exceptions
 - 
  
    | std::runtime_error | if I2C read command fails  | 
  
   
 
 
Get sensor version 
- Returns
 - Sensor version 
 
- Exceptions
 - 
  
    | std::runtime_error | if I2C read command fails  | 
  
   
 
 
      
        
          | uint16_t get_moisture  | 
          ( | 
           | ) | 
           | 
        
      
 
Get moisture reading from sensor 
- Returns
 - Unitless, relative capacitance value (moisture) 
 
- Exceptions
 - 
  
    | std::runtime_error | if I2C read command fails  | 
  
   
 
 
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_error | if I2C write/read command fails  | 
  
   
 
 
      
        
          | float get_temperature  | 
          ( | 
           | ) | 
           | 
        
      
 
Get temperature reading from device 
- Returns
 - rd_data Temperature in degrees Celsius 
 
- Exceptions
 - 
  
    | std::runtime_error | if I2C read command fails  | 
  
   
 
 
Reset sensor 
- Exceptions
 - 
  
    | std::runtime_error | if I2C write command fails  | 
  
   
 
 
      
        
          | void reset_i2c_address  | 
          ( | 
          uint8_t  | 
          address_new | ) | 
           | 
        
      
 
Set I2C address AND reset sensor 
- Parameters
 - 
  
    | address_new | New I2C for device  | 
  
   
- Exceptions
 - 
  
    | std::runtime_error | if I2C write command fails  | 
  
   
 
 
Put device into low-power mode. Device wakes on any I2C command. 
- Exceptions
 - 
  
    | std::runtime_error | if I2C write command fails  | 
  
   
 
 
The documentation for this class was generated from the following files: