Merge pull request #123 from Kolbi/development
Some changes for the DallasTemperatureSensors.ino and BatteryPoweredSensor.ino
This commit is contained in:
@@ -30,6 +30,8 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <MySensor.h>
|
#include <MySensor.h>
|
||||||
|
|
||||||
|
#define DEBUG 1 // Debug enables Serial.print 1 = Yes 0 = No
|
||||||
|
|
||||||
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
|
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
|
||||||
|
|
||||||
MySensor gw;
|
MySensor gw;
|
||||||
@@ -50,7 +52,9 @@ void loop()
|
|||||||
{
|
{
|
||||||
// get the battery Voltage
|
// get the battery Voltage
|
||||||
int sensorValue = analogRead(BATTERY_SENSE_PIN);
|
int sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||||
|
#if DEBUG > 0
|
||||||
Serial.println(sensorValue);
|
Serial.println(sensorValue);
|
||||||
|
#endif
|
||||||
|
|
||||||
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
|
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
|
||||||
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
|
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
|
||||||
@@ -59,6 +63,7 @@ void loop()
|
|||||||
float batteryV = sensorValue * 0.003363075;
|
float batteryV = sensorValue * 0.003363075;
|
||||||
int batteryPcnt = sensorValue / 10;
|
int batteryPcnt = sensorValue / 10;
|
||||||
|
|
||||||
|
#if DEBUG > 0
|
||||||
Serial.print("Battery Voltage: ");
|
Serial.print("Battery Voltage: ");
|
||||||
Serial.print(batteryV);
|
Serial.print(batteryV);
|
||||||
Serial.println(" V");
|
Serial.println(" V");
|
||||||
@@ -66,6 +71,7 @@ void loop()
|
|||||||
Serial.print("Battery percent: ");
|
Serial.print("Battery percent: ");
|
||||||
Serial.print(batteryPcnt);
|
Serial.print(batteryPcnt);
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (oldBatteryPcnt != batteryPcnt) {
|
if (oldBatteryPcnt != batteryPcnt) {
|
||||||
// Power up radio after sleep
|
// Power up radio after sleep
|
||||||
|
|||||||
@@ -29,11 +29,13 @@
|
|||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
|
|
||||||
|
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
|
||||||
|
|
||||||
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
|
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
|
||||||
#define MAX_ATTACHED_DS18B20 16
|
#define MAX_ATTACHED_DS18B20 16
|
||||||
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
|
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
|
||||||
OneWire oneWire(ONE_WIRE_BUS);
|
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
||||||
DallasTemperature sensors(&oneWire);
|
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
|
||||||
MySensor gw;
|
MySensor gw;
|
||||||
float lastTemperature[MAX_ATTACHED_DS18B20];
|
float lastTemperature[MAX_ATTACHED_DS18B20];
|
||||||
int numSensors=0;
|
int numSensors=0;
|
||||||
@@ -44,14 +46,14 @@ MyMessage msg(0,V_TEMP);
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// Startup OneWire
|
// Startup up the OneWire library
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
|
|
||||||
// Startup and initialize MySensors library. Set callback for incoming messages.
|
// Startup and initialize MySensors library. Set callback for incoming messages.
|
||||||
gw.begin();
|
gw.begin();
|
||||||
|
|
||||||
// Send the sketch version information to the gateway and Controller
|
// Send the sketch version information to the gateway and Controller
|
||||||
gw.sendSketchInfo("Temperature Sensor", "1.0");
|
gw.sendSketchInfo("Temperature Sensor", "1.1");
|
||||||
|
|
||||||
// Fetch the number of attached temperature sensors
|
// Fetch the number of attached temperature sensors
|
||||||
numSensors = sensors.getDeviceCount();
|
numSensors = sensors.getDeviceCount();
|
||||||
@@ -78,10 +80,15 @@ void loop()
|
|||||||
float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
|
float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
|
||||||
|
|
||||||
// Only send data if temperature has changed and no error
|
// Only send data if temperature has changed and no error
|
||||||
if (lastTemperature[i] != temperature && temperature != -127.00) {
|
#if COMPARE_TEMP == 1
|
||||||
|
if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
|
||||||
|
#else
|
||||||
|
if (temperature != -127.00 && temperature != 85.00) {
|
||||||
|
#endif
|
||||||
|
|
||||||
// Send in the new temperature
|
// Send in the new temperature
|
||||||
gw.send(msg.setSensor(i).set(temperature,1));
|
gw.send(msg.setSensor(i).set(temperature,1));
|
||||||
|
// Save new temperatures for next compare
|
||||||
lastTemperature[i]=temperature;
|
lastTemperature[i]=temperature;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user