Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ds18b20 to 12bit resolution and add compiled version for SolarPV RFM69 native #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions firmware/SolarPV_rfm69/SolarPV_rfm69.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ GLCD_ST7565 glcd;
#include <DallasTemperature.h> // http://download.milesburton.com/Arduino/MaximTemperature/ (3.7.2 Beta needed for Arduino 1.0)
#include <RTClib.h> // Real time clock (RTC) - used for software RTC to reset kWh counters at midnight
#include <Wire.h> // Part of Arduino libraries - needed for RTClib
#include <avr/wdt.h>
RTC_Millis RTC;

//--------------------------------------------------------------------------------------------
// RF Settings
//--------------------------------------------------------------------------------------------
#define MYNODE 20 // Should be unique on network, node ID 30 reserved for base station
#define MYNODE 21 // Should be unique on network, node ID 30 reserved for base station
//#define RF_freq RF12_433MHZ // frequency - match to same frequency as RFM12B module (change to 868Mhz or 915Mhz if appropriate)
#define group 210 // network group, must be same as emonTx and emonBase
#define EMONPI 5 //id of EMONPI base (where transmissions come from)
Expand Down Expand Up @@ -176,14 +177,16 @@ double use_history[7], gen_history[7];
#define ONE_WIRE_BUS 5 // temperature sensor connection - hard wired
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
double intemp, outtemp, maxtemp, mintemp;
double intemp, outtemp, maxtemp, mintemp = -127;


//--------------------------------------------------------------------------------------------
// Flow control
//--------------------------------------------------------------------------------------------
unsigned long last_emontx; // Used to count time from last emontx update
unsigned long last_emonbase; // Used to count time from last emontx update
unsigned long last_emonbase; // Used to count time from last emonpi update
unsigned long last_wx; // Used to count time from last WC update

boolean last_switch_state, switch_state;
unsigned long fast_update, slow_update;

Expand All @@ -192,16 +195,26 @@ unsigned long fast_update, slow_update;
//--------------------------------------------------------------------------------------------
void setup()
{
delay(500); //wait for power to settle before firing up the RF


DeviceAddress insideThermometer ;


delay(200); //wait for power to settle before firing up the RF

wdt_enable(WDTO_8S) ;

rf.init(MYNODE, 210, 434);
delay(100); //wait for RF to settle befor turning on display
glcd.begin(0x19);
glcd.backLight(200);

sensors.begin(); // start up the DS18B20 temp sensor onboard
sensors.getAddress(insideThermometer, 0);
sensors.setResolution(insideThermometer, 12);
sensors.requestTemperatures();
intemp = (sensors.getTempCByIndex(0)); // get inital temperture reading
mintemp = intemp; maxtemp = intemp; // reset min and max
outtemp = -127 ;

pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
Expand All @@ -211,8 +224,8 @@ void setup()
digitalWrite(switch1, HIGH); digitalWrite(switch2, HIGH); digitalWrite(switch3, HIGH);
#endif

//Set Date to a reasonable default (midnight, Jan1, 2020)
RTC.adjust(DateTime(2020, 1, 1, 0, 0, 0));
//Set Date to a reasonable default (midnight, Jan1, 2022)
RTC.adjust(DateTime(2022, 1, 1, 0, 0, 0));
}

//--------------------------------------------------------------------------------------------
Expand All @@ -228,7 +241,7 @@ void loop()
byte sender = nativeMsg[1];

#ifdef EMONTX
if (sender == EMONTX && len == sizeOf(emonTx) ) {
if (sender == EMONTX && len == sizeOf(emontx) ) {
memcpy (rfdata, nativeMsg, len) ;
emontx = *(PayloadTX*) rfdata;
last_emontx = millis();
Expand All @@ -242,7 +255,8 @@ void loop()
#else
//Sanity with an EMONPI :)

if (sender == EMONPI && nativeMsg[2] == 0x0A) {
if (sender == EMONPI && nativeMsg[2] == 0x0A && len == sizeof(emontx) ) {

//this packet is for us
memcpy (rfdata, nativeMsg, len) ;
emontx = *(PayloadTX*) rfdata;
Expand All @@ -256,10 +270,14 @@ void loop()
#endif

//sniff my weather station packet to get external temperature displayed
//rf.receive will only send broadcast packets (dest=0) and direct packets for reception (dest=this nodeId)
//wx packets are broadcast, dest=0
if ( len == sizeof(wx)) {
memcpy (rfdata, nativeMsg, len) ;
wx = *(wh1050Payload*) rfdata;
outtemp = wx.tempC ;
last_wx = millis();

}

} // if len>0
Expand All @@ -272,6 +290,12 @@ void loop()
//--------------------------------------------------------------------------------------------
if ((millis() - fast_update) > 200)
{

if (last_wx + 120000 < millis()) {
outtemp = -127;
}


fast_update = millis();

DateTime now = RTC.now();
Expand Down Expand Up @@ -370,7 +394,9 @@ void loop()
int LDR = analogRead(LDRpin); // Read the LDR Value so we can work out the light level in the room.
int LDRbacklight = map(LDR, 0, 1023, 1, 250); // Map the data from the LDR from 0-1023 (Max seen 1000) to var GLCDbrightness min/max
LDRbacklight = constrain(LDRbacklight, 0, 255); // Constrain the value to make sure its a PWM value 0-255
if ((hour > 23) || (hour < 6)) glcd.backLight(0); else

//Turn backlight off from 2100 - 0800
if ((hour >= 21) || (hour <= 8)) glcd.backLight(0); else
glcd.backLight(LDRbacklight);

int PWRleds = 0 ;
Expand Down Expand Up @@ -420,4 +446,7 @@ void loop()


}

wdt_reset();

}
Loading