Skip to content

Commit f6dbdcf

Browse files
committed
Merge pull request arduino#123 from Kolbi/development
Some changes for the DallasTemperatureSensors.ino and BatteryPoweredSensor.ino
2 parents a88ffd4 + ed939e7 commit f6dbdcf

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <SPI.h>
3131
#include <MySensor.h>
3232

33+
#define DEBUG 1 // Debug enables Serial.print 1 = Yes 0 = No
34+
3335
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
3436

3537
MySensor gw;
@@ -50,7 +52,9 @@ void loop()
5052
{
5153
// get the battery Voltage
5254
int sensorValue = analogRead(BATTERY_SENSE_PIN);
55+
#if DEBUG > 0
5356
Serial.println(sensorValue);
57+
#endif
5458

5559
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
5660
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
@@ -59,13 +63,15 @@ void loop()
5963
float batteryV = sensorValue * 0.003363075;
6064
int batteryPcnt = sensorValue / 10;
6165

66+
#if DEBUG > 0
6267
Serial.print("Battery Voltage: ");
6368
Serial.print(batteryV);
6469
Serial.println(" V");
6570

6671
Serial.print("Battery percent: ");
6772
Serial.print(batteryPcnt);
6873
Serial.println(" %");
74+
#endif
6975

7076
if (oldBatteryPcnt != batteryPcnt) {
7177
// Power up radio after sleep

libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
#include <DallasTemperature.h>
3030
#include <OneWire.h>
3131

32+
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
33+
3234
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
3335
#define MAX_ATTACHED_DS18B20 16
3436
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
35-
OneWire oneWire(ONE_WIRE_BUS);
36-
DallasTemperature sensors(&oneWire);
37+
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
38+
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
3739
MySensor gw;
3840
float lastTemperature[MAX_ATTACHED_DS18B20];
3941
int numSensors=0;
@@ -44,14 +46,14 @@ MyMessage msg(0,V_TEMP);
4446

4547
void setup()
4648
{
47-
// Startup OneWire
49+
// Startup up the OneWire library
4850
sensors.begin();
4951

5052
// Startup and initialize MySensors library. Set callback for incoming messages.
51-
gw.begin();
53+
gw.begin();
5254

5355
// Send the sketch version information to the gateway and Controller
54-
gw.sendSketchInfo("Temperature Sensor", "1.0");
56+
gw.sendSketchInfo("Temperature Sensor", "1.1");
5557

5658
// Fetch the number of attached temperature sensors
5759
numSensors = sensors.getDeviceCount();
@@ -78,10 +80,15 @@ void loop()
7880
float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
7981

8082
// Only send data if temperature has changed and no error
81-
if (lastTemperature[i] != temperature && temperature != -127.00) {
83+
#if COMPARE_TEMP == 1
84+
if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
85+
#else
86+
if (temperature != -127.00 && temperature != 85.00) {
87+
#endif
8288

8389
// Send in the new temperature
8490
gw.send(msg.setSensor(i).set(temperature,1));
91+
// Save new temperatures for next compare
8592
lastTemperature[i]=temperature;
8693
}
8794
}

0 commit comments

Comments
 (0)