Skip to content

Commit ba1ecd8

Browse files
committed
Merge pull request arduino#78 from tbowmo/master
Small update to MysensorMicro sketch
2 parents c3eb970 + c6efc23 commit ba1ecd8

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

libraries/MySensors/examples/MysensorMicro/MysensorMicro.ino

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#define MEASURE_INTERVAL 60000
2828

29+
// FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller
30+
#define FORCE_TRANSMIT_INTERVAL 30
31+
2932
SI7021 humiditySensor;
3033
MySensor gw;
3134

@@ -45,7 +48,6 @@ long lastBattery = -100;
4548

4649
void setup() {
4750

48-
Serial.begin(115200);
4951
pinMode(LED_PIN, OUTPUT);
5052
digitalWrite(LED_PIN, LOW);
5153

@@ -73,6 +75,7 @@ void setup() {
7375
gw.present(CHILD_ID_HUM,S_HUM);
7476

7577
gw.present(CHILD_ID_BATT, S_POWER);
78+
switchClock(1<<CLKPS2);
7679
}
7780

7881

@@ -81,7 +84,8 @@ void loop() {
8184
measureCount ++;
8285
bool forceTransmit = false;
8386

84-
if (measureCount > 30) {// Every 60th time we wake up, force a transmission on all sensors.
87+
if (measureCount > FORCE_TRANSMIT_INTERVAL
88+
) {// Every 60th time we wake up, force a transmission on all sensors.
8589
forceTransmit = true;
8690
measureCount = 0;
8791
}
@@ -106,23 +110,19 @@ void sendTempHumidityMeasurements(bool force)
106110
lastTemperature = -100;
107111
}
108112

109-
float temperature = humiditySensor.getCelsiusHundredths()/10;
110-
111-
temperature = temperature / 10;
113+
si7021_env data = humiditySensor.getHumidityAndTemperature();
112114

113-
int humidity = humiditySensor.getHumidityPercent();
115+
float temperature = data.celsiusHundredths/100;
116+
117+
int humidity = data.humidityPercent;
114118

115119
if (lastTemperature != temperature) {
116120
gw.send(msgTemp.set(temperature,1));
117121
lastTemperature = temperature;
118-
Serial.print("temperature ");
119-
Serial.println(temperature);
120122
}
121123
if (lastHumidity != humidity) {
122124
gw.send(msgHum.set(humidity));
123125
lastHumidity = humidity;
124-
Serial.print("Humidity ");
125-
Serial.println(humidity);
126126
}
127127
}
128128

@@ -155,7 +155,7 @@ long readVcc() {
155155
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
156156
ADMUX = _BV(MUX5) | _BV(MUX0);
157157
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
158-
ADMUX = _BV(MUX3) | _BV(MUX2);
158+
ADcdMUX = _BV(MUX3) | _BV(MUX2);
159159
#else
160160
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
161161
#endif
@@ -188,4 +188,11 @@ void resetEEP()
188188
}
189189
}
190190

191-
191+
void switchClock(unsigned char clk)
192+
{
193+
cli();
194+
195+
CLKPR = 1<<CLKPCE; // Set CLKPCE to enable clk switching
196+
CLKPR = clk;
197+
sei();
198+
}

libraries/SI7021/SI7021.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void SI7021::setHeater(bool on) {
128128
// get humidity, then get temperature reading from humidity measurement
129129
struct si7021_env SI7021::getHumidityAndTemperature() {
130130
si7021_env ret = {0, 0, 0};
131-
ret.humidityBasisPoints = getHumidityBasisPoints();
131+
ret.humidityPercent = getHumidityPercent();
132132
ret.celsiusHundredths = _getCelsiusPostHumidity();
133133
ret.fahrenheitHundredths = (1.8 * ret.celsiusHundredths) + 3200;
134134
return ret;

libraries/SI7021/SI7021.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This program is licensed under the GNU GPL v2
2323
typedef struct si7021_env {
2424
int celsiusHundredths;
2525
int fahrenheitHundredths;
26-
unsigned int humidityBasisPoints;
26+
unsigned int humidityPercent;
2727
} si7021_env;
2828

2929
class SI7021

0 commit comments

Comments
 (0)