WaspSensorAgr Class Reference

WaspSensorAgr Class. More...

#include <WaspSensorAgr.h>


Public Member Functions

 WaspSensorAgr ()
 class constructor
void setBoardMode (uint8_t mode)
 It sets board power mode, setting ON/OFF 3v3 and 5V switches.
void setSensorMode (uint8_t mode, uint16_t sensor)
 It sets ON/OFF the different sensor switches.
float readValue (uint16_t sensor)
 It reads the value measured by the sensor.
float readValue (uint16_t sensor, uint8_t type)
 It reads the value measured by the sensor.
void setAnemometerThreshold (float threshold)
 It sets threshold configuring digipots.
void sleepAgr (const char *time2wake, uint8_t offset, uint8_t mode, uint8_t option)
 It sleeps Waspmote enabling the switches required for the agriculture board.
void sleepAgr (const char *time2wake, uint8_t offset, uint8_t mode, uint8_t option, uint8_t agr_interrupt)
 It sleeps Waspmote enabling the switches required for the agriculture board.
void attachInt (uint8_t sens)
 It switches off the general switch enabling RTC interruption for the Agriculture Board.
void detachInt (uint8_t sens)
 It attaches the interruption.

Data Fields

uint16_t vane_direction
 Variable : specifies the wind direction.

Private Member Functions

void setDigipot (float value)
 It sets the Digipot threshold.
float readDendrometer ()
 It reads from the dendrometer.
float readPT1000 ()
 It reads from the PT1000.
float readRadiation ()
 It reads from the radiation sensors.
float readWatermark (uint8_t sens)
 It reads from the Watermark.
float readSensirion (uint8_t parameter)
 It reads from the sensirion.
uint16_t readPluviometer ()
 It reads from the pluviometer.
float conversion (byte data_input[3], uint8_t type)
 It converts data.
float pressure_conversion (int readValue)
 It converts pressure.
float lws_conversion (int readValue)
 It converts leaf wetness.
float humidity_conversion (int readValue)
 It converts humidity.
float temperature_conversion (int readValue)
 It converts temperature.
void getVaneDirection (float vane)
 It gets the direction of the wind.
float temperature_conversion (int readValue, int precision)
 It converts the temperature returned by sensirion.
float humidity_conversion (int readValue, int precision)
 It converts the humidity returned by sensirion.
float sencera_conversion (int readValue)
 It converts the humidity returned by sencera.
float mcp_conversion (int readValue)
 It converts the temperature returned by mcp.


Detailed Description

WaspSensorAgr Class.

WaspSensorAgr Class defines all the variables and functions used for managing the Agriculture Sensor Board

Definition at line 267 of file WaspSensorAgr.h.


Constructor & Destructor Documentation

WaspSensorAgr::WaspSensorAgr (  ) 

class constructor

It initializes the different digital pins

Parameters:
void 
Returns:
void

Definition at line 30 of file WaspSensorAgr.cpp.

References ANA0, DIGITAL1, DIGITAL2, DIGITAL3, DIGITAL4, DIGITAL5, DIGITAL6, DIGITAL7, DIGITAL8, digitalWrite(), INPUT, LOW, OUTPUT, pinMode(), SENS_PW_3V3, and SENS_PW_5V.

Here is the call graph for this function:


Member Function Documentation

void WaspSensorAgr::setDigipot ( float  value  )  [private]

It sets the Digipot threshold.

Parameters:
uint8_t value : threshold
Returns:
void

Definition at line 626 of file WaspSensorAgr.cpp.

References B00000000, B0101000, TwoWire::begin(), TwoWire::beginTransmission(), WaspPWR::closeI2C(), delay(), TwoWire::endTransmission(), PWR, TwoWire::send(), and Wire.

Referenced by setAnemometerThreshold().

00627 {
00628 
00629         float thres=0.0;
00630         uint8_t threshold=0;
00631         uint8_t address=B0101000;       
00632         
00633         thres=(3.3-value);
00634         thres *=128;
00635         thres /=3.3;
00636         threshold = (uint8_t) thres;
00637         Wire.begin();
00638         delay(100);
00639         Wire.beginTransmission(address);
00640         Wire.send(B00000000);
00641         Wire.send(threshold);
00642         Wire.endTransmission();
00643         PWR.closeI2C(); 
00644 }

Here is the call graph for this function:

Here is the caller graph for this function:

float WaspSensorAgr::readDendrometer (  )  [private]

It reads from the dendrometer.

Returns:
the value returned by the sensor

Definition at line 298 of file WaspSensorAgr.cpp.

References TwoWire::available(), B0010110, B01010101, B10100001, TwoWire::begin(), TwoWire::beginTransmission(), WaspPWR::closeI2C(), conversion(), delay(), TwoWire::endTransmission(), PWR, TwoWire::receive(), TwoWire::requestFrom(), TwoWire::send(), and Wire.

Referenced by readValue().

00299 {
00300         const byte address_ADC = B0010110;
00301         const byte dendro_channel = B10100001;
00302         byte data_dendro[3] = {0,0,0};
00303         float value_dendro = 0;
00304         
00305         Wire.begin();
00306         delay(100);
00307         delay(100);
00308         
00309         delay(100);
00310   
00311         Wire.beginTransmission(B0010110);
00312         Wire.send(dendro_channel);
00313         Wire.send(B01010101);
00314         Wire.endTransmission();
00315 
00316         delay(300);
00317   
00318         Wire.requestFrom(B0010110, 3);
00319   
00320         int i=0;
00321         while(Wire.available())
00322         {
00323                 data_dendro[i]=Wire.receive();
00324                 i++;
00325         }
00326         
00327         PWR.closeI2C(); 
00328   
00329         return value_dendro = conversion(data_dendro,0);
00330 }

Here is the call graph for this function:

Here is the caller graph for this function:

float WaspSensorAgr::readPT1000 (  )  [private]

It reads from the PT1000.

Returns:
the value returned by the sensor

Definition at line 332 of file WaspSensorAgr.cpp.

References TwoWire::available(), B0010110, B01010101, B10100000, TwoWire::begin(), TwoWire::beginTransmission(), WaspPWR::closeI2C(), conversion(), delay(), TwoWire::endTransmission(), PWR, TwoWire::receive(), TwoWire::requestFrom(), TwoWire::send(), and Wire.

Referenced by readValue().

00333 {
00334         const byte address_ADC = B0010110;
00335         const byte pt1000_channel = B10100000;
00336         byte data_pt1000[3] = {0,0,0};
00337         float value_pt1000 = 0;
00338         
00339         Wire.begin();
00340         delay(100);
00341         delay(100);
00342         
00343         delay(100);
00344 
00345         Wire.beginTransmission(B0010110);
00346         Wire.send(pt1000_channel);
00347         Wire.send(B01010101);
00348         Wire.endTransmission();
00349   
00350         delay(300);
00351   
00352         Wire.requestFrom(B0010110, 3);
00353 
00354         int k=0;
00355         while(Wire.available())
00356         {
00357                 data_pt1000[k]=Wire.receive();
00358                 k++;
00359         }
00360 
00361         PWR.closeI2C(); 
00362 
00363         return value_pt1000 = conversion(data_pt1000,1);  
00364 }

Here is the call graph for this function:

Here is the caller graph for this function:

float WaspSensorAgr::readRadiation (  )  [private]

It reads from the radiation sensors.

Returns:
the value returned by the sensor

Definition at line 366 of file WaspSensorAgr.cpp.

References TwoWire::available(), B0010100, TwoWire::begin(), WaspPWR::closeI2C(), delay(), PWR, TwoWire::receive(), TwoWire::requestFrom(), and Wire.

Referenced by readValue().

00367 {
00368         const byte address = B0010100;
00369         byte data_apogee[2] = {0,0};
00370         long val = 0;
00371         float val_def = 0;
00372         
00373         Wire.begin();
00374   
00375         delay(100);
00376   
00377         delay(50);
00378         
00379         Wire.requestFrom(B0010100, 2);
00380   
00381         int i = 0;
00382         while(Wire.available())
00383         {
00384                 data_apogee[i] = Wire.receive();
00385                 i++;
00386         }
00387   
00388 // FIN DE LA LECTURA
00389         
00390         PWR.closeI2C(); 
00391 
00392 // CONVERSIÓN A VALOR DE TENSIÓN
00393   
00394         val = long(data_apogee[1]) + long(data_apogee[0])*256;
00395     
00396         val_def = (val - 32769)*9;
00397         return val_def = val_def/65535;
00398 }

Here is the call graph for this function:

Here is the caller graph for this function:

float WaspSensorAgr::readWatermark ( uint8_t  sens  )  [private]

It reads from the Watermark.

Parameters:
uint8_t sens : the Watermark on use
Returns:
the value returned by the sensor

Definition at line 400 of file WaspSensorAgr.cpp.

References digitalRead(), digitalWrite(), INPUT, LOW, millis(), pinMode(), SENS_AGR_WATERMARK_1, SENS_AGR_WATERMARK_2, SENS_AGR_WATERMARK_3, and SENS_MUX_SEL.

Referenced by readValue().

00401 {
00402         uint8_t pin=0;
00403         int value_watermark = 0;
00404         int previous_value_watermark = 0;
00405         int counter_watermark = 0;
00406         unsigned long start = 0;
00407         float freq = 0;
00408         
00409         pinMode(15, INPUT);
00410         pinMode(17, INPUT);
00411         pinMode(19, INPUT);
00412         
00413         digitalWrite(SENS_MUX_SEL,LOW);
00414         
00415         switch( sens )
00416         {
00417                 case SENS_AGR_WATERMARK_1:      pin=17;
00418                                                 break;
00419                 case SENS_AGR_WATERMARK_2:      pin=19;
00420                                                 break;
00421                 case SENS_AGR_WATERMARK_3:      pin=15;
00422                                                 break;
00423         }
00424         
00425         counter_watermark = 0;
00426         start = millis();
00427         while(counter_watermark < 2000)
00428         {
00429                 previous_value_watermark = value_watermark;
00430                 value_watermark = digitalRead(pin);
00431     
00432                 if((previous_value_watermark ==1)&&(value_watermark == 0))
00433                 {
00434                         counter_watermark++;
00435                 }
00436         }
00437   
00438         return freq = 2000000 / float((millis() - start));
00439 }

Here is the call graph for this function:

Here is the caller graph for this function:

float WaspSensorAgr::readSensirion ( uint8_t  parameter  )  [private]

It reads from the sensirion.

Parameters:
uint8_t parameter : TEMPERATURE or HUMIDITY
Returns:
the value returned by the sensor

Definition at line 441 of file WaspSensorAgr.cpp.

References B00000011, B00000101, delayMicroseconds(), digitalRead(), digitalWrite(), HIGH, humidity_conversion(), INPUT, LOW, MSBFIRST, OUTPUT, pinMode(), SENS_CLK, SENS_DATA, SENS_PREC_HIGH, SENSIRION_HUM, SENSIRION_TEMP, shiftOut(), and temperature_conversion().

Referenced by readValue().

00442 {
00443         int ack = 0;
00444         int val_read = 0;
00445         int ack2, ack3, i = 0;
00446         
00447         const byte HUMIDITY = B00000101;
00448         const byte TEMPERATURE = B00000011;
00449         
00450         
00451 
00452         if( parameter==SENSIRION_TEMP ) parameter=TEMPERATURE;
00453         else if( parameter==SENSIRION_HUM ) parameter=HUMIDITY;
00454                 
00455   //************************************* 
00456   // PRIMER CICLO DE TRANSMISIÓN (START)
00457   
00458         pinMode(SENS_DATA,  OUTPUT);
00459         pinMode(SENS_CLK, OUTPUT);
00460         digitalWrite(SENS_DATA,  HIGH);
00461         digitalWrite(SENS_CLK, HIGH);
00462         delayMicroseconds(1);
00463         digitalWrite(SENS_DATA,  LOW);
00464         digitalWrite(SENS_CLK, LOW);
00465         delayMicroseconds(1);
00466         digitalWrite(SENS_CLK, HIGH);
00467         digitalWrite(SENS_DATA,  HIGH);
00468         delayMicroseconds(1);
00469         digitalWrite(SENS_CLK, LOW);
00470 
00471   //***************************************
00472   // escribir el comando (los 3 primeros bits deben ser la direccion (siempre 000), y los ultimos 5 bits son el comando)
00473 
00474         shiftOut(SENS_DATA, SENS_CLK, MSBFIRST, parameter);  //parameter: B00000011 para temperatura y B00000101 para Humedad
00475         digitalWrite(SENS_CLK, HIGH);
00476         pinMode(SENS_DATA, INPUT);
00477 
00478         ack = digitalRead(SENS_DATA);
00479         while(ack == HIGH)
00480         {
00481                 ack = digitalRead(SENS_DATA);
00482         }
00483 
00484   
00485         digitalWrite(SENS_CLK, LOW);
00486   
00487         ack = digitalRead(SENS_DATA);
00488         while(ack == LOW)
00489         {
00490                 ack = digitalRead(SENS_DATA);
00491         }
00492   
00493   //****************************************
00494   //Espera a que la conversión esté completa
00495   
00496         ack = digitalRead(SENS_DATA);
00497         while(ack == HIGH)
00498         {
00499                 ack = digitalRead(SENS_DATA);
00500         }
00501   
00502   //*****************************************
00503   //Obtención de los 8 bits más significativos
00504 
00505         for(int i = 0; i < 8; i++)
00506         {
00507                 digitalWrite(SENS_CLK, HIGH);
00508                 val_read = (val_read * 2) + digitalRead(SENS_DATA);
00509                 digitalWrite(SENS_CLK, LOW);
00510         }
00511   
00512         ack = digitalRead(SENS_DATA);
00513         while(ack == LOW)
00514         {
00515                 ack = digitalRead(SENS_DATA);
00516         }
00517   
00518   //****************************************
00519   //ACK del micro
00520         pinMode(SENS_DATA, OUTPUT);
00521         digitalWrite(SENS_DATA, LOW);
00522         delayMicroseconds(1);
00523         digitalWrite(SENS_CLK, HIGH);
00524         delayMicroseconds(400);
00525         digitalWrite(SENS_CLK, LOW);
00526         pinMode(SENS_DATA, INPUT);
00527   
00528   
00529   //***************************************
00530   //Lectura de los 8 bits menos significativos
00531   
00532         for(int i = 0; i < 8; i++)
00533         {
00534                 digitalWrite(SENS_CLK, HIGH);
00535                 val_read = val_read * 2 + digitalRead(SENS_DATA);
00536                 digitalWrite(SENS_CLK, LOW);
00537         }
00538   
00539   //**************************************
00540   //Prescindimos del byte CRC  
00541   
00542         pinMode(SENS_DATA, OUTPUT);
00543         digitalWrite(SENS_DATA, HIGH);
00544         digitalWrite(SENS_CLK, HIGH);
00545         delayMicroseconds(400);
00546         digitalWrite(SENS_CLK, LOW);
00547   
00548         if( parameter==TEMPERATURE ) return temperature_conversion(val_read,SENS_PREC_HIGH);
00549         else if( parameter==HUMIDITY ) return humidity_conversion(val_read,SENS_PREC_HIGH);
00550 
00551         digitalWrite(SENS_DATA, LOW);
00552         
00553 
00554 } 

Here is the call graph for this function:

Here is the caller graph for this function:

uint16_t WaspSensorAgr::readPluviometer (  )  [private]

It reads from the pluviometer.

Returns:
the value returned by the sensor

Definition at line 602 of file WaspSensorAgr.cpp.

References delay(), DIGITAL2, digitalRead(), and millis().

Referenced by readValue().

00603 {
00604         int reading_pluviometer = 0;
00605         int previous_reading_pluviometer = 0;
00606         int value_pluviometer = 0;
00607         unsigned long start_pluviometer=0;
00608 
00609         value_pluviometer = 0;
00610         start_pluviometer = millis();
00611         while((millis()-start_pluviometer)<=3000)
00612         {
00613                 previous_reading_pluviometer = reading_pluviometer;
00614                 reading_pluviometer = digitalRead(DIGITAL2);
00615     
00616                 if((previous_reading_pluviometer == 1)&&(reading_pluviometer == 0))
00617                 {
00618                         value_pluviometer++;
00619                 }
00620         }
00621         delay(100);
00622   
00623         return value_pluviometer;
00624 }

Here is the call graph for this function:

Here is the caller graph for this function:

float WaspSensorAgr::conversion ( byte  data_input[3],
uint8_t  type 
) [private]

It converts data.

Parameters:
byte data_input : the data to convert
uint8_t type : temperature(1) or dendrometer(0)
Returns:
the value converted

Definition at line 647 of file WaspSensorAgr.cpp.

References B00000001, B00000011, and B00111111.

Referenced by readDendrometer(), and readPT1000().

00648 {
00649         long val = 0;
00650         float val_def = 0;
00651         int signo = 0;
00652         int overflow = 0;
00653         float Vcc = 3.3;
00654         float R1           = 1005.0; 
00655         float R2           = 1005.0;
00656         float R3           = 1005.0;
00657         float Rx           = 0.0;
00658         float tempPt       = 0.0;
00659         float equis        = 0.0;
00660   
00661         signo = int(data_input[0] >> 7);
00662         overflow = int((data_input[0] >> 6)&B00000001);
00663 
00664         val = long((data_input[2] >> 6)&B00000011) + long(data_input[1])*4 + long((data_input[0])&B00111111)*1024;
00665 
00666   
00667         if (signo == 1)
00668         {
00669                 if (overflow == 1)
00670                 {
00671       //OVERFLOW High
00672                         val_def = 2;
00673                 }
00674                 else
00675                 {
00676                         val_def = val*1.5;
00677                         val_def = val_def/65535;
00678                 }
00679         }
00680         else
00681         {
00682                 if (overflow == 0)
00683                 {
00684       //OVERFLOW LOW
00685                         val_def = -2;
00686                 }
00687                 else
00688                 {
00689                         val_def = -(65535 - val)*1.5;
00690                         val_def = val_def/65535;
00691                 }
00692         }
00693 
00694         if( type==1 ){
00695                 Rx = (Vcc*R2*R3 + val_def*R3*(R1+R2)) / (Vcc*R1 - val_def*(R1+R2));
00696                 equis = (Rx - 1001.52) / 1351.99;
00697                 Rx = equis * 1494.46 + 996.04;
00698                 tempPt = (Rx-1000)/3.9083;
00699                 return(tempPt);
00700         }
00701         else if( type==0) return ( (val_def * 11000)/1000.0 );
00702 }

Here is the caller graph for this function:

float WaspSensorAgr::pressure_conversion ( int  readValue  )  [private]

It converts pressure.

Parameters:
int readValue : the data to convert
Returns:
the value converted

Definition at line 706 of file WaspSensorAgr.cpp.

Referenced by readValue().

00707 {
00708         float pressure = 0;
00709    
00710         pressure = float(readValue) * 5000 / 1023;
00711    
00712         pressure = (((pressure + 270) / 5000) + 0.095 ) / 0.0088;
00713    
00714         return(pressure);
00715 }

Here is the caller graph for this function:

float WaspSensorAgr::lws_conversion ( int  readValue  )  [private]

It converts leaf wetness.

Parameters:
int readValue : the data to convert
Returns:
the value converted

Definition at line 717 of file WaspSensorAgr.cpp.

00718 {
00719         float lws = 0;
00720    
00721         lws = float(readValue) * 3.3 / 1023;
00722    
00723         return(lws);
00724    
00725 }

float WaspSensorAgr::humidity_conversion ( int  readValue  )  [private]

It converts humidity.

Parameters:
int readValue : the data to convert
Returns:
the value converted

Definition at line 727 of file WaspSensorAgr.cpp.

Referenced by readSensirion().

00728 {
00729         float humidity = 0;
00730    
00731         humidity = float(readValue) * 5000 / 1023;
00732    
00733         humidity = (humidity - 800) / 31;
00734    
00735         return(humidity);
00736    
00737 }

Here is the caller graph for this function:

float WaspSensorAgr::temperature_conversion ( int  readValue  )  [private]

It converts temperature.

Parameters:
int readValue : the data to convert
Returns:
the value converted

Definition at line 739 of file WaspSensorAgr.cpp.

Referenced by readSensirion().

00740 {
00741         float temperature = 0;
00742    
00743         temperature = float(readValue) * 3300 / 1023;
00744    
00745         temperature = (temperature - 500) / 10;
00746    
00747         return(temperature);
00748    
00749 }

Here is the caller graph for this function:

void WaspSensorAgr::getVaneDirection ( float  vane  )  [private]

It gets the direction of the wind.

Parameters:
float vane : the voltage got from the vane
Returns:
nothing

Definition at line 751 of file WaspSensorAgr.cpp.

References SENS_AGR_VANE_E, SENS_AGR_VANE_ENE, SENS_AGR_VANE_ESE, SENS_AGR_VANE_N, SENS_AGR_VANE_NE, SENS_AGR_VANE_NNE, SENS_AGR_VANE_NNW, SENS_AGR_VANE_NW, SENS_AGR_VANE_S, SENS_AGR_VANE_SE, SENS_AGR_VANE_SSE, SENS_AGR_VANE_SSW, SENS_AGR_VANE_SW, SENS_AGR_VANE_W, SENS_AGR_VANE_WNW, SENS_AGR_VANE_WSW, and vane_direction.

Referenced by readValue().

00752 {
00753         if( vane<0.25 ) vane_direction=SENS_AGR_VANE_ESE;
00754         else if( vane>=0.25 && vane<0.28 ) vane_direction=SENS_AGR_VANE_ENE;
00755         else if( vane>=0.28 && vane<0.35 ) vane_direction=SENS_AGR_VANE_E;
00756         else if( vane>=0.35 && vane<0.5 ) vane_direction=SENS_AGR_VANE_SSE;
00757         else if( vane>=0.5 && vane<0.65 ) vane_direction=SENS_AGR_VANE_SE;
00758         else if( vane>=0.65 && vane<0.85 ) vane_direction=SENS_AGR_VANE_SSW;
00759         else if( vane>=0.85 && vane<1.1 ) vane_direction=SENS_AGR_VANE_S;
00760         else if( vane>=1.1 && vane<1.38 ) vane_direction=SENS_AGR_VANE_NNE;
00761         else if( vane>=1.38 && vane<1.6 ) vane_direction=SENS_AGR_VANE_NE;
00762         else if( vane>=1.6 && vane<1.96 ) vane_direction=SENS_AGR_VANE_WSW;
00763         else if( vane>=1.96 && vane<2.15 ) vane_direction=SENS_AGR_VANE_SW;
00764         else if( vane>=2.15 && vane<2.35 ) vane_direction=SENS_AGR_VANE_NNW;
00765         else if( vane>=2.35 && vane<2.6 ) vane_direction=SENS_AGR_VANE_N;
00766         else if( vane>=2.6 && vane<2.8 ) vane_direction=SENS_AGR_VANE_WNW;
00767         else if( vane>=2.8 && vane<3.1 ) vane_direction=SENS_AGR_VANE_W;
00768         else if( vane>=3.1 ) vane_direction=SENS_AGR_VANE_NW;
00769 }

Here is the caller graph for this function:

float WaspSensorAgr::temperature_conversion ( int  readValue,
int  precision 
) [private]

It converts the temperature returned by sensirion.

Parameters:
int readValue : value returned by sensirion
int precision : precission bits
Returns:
the converted value

Definition at line 556 of file WaspSensorAgr.cpp.

References SENS_PREC_HIGH, and SENS_PREC_LOW.

00557 {
00558         float temperature = 0;
00559         float d1 = -39.7;
00560         float d2 = 0;
00561         
00562         float aux=0;
00563   
00564         switch(precision)
00565         {
00566                 case SENS_PREC_HIGH:    d2 = 0.01;
00567                                         temperature = d1 + (d2 * float(readValue));
00568                                         break;    
00569                 case SENS_PREC_LOW:     d2 = 0.04;
00570                                         temperature = d1 + (d2 * float(readValue));
00571                                         break;
00572         }
00573   
00574         return(temperature);
00575 }

float WaspSensorAgr::humidity_conversion ( int  readValue,
int  precision 
) [private]

It converts the humidity returned by sensirion.

Parameters:
int readValue : value returned by sensirion
int precision : precission bits
Returns:
the converted value

Definition at line 578 of file WaspSensorAgr.cpp.

References SENS_PREC_HIGH, and SENS_PREC_LOW.

00579 {
00580         float humidity = 0;
00581         float c1 = -2.0468;
00582         float c2 = 0;
00583         float c3 = 0;
00584   
00585         switch(precision)
00586         {
00587                 case SENS_PREC_HIGH:    c2 = 0.0367;
00588                                         c3 = -1.5955e-6;
00589                                         humidity = c1 + (c2 * float(readValue)) + (c3 * float(readValue) * float(readValue));
00590                                         break;
00591 
00592                 case SENS_PREC_LOW:     c2 = 0.5872;
00593                                         c3 = -4.0845e-4;
00594                                         humidity = c1 + (c2 * float(readValue)) + (c3 * float(readValue) * float(readValue));
00595                                         break;
00596 
00597         }
00598   
00599         return(humidity);
00600 }

float WaspSensorAgr::sencera_conversion ( int  readValue  )  [private]

It converts the humidity returned by sencera.

Parameters:
int readValue : value returned by sencera
Returns:
the converted value

Definition at line 771 of file WaspSensorAgr.cpp.

Referenced by readValue().

00772 {
00773         float humidity = 0;
00774    
00775         humidity = float(readValue) * 5000 / 1023;
00776    
00777         humidity = (humidity - 800) / 31;
00778    
00779         return(humidity);
00780    
00781 }

Here is the caller graph for this function:

float WaspSensorAgr::mcp_conversion ( int  readValue  )  [private]

It converts the temperature returned by mcp.

Parameters:
int readValue : value returned by mcp
Returns:
the converted value

Definition at line 783 of file WaspSensorAgr.cpp.

Referenced by readValue().

00784 {
00785         float temperature = 0;
00786    
00787         temperature = float(readValue) * 3300 / 1023;
00788    
00789         temperature = (temperature - 500) / 10;
00790    
00791         return(temperature);
00792    
00793 }

Here is the caller graph for this function:

void WaspSensorAgr::setBoardMode ( uint8_t  mode  ) 

It sets board power mode, setting ON/OFF 3v3 and 5V switches.

Parameters:
uint8_t mode : SENS_ON or SENS_OFF
Returns:
void

Definition at line 60 of file WaspSensorAgr.cpp.

References delay(), digitalWrite(), HIGH, LOW, RTC, RTC_ON, SENS_OFF, SENS_ON, SENS_PW_3V3, SENS_PW_5V, and WaspRTC::setMode().

00061 {
00062         delay(1000);
00063         
00064         //FIXME
00065 //      digitalWrite(SENS_SWITCH_3,HIGH);
00066         
00067         switch( mode )
00068         {
00069                 case    SENS_ON :       digitalWrite(SENS_PW_3V3,HIGH);
00070                                         digitalWrite(SENS_PW_5V,HIGH);
00071                                         // Sets RTC on to enable I2C
00072                                         RTC.setMode(RTC_ON);
00073                                         break;
00074                 case    SENS_OFF:       digitalWrite(SENS_PW_3V3,LOW);
00075                                         digitalWrite(SENS_PW_5V,LOW);
00076                                         break;
00077         }
00078 }

Here is the call graph for this function:

void WaspSensorAgr::setSensorMode ( uint8_t  mode,
uint16_t  sensor 
)

It sets ON/OFF the different sensor switches.

Parameters:
uint8_t mode : SENS_ON or SENS_OFF
uint16_t sensor : the sensor to set ON/OFF
Returns:
void

Definition at line 81 of file WaspSensorAgr.cpp.

References digitalWrite(), HIGH, LOW, SENS_AGR_ANEMOMETER, SENS_AGR_DENDROMETER, SENS_AGR_HUMIDITY, SENS_AGR_LEAF_WETNESS, SENS_AGR_PRESSURE, SENS_AGR_PT1000, SENS_AGR_RADIATION, SENS_AGR_SENSIRION, SENS_AGR_TEMPERATURE, SENS_AGR_VANE, SENS_AGR_WATERMARK_1, SENS_AGR_WATERMARK_2, SENS_AGR_WATERMARK_3, SENS_OFF, SENS_ON, SENS_SWITCH_1, SENS_SWITCH_2, SENS_SWITCH_3, and SENS_SWITCH_4.

00082 {       
00083         if( mode==SENS_ON )
00084         {
00085                 switch( sensor )
00086                 {
00087                         case    SENS_AGR_PRESSURE:      digitalWrite(SENS_SWITCH_1,HIGH);
00088                                                         break;
00089                         case    SENS_AGR_WATERMARK_1:   digitalWrite(SENS_SWITCH_2,HIGH);
00090                                                         break;
00091                         case    SENS_AGR_WATERMARK_2:   digitalWrite(SENS_SWITCH_2,HIGH);
00092                                                         break;
00093                         case    SENS_AGR_WATERMARK_3:   digitalWrite(SENS_SWITCH_2,HIGH);
00094                                                         break;                          
00095                         case    SENS_AGR_ANEMOMETER:    digitalWrite(SENS_SWITCH_3,HIGH);
00096                                                         break;
00097                         case    SENS_AGR_VANE   :       digitalWrite(SENS_SWITCH_3,HIGH);
00098                                                         break;
00099                         case    SENS_AGR_DENDROMETER:   digitalWrite(SENS_SWITCH_4,HIGH);
00100                                                         break;
00101                         case    SENS_AGR_PT1000 :       digitalWrite(SENS_SWITCH_4,HIGH);
00102                                                         break;
00103                         case    SENS_AGR_LEAF_WETNESS:  digitalWrite(SENS_SWITCH_4,HIGH);
00104                                                         break;
00105                         case    SENS_AGR_TEMPERATURE:   digitalWrite(SENS_SWITCH_4,HIGH);
00106                                                         break;
00107                         case    SENS_AGR_HUMIDITY:      digitalWrite(SENS_SWITCH_4,HIGH);
00108                                                         break;
00109                         case    SENS_AGR_RADIATION:     digitalWrite(SENS_SWITCH_4,HIGH);
00110                                                         break;
00111                         case    SENS_AGR_SENSIRION:     digitalWrite(SENS_SWITCH_4,HIGH);
00112                                                         break;
00113                 }
00114         }
00115         
00116         if( mode==SENS_OFF )
00117         {
00118                 switch( sensor )
00119                 {
00120                         case    SENS_AGR_PRESSURE:      digitalWrite(SENS_SWITCH_1,LOW);
00121                                                         break;
00122                         case    SENS_AGR_WATERMARK_1:   digitalWrite(SENS_SWITCH_2,LOW);
00123                                                         break;
00124                         case    SENS_AGR_WATERMARK_2:   digitalWrite(SENS_SWITCH_2,LOW);
00125                                                         break;
00126                         case    SENS_AGR_WATERMARK_3:   digitalWrite(SENS_SWITCH_2,LOW);
00127                                                         break;                          
00128                         case    SENS_AGR_ANEMOMETER:    digitalWrite(SENS_SWITCH_3,LOW);
00129                                                         break;
00130                         case    SENS_AGR_VANE   :       digitalWrite(SENS_SWITCH_3,LOW);
00131                                                         break;
00132                         case    SENS_AGR_DENDROMETER:   digitalWrite(SENS_SWITCH_4,LOW);
00133                                                         break;
00134                         case    SENS_AGR_PT1000 :       digitalWrite(SENS_SWITCH_4,LOW);
00135                                                         break;
00136                         case    SENS_AGR_LEAF_WETNESS:  digitalWrite(SENS_SWITCH_4,LOW);
00137                                                         break;
00138                         case    SENS_AGR_TEMPERATURE:   digitalWrite(SENS_SWITCH_4,LOW);
00139                                                         break;
00140                         case    SENS_AGR_HUMIDITY:      digitalWrite(SENS_SWITCH_4,LOW);
00141                                                         break;
00142                         case    SENS_AGR_RADIATION:     digitalWrite(SENS_SWITCH_4,LOW);
00143                                                         break;
00144                         case    SENS_AGR_SENSIRION:     digitalWrite(SENS_SWITCH_4,LOW);
00145                                                         break;
00146                 }
00147         }
00148 }

Here is the call graph for this function:

float WaspSensorAgr::readValue ( uint16_t  sensor  ) 

It reads the value measured by the sensor.

Parameters:
uint16_t sensor : the sensor to read the value from
Returns:
the value measured by the sensor (range [0-3.3] Volts)

Definition at line 151 of file WaspSensorAgr.cpp.

00152 {
00153         return readValue(sensor,0);
00154 }

float WaspSensorAgr::readValue ( uint16_t  sensor,
uint8_t  type 
)

It reads the value measured by the sensor.

Parameters:
uint16_t sensor : the sensor to read the value from
uint8_t type : the type to read
Returns:
the value measured by the sensor (range [0-3.3] Volts)

Definition at line 157 of file WaspSensorAgr.cpp.

References ANALOG2, ANALOG3, ANALOG4, ANALOG5, ANALOG6, ANALOG7, analogRead(), digitalWrite(), getVaneDirection(), HIGH, LOW, mcp_conversion(), pressure_conversion(), readDendrometer(), readPluviometer(), readPT1000(), readRadiation(), readSensirion(), readWatermark(), sencera_conversion(), SENS_AGR_ANEMOMETER, SENS_AGR_DENDROMETER, SENS_AGR_HUMIDITY, SENS_AGR_LEAF_WETNESS, SENS_AGR_PLUVIOMETER, SENS_AGR_PRESSURE, SENS_AGR_PT1000, SENS_AGR_RADIATION, SENS_AGR_SENSIRION, SENS_AGR_TEMPERATURE, SENS_AGR_VANE, SENS_AGR_WATERMARK_1, SENS_AGR_WATERMARK_2, SENS_AGR_WATERMARK_3, SENS_MUX_SEL, SENSIRION_HUM, and SENSIRION_TEMP.

00158 {
00159         float aux=0;
00160         uint16_t aux2=0;
00161         
00162         switch( sensor )
00163         {
00164                 case    SENS_AGR_PRESSURE:      aux2=analogRead(ANALOG3);
00165                                                 aux=pressure_conversion(aux2); // KPa
00166                                                 break;
00167                 case    SENS_AGR_WATERMARK_1:   aux=readWatermark(SENS_AGR_WATERMARK_1); // 50Hz - 200cbar || 10KHz - 0cbar
00168                                                 break;
00169                 case    SENS_AGR_WATERMARK_2:   aux=readWatermark(SENS_AGR_WATERMARK_2); // 50Hz - 200cbar || 10KHz - 0cbar
00170                                                 break;
00171                 case    SENS_AGR_WATERMARK_3:   aux=readWatermark(SENS_AGR_WATERMARK_3); // 50Hz - 200cbar || 10KHz - 0cbar
00172                                                 break;
00173                 case    SENS_AGR_ANEMOMETER:    aux2=analogRead(ANALOG7);
00174                                                 aux = float(aux2) * 3.3 * 2.4 / (1023*0.03); // km/h
00175                                                 break;
00176                 case    SENS_AGR_VANE   :       aux2=analogRead(ANALOG5);
00177                                                 aux=(aux2*3.3)/1023; // Volts
00178                                                 getVaneDirection(aux); // Direction
00179                                                 break;
00180                 case    SENS_AGR_DENDROMETER:   aux=readDendrometer(); //mm
00181                                                 break;
00182                 case    SENS_AGR_PT1000 :       aux=readPT1000(); // º Celsius
00183                                                 break;
00184                 case    SENS_AGR_LEAF_WETNESS:  digitalWrite(SENS_MUX_SEL,HIGH); // Volts
00185                                                 aux2=analogRead(ANALOG6);
00186                                                 aux=(aux2*3.3)/1023;
00187                                                 digitalWrite(SENS_MUX_SEL, LOW);
00188                                                 break;
00189                 case    SENS_AGR_TEMPERATURE:   digitalWrite(SENS_MUX_SEL,HIGH);
00190                                                 aux2=analogRead(ANALOG4);
00191                                                 aux=mcp_conversion(aux2); // ºCelsius
00192                                                 digitalWrite(SENS_MUX_SEL, LOW);
00193                                                 break;
00194                 case    SENS_AGR_HUMIDITY:      digitalWrite(SENS_MUX_SEL,HIGH);
00195                                                 aux2=analogRead(ANALOG2);
00196                                                 aux=sencera_conversion(aux2); // %Hum
00197                                                 digitalWrite(SENS_MUX_SEL, LOW);
00198                                                 break;
00199                 case    SENS_AGR_RADIATION:     aux=readRadiation(); //mV
00200                                                 break;
00201                 case    SENS_AGR_SENSIRION:     if( type==SENSIRION_TEMP ) aux=readSensirion(SENSIRION_TEMP); // ºCelsius
00202                                                 else if( type==SENSIRION_HUM ) aux=readSensirion(SENSIRION_HUM);// %Hum
00203                                                 break;
00204                 case    SENS_AGR_PLUVIOMETER:   aux2=readPluviometer();
00205                                                 aux=float(aux2) * 0.2794 * 20; // mm/min
00206                                                 break;  
00207         }
00208         return  aux;
00209 }

Here is the call graph for this function:

void WaspSensorAgr::setAnemometerThreshold ( float  threshold  ) 

It sets threshold configuring digipots.

Parameters:
uint8_t sensor : specifies the socket to set the threshold to ('SENS_SOCKETX')
float threshold : the threshold to set (0-3.3V)
Returns:
void

Definition at line 216 of file WaspSensorAgr.cpp.

References setDigipot().

00217 {
00218         threshold =  threshold*0.03/(2.4);
00219         setDigipot(threshold);
00220 }

Here is the call graph for this function:

void WaspSensorAgr::sleepAgr ( const char *  time2wake,
uint8_t  offset,
uint8_t  mode,
uint8_t  option 
)

It sleeps Waspmote enabling the switches required for the agriculture board.

Parameters:
const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss"
uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE
uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5
uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF
Returns:
void

Definition at line 254 of file WaspSensorAgr.cpp.

00255 {
00256         sleepAgr(time2wake, offset, mode, option, 0);
00257 }

void WaspSensorAgr::sleepAgr ( const char *  time2wake,
uint8_t  offset,
uint8_t  mode,
uint8_t  option,
uint8_t  agr_interrupt 
)

It sleeps Waspmote enabling the switches required for the agriculture board.

Parameters:
const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss"
uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE
uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5
uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF
uint8_t agr_interrupt : specifies the sensor we are enabling before going sleep (Anemometer and Pluviometer)
Returns:
void

Definition at line 259 of file WaspSensorAgr.cpp.

References ANE_INT, WaspRTC::close(), digitalWrite(), enableInterrupts(), HIGH, LOW, PLV_INT, PWR, RTC, SENS_AGR_ANEMOMETER, SENS_AGR_PLUVIOMETER, SENS_DATA, SENS_MUX_SEL, SENS_SWITCH_1, SENS_SWITCH_2, SENS_SWITCH_3, SENS_SWITCH_4, WaspRTC::setAlarm1(), WaspPWR::switchesOFF(), and WaspPWR::switchesON().

00260 {
00261         // Set RTC alarme to wake up from Sleep Power Down Mode
00262         RTC.setAlarm1(time2wake,offset,mode);
00263         RTC.close();
00264         digitalWrite(SENS_SWITCH_1, LOW);
00265         digitalWrite(SENS_SWITCH_2, LOW);
00266         digitalWrite(SENS_SWITCH_4, LOW);
00267         digitalWrite(SENS_MUX_SEL, LOW);
00268         digitalWrite(SENS_DATA, LOW);
00269 
00270         PWR.switchesOFF(option);
00271 
00272         if (agr_interrupt && SENS_AGR_ANEMOMETER)
00273         {
00274                 digitalWrite(SENS_SWITCH_3, HIGH);
00275                 enableInterrupts(ANE_INT);
00276         }
00277         else
00278         {
00279                 digitalWrite(SENS_SWITCH_3, LOW);
00280         }
00281 
00282         if (agr_interrupt && SENS_AGR_PLUVIOMETER)
00283         {
00284                 enableInterrupts(PLV_INT);
00285         }
00286 
00287 
00288         set_sleep_mode(SLEEP_MODE_PWR_DOWN);
00289         sleep_enable();
00290         sleep_mode();
00291         sleep_disable();
00292         PWR.switchesON(option);
00293 }

Here is the call graph for this function:

void WaspSensorAgr::attachInt ( uint8_t  sens  ) 

It switches off the general switch enabling RTC interruption for the Agriculture Board.

Parameters:
const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss"
uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE
uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5
Returns:
void
See also:
sleep(uint8_t option), sleep(uint8_t timer, uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option)

Definition at line 227 of file WaspSensorAgr.cpp.

References ANE_INT, enableInterrupts(), PLV_INT, SENS_AGR_ANEMOMETER, and SENS_AGR_PLUVIOMETER.

00228 {
00229         switch( sens )
00230         {
00231                 case SENS_AGR_ANEMOMETER:       enableInterrupts(ANE_INT);
00232                                                 break;
00233                 case SENS_AGR_PLUVIOMETER:      enableInterrupts(PLV_INT);
00234                                                 break;
00235         }
00236 }

Here is the call graph for this function:

void WaspSensorAgr::detachInt ( uint8_t  sens  ) 

It attaches the interruption.

Parameters:
uint8_t sens: specifies the sensor (ANEMOMETER or PLUVIOMETER) which detaches the interruption
Returns:
void

Definition at line 243 of file WaspSensorAgr.cpp.

References ANE_INT, disableInterrupts(), PLV_INT, SENS_AGR_ANEMOMETER, and SENS_AGR_PLUVIOMETER.

00244 {
00245         switch( sens )
00246         {
00247                 case SENS_AGR_ANEMOMETER:       disableInterrupts(ANE_INT);
00248                                                 break;
00249                 case SENS_AGR_PLUVIOMETER:      disableInterrupts(PLV_INT);
00250                                                 break;
00251         }
00252 }

Here is the call graph for this function:


Field Documentation

Variable : specifies the wind direction.

Definition at line 394 of file WaspSensorAgr.h.

Referenced by getVaneDirection().


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

Generated on Tue Jul 20 09:31:03 2010 for WaspmoteAPI by  doxygen 1.5.6