[code] //-------------------------------------------------------------------------------------- // WeatherDuino Pro2 RF Transmiter // Compatible with Cumulus Weather Software // Boards compatibility   : WeatherDuino TX v2.xx, Board Series   // Software compatibility : WeatherDuino RX v013 series only // // Version: 0.13-b005 // Version Released date: 13/01/2015 // Last revision date   : 10/01/2015 // Licence: GNU GPL // Author : Werk_AG (Portugal) // // I wish to thanks to kevinkessler from http://kesslerarduino.wordpress.com/ // for the base code to read wind and rain sensors. //-------------------------------------------------------------------------------------- #include  // library for RF RX/TX #include  #include  #include  #include "HTU21D.h" // library for HTU21 Temp/Hum Sensor #include             // library for DHTxx #include  #include "RunningAverage.h" #include  // Library to eeprom read and write // -------------------------------------------------------------------------------------- //   User configurable options start here.  // -------------------------------------------------------------------------------------- byte StationID = 0xA1; // Must be equal to your RX Unit (Value from 0x00 to 0xFF) byte UnitID = 1; // If you use only one TX unit define it as UnitID = 0                                 // For a second TX unit, define it as UnitID = 1 // -------  Let's define the data we want to send -------------- //#define ID0 0        // Temp / Hum sensors - 0 for SHT2x sensor, 1 for HTU21 sensor #define ID1 1        // Temp / Hum sensors - 0 for SHT1x sensor, 1 for DHT22 sensor #define ID2          // Wind data #define ID3          // Rain data //#define ID4          // UV / SolRad data #define ID5          // Hardware Status - System Temp, Battery Voltage etc byte fanOn_HiTemp = 32; // RS Fan turn on when outside temperature is >= than this value (ºC) byte fanOn_LowTemp = 3; // RS Fan turn on when outside temperature is <= than this value (ºC) byte fanOn_LowWind = 2; // RS Fan turn on when Wind Average is <= than this value (m/s) // --------------------------------------------------------------------------------------------------- //                       There is nothing to edit below this line !!! // --------------------------------------------------------------------------------------------------- //#define DebugID0 //#define DebugID1 //#define DebugID2 //#define DebugID3 //#define DebugID4 //#define DebugID5 #define Local_TestMode #if ID0 == 1 HTU21D myHTU21; #endif #if ID1 == 0 // Specify data and clock connections and instantiate SHT1x object #define dataPin  6 #define clockPin 9 SHT1x sht1x(dataPin, clockPin); #endif #if ID1 == 1 // DTH22 Data wire is plugged into port 6 on the Arduino // Connect a 10K resistor between VCC and the data pin (strong pullup) #define DHT22_PIN 6 DHTxx dht (DHT22_PIN); #endif // --- Analog Pins --- #define SolarRad_PIN A0 #define IndiceUV_PIN A1 #define BatVolt_PIN A2 #define VANE_PIN A3 #define SysTemp_PIN A7 // --- Digital Pins --- #define RAIN_GAUGE_INT 0 #define ANEMOMETER_INT 1 #define RAIN_GAUGE_PIN 2 #define ANEMOMETER_PIN 3 #define VANE_PWR 4 #define Fan_PIN 5 #define TXPower_PIN 7 #define TX_PIN 8             // Transmitter connected to pin 8 // --- Wind ------------ #define WIND_FACTOR 0.666667          // Factor 2.4 Km/h = 0,66666666666667 M/s #define TEST_PAUSE 30                 // Value for WindAverage - 30 secs volatile unsigned long anem_count = 0; volatile unsigned long anem_last = 0; volatile unsigned long anem_min = 0xffffffff; unsigned int WindAvg, WindGust; unsigned int last_WindGust = 50000; RunningAverage raWindAvg(10); // --- Vane ----------- const int vaneValues[] PROGMEM={66,84,92,127,184,244,287,406,461,600,631,702,786,827,889,946}; const int vaneDirections[] PROGMEM={1125,675,900,1575,1350,2025,1800,225,450,2475,2250,3375,0,2925,3150,2700}; #ifdef Local_TestMode const char vaneDirectionsText[16] [4] = {"N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"}; String winddr; #endif unsigned int WindDir; // --- Rain ----------- //#define RAIN_FACTOR 0.3                           // Datasheet value = 0.2794 const float RAIN_FACTOR = 0.3; // Datasheet value = 0.2794 volatile unsigned long rain_count = 0; volatile unsigned long rain_last = 0; volatile unsigned long RainFall_rate; unsigned int TotalRainTips; unsigned int LastHourRainTips; unsigned int lasthour_TotalRainTips = 0; unsigned int last_TotalRainTips = 0; //float TotalRain; byte Pool_Rain_Interval = 31; //Pool Rain tick counter every 31 seconds byte TotalRainTips_Eeprom_adr = 10; // --------------------- RunningAverage raSolarRad(4); RunningAverage raIndiceUV(4); char DataPacket[32]; byte PacketID; byte RSfan; unsigned int avg_SolarRad, SolarRad, avg_IndiceUV; float IndiceUV; float TotalRain; // Used only in Debug Mode unsigned int BatVolt, SysTempADC; int ID0_TemperaturaExt, ID1_TemperaturaExt; int ID0_HumidadeExt, ID1_HumidadeExt; #ifdef Local_TestMode // ----------   Temp Var for debug --------------------- int DHT_HumidadeInt = 500; int DHT_TemperaturaInt = 200; int DHT_TemperaturaInt_offset = 0.0; float pressure = 100000; float pressure_offset = 0.0; //------------------------------------------------ #endif Timer t; // --------- Soft Reset ------------------------------------------- void(*softReset)(void) = 0; //SoftwareReset vector (goto address 0) // SETUP //-------------------------------------------------------------------------------------- void setup() {  //  erase_eeprom();    //------------------------------------------------------------ // Setup the transmitter //------------------------------------------------------------   vw_set_ptt_pin(TXPower_PIN);   vw_set_tx_pin(TX_PIN);        // Transmitter connected to pin 8   vw_setup(1000);         // Bits per second //------------------------------------------------------------   pinMode(13,OUTPUT);   digitalWrite(13, LOW);   pinMode(Fan_PIN,OUTPUT);   pinMode(TXPower_PIN,OUTPUT);   Wire.begin();   #if ID0 == 1   myHTU21.begin();   #endif     #ifdef Local_TestMode     Serial.begin(19200);     t.every(3050, Cumulus_Output);   #endif   #ifdef ID0   t.every(19000, send_SensorID0);   #endif   #ifdef ID1   t.every(53000, send_SensorID1);   #endif   #ifdef ID2     setupWindInts();   t.every(5000, send_SensorID2); // Send PacketID2. Before sending, call getGust() function   t.every(TEST_PAUSE * 1000, getUnitWind); // Calls Wind Average function +- every TEST_PAUSE seconds   #endif   #ifdef ID3   setupRainInts();   TotalRainTips = eepromReadInt(TotalRainTips_Eeprom_adr);   t.every(Pool_Rain_Interval * 1000, send_SensorID3);   t.every(3600000, TotalRainTips_toEeprom); // Every 1 hours call routine to save Rain Totals to eeprom (Routine only save if value is different from last call)   #endif   #ifdef ID4   t.every(37000, send_SensorID4);   //t.every(5000, send_SensorID4); // For testing...   #endif      #ifdef ID5   t.every(97000, send_SensorID5);   #endif } // MAIN LOOP //-------------------------------------------------------------------------------------- void loop() {       // Reboot if millis is close to rollover. RTC_Millis won't work properly if millis rolls over. Takes 49 days to rollover   if( millis() > 4294000000UL ) softReset();   t.update(); }   // End MAIN LOOP ------------------------------------------------------------------------ [/code]