Advertisement
Guest User

Untitled

a guest
Nov 15th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. /*
  2. Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
  3. RF24 libraries and code
  4. Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
  5. SHT1x library and code
  6. Copyright ???? ???? ???? ???????
  7. DallasTemperature library and code
  8. Copyright 2012 C. LeBlanc <ominously.chaotic@gmail.com>
  9. Mashing it all together
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. version 2 as published by the Free Software Foundation.
  14. */
  15.  
  16. #include <RF24Network.h>
  17. #include <RF24.h>
  18. #include <SPI.h>
  19. #include <LiquidCrystal_I2C.h>
  20. #include <SHT1x.h>
  21. #include <Wire.h>
  22. #include <OneWire.h>
  23. #include <DallasTemperature.h>
  24.  
  25. #define ONE_WIRE_BUS 10 //DS18B20 data to pin 10
  26. #define dataPin 9 //SHT data to pin 9
  27. #define clockPin 8 //SHT clock to pin 8
  28.  
  29. RF24 radio(2,3); // nRF24L01(+) radio CE/CSN to pins 2 and 3
  30. RF24Network network(radio);
  31.  
  32. SHT1x sht1x(dataPin, clockPin);
  33. LiquidCrystal_I2C lcd(0x27,16,2);
  34. OneWire oneWire(ONE_WIRE_BUS);
  35. DallasTemperature sensors(&oneWire);
  36. DeviceAddress insideTemp = {0x28, 0x9B, 0x26, 0xDF, 0x03, 0x00, 0x00, 0x4C};
  37.  
  38. const uint16_t base = 0;
  39. const uint16_t outside = 1;
  40.  
  41. struct payload_t
  42. {
  43. float temp;
  44. float humid;
  45. };
  46.  
  47. void setup(void)
  48. {
  49. sensors.begin();
  50. sensors.setResolution(insideTemp, 10);
  51. SPI.begin();
  52. radio.begin();
  53. network.begin(90, base);
  54. lcd.init();
  55. lcd.backlight();
  56. }
  57.  
  58. void printTemperature(DeviceAddress insideTemp)
  59. {
  60. float humidity = sht1x.readHumidity();
  61. float tempC = sensors.getTempC(insideTemp);
  62. float tempF = DallasTemperature::toFahrenheit(tempC);
  63. sensors.requestTemperatures();
  64. delay(500);
  65. lcd.setCursor(0,0);
  66. lcd.print(tempF);
  67. lcd.print(" F ");
  68. lcd.print(humidity);
  69. lcd.print(" H");
  70.  
  71. }
  72.  
  73. void loop(void)
  74. {
  75. printTemperature(insideTemp);
  76. network.update();
  77. while ( network.available() )
  78. {
  79. RF24NetworkHeader header;
  80. payload_t payload;
  81. network.read(header,&payload,sizeof(payload));
  82. lcd.setCursor(0,1);
  83. lcd.print(payload.temp);
  84. lcd.print(" F ");
  85. lcd.print(payload.humid);
  86. lcd.print(" H");
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement