//***************************************************** //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 0.01 Initial WH1080 fine offset Arduino decoder // by Steve Pyle //****************************************************** //************ To Do / Change log **************** // // // ***************************************************** #include #include "Arduino.h" #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 1 // set to 1 to see debug messages 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; 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 if msg starts with A (WH1080) boolean is_msg_valid(unsigned int msgFirstByte) { boolean result = false; unsigned int msgFlag = (msgFirstByte & 240) >> 4; if (msgFlag == 10) { result = true; if (DEBUG) { Serial.println("OK"); } } else { if (DEBUG) { Serial.print("Msg does not start with A, 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 = (float)temperature_raw / 10 ; humidity = frame[3]; wind_avg_raw = frame[4]; wind_avg_ms = ((float)wind_avg_raw * 34.0) / 100; wind_avg_mph = wind_avg_ms * 2.23693629; wind_gust_raw = frame[5]; wind_gust_ms = ((float)wind_gust_raw * 34.0) / 100; 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]; Serial.print("Id: "); Serial.println(device_id); Serial.print("Temperature: "); Serial.println(temperature); 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); Serial.println("mm"); Serial.flush(); } } }