//***************************************************** //RFM12B OKK sections taken from the original Jeenode OKK Raw example //Tested with Arduino 0021 // polling RFM12B to decode FSK iT+ with a Jeenode from Jeelabs. // device : iT+ TX29IT 04/2010 v36 D1 LA Crosse Technology (c) // info : http://forum.jeelabs.net/node/110 // http://fredboboss.free.fr/tx29/tx29_sw.php // http://www.f6fbb.org/domo/sensors/ // benedikt.k http://www.mikrocontroller.net/topic/67273 // rinie,marf,joop 1 nov 2011 // ***************************************************** // * Resouces used:- // *http://www.susa.net/wordpress/2012/08/raspberry-pi-reading-wh1081-weather-sensors-using-an-rfm01-and-rfm12b/ // * jeenode_lacross_rx by Rufik // ***************************************************** // 09/01/2013 V 1.10 Initial WH1080 fine offset Arduino decoder // by Steve Pyle //****************************************************** //************ Change log **************** //Added Baro - BMP05 as per Adafruit //Need to add Battery Status in progress //Need to add windchill Status // ***************************************************** #include #include #include "Arduino.h" #include #include #define clrb(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #define setb(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #define RF_PORT PORTB #define RF_DDR DDRB #define RF_PIN PINB #define SDI 3 #define SCK 5 #define CS 2 #define SDO 4 #define CRC_POLY 0x31 // CRC-8 = 0x31 is for: x8 + x5 + x4 + 1 #define DEBUG 0 // set to 1 to see debug messages #define I2C 1 // use i2c bus for BMP085 and SHT21 int frame; int device_id; int temperature_raw; float temperature; int humidity; float wind_avg_ms; float wind_avg_mph; int wind_avg_raw; int wind_gust_raw; float wind_gust_ms; float wind_gust_mph; float rain; int rain_raw; int wind_direction; float pressure; float readPressure; int MSB; int LSB; String s; char sign; int Bat; Adafruit_BMP085 bmp; char *direction_name[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"}; //Receive message, data[] void receive(unsigned int *data) { unsigned char mesage[20]; if (DEBUG) { Serial.println("Listening...."); } rf12_rxdata(mesage,20); if (DEBUG) { Serial.print("Received HEX raw data: "); for (int i=0; i<20; i++) { // for(uint8_t i = 0; i<20; i++) Serial.print(mesage[i], HEX); Serial.print(" "); } Serial.println(); } //Write message into table // for(uint8_t i = 0; i<20; i++) for (int i=0; i<20; i++) { //20 data[i] = (unsigned int) mesage[i]; } } // Calculate CRC static uint8_t compute_crc(uint8_t b) { uint8_t do_xor; uint8_t reg; reg = 0; do_xor = (reg & 0x80); reg <<=1; reg |= b; if (do_xor) { reg ^= CRC_POLY; } return reg; } //check if CRC is OK boolean is_crc_valid(unsigned int crcByte) { boolean result = false; uint8_t crc_computed = compute_crc((uint8_t) crcByte); if ((unsigned int) crc_computed == crcByte) { result = true; if (DEBUG) { Serial.print("CRC OK: "); Serial.println(crc_computed, HEX); } } else { if (DEBUG) { Serial.print("CRC Error... Calculated is "); Serial.print(crc_computed, HEX); Serial.print(" Received is "); Serial.println(crcByte, HEX); } } return result; } //Check device ID starts with A7 (My WH1080 stn ID) boolean is_msg_valid(unsigned int msgFirstByte) { boolean result = false; unsigned int msgFlag = (msgFirstByte); // was & 240) >> 4; if (msgFlag == 167) { result = true; if (DEBUG) { Serial.println("OK"); } } else { if (DEBUG) { Serial.print("Msg does not start with A7, it's: "); Serial.println(msgFlag, HEX);} } return result; } void rf12_rxdata(unsigned char *data, unsigned char number) { uint8_t i; rf12_xfer(0x82C8); // receiver on rf12_xfer(0xCA81); // set FIFO mode rf12_xfer(0xCA83); // enable FIFO for (i=0; i> 4)); // temperature_raw = ((frame[1] & 0x0f) << 8) | (frame[2]); temperature_raw= ((frame[1] & 0x07) << 8) + frame[2]; MSB = temperature_raw / 10; LSB = temperature_raw - (MSB*10); if (frame[1] & 0x08) { sign = '-'; s = String(sign); } else { s = String(); } humidity = frame[3]; wind_avg_raw = frame[4]; wind_avg_ms = ((float)wind_avg_raw * 34.0) / 100; if(DEBUG) { wind_avg_mph = wind_avg_ms * 2.23693629;} wind_gust_raw = frame[5]; wind_gust_ms = ((float)wind_gust_raw * 34.0) / 100; if (DEBUG){ wind_gust_mph = wind_gust_ms * 2.23693629;} rain_raw = ((frame[6] & 0x0f) << 8) | frame[7]; rain = ((float)rain_raw / 0.3); wind_direction = frame[8] & 0x0f; char *direction_str = direction_name[wind_direction]; float pressure = bmp.readPressure(); pressure = pressure / 100; // Bat = frame[8] & 0xf0; if (DEBUG) { Serial.print("ID="); Serial.println(device_id); Serial.print("Temperature="); Serial.print(sign); Serial.print (MSB, DEC); Serial.print ("."); Serial.println(LSB, DEC); Serial.print("Humidity="); Serial.println(humidity); Serial.print("Wind avg="); Serial.print(wind_avg_ms); Serial.print("m/s or "); Serial.print(wind_avg_mph); Serial.println("mph"); Serial.print("Wind Gust="); Serial.print(wind_gust_ms); Serial.print("m/s or "); Serial.print(wind_gust_mph); Serial.println("mph"); Serial.print("Wind Direction="); Serial.println(direction_str); Serial.print("Total rain="); Serial.print(rain,1); Serial.println("mm"); Serial.print("Indoor Temperature="); Serial.println(bmp.readTemperature(),1); //Serial.println(" C"); Serial.print("Pressure="); Serial.print(pressure,1); Serial.println(" hPa"); // Serial.print("Battery Status"); // Serial.print(Bat); Serial.flush(); } // Print raw data to serial port Serial.print(device_id); Serial.print(" "); // Serial.print(sign); Serial.print (MSB, DEC); Serial.print ("."); Serial.print(LSB, DEC); Serial.print (" "); Serial.print(humidity); Serial.print(" "); Serial.print(wind_avg_ms); Serial.print(" "); Serial.print(wind_gust_ms); Serial.print(" "); Serial.print(direction_str); Serial.print(" "); Serial.print(rain,1); Serial.print(" "); Serial.print(bmp.readTemperature(),1); Serial.print(" "); Serial.println(pressure,1); // Serial.print(" "); // Serial.print(Bat); } } }