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

Small update to MysensorMicro sketch #78

Merged
merged 2 commits into from
Feb 23, 2015
Merged
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
31 changes: 19 additions & 12 deletions libraries/MySensors/examples/MysensorMicro/MysensorMicro.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

#define MEASURE_INTERVAL 60000

// FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller
#define FORCE_TRANSMIT_INTERVAL 30

SI7021 humiditySensor;
MySensor gw;

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

void setup() {

Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);

Expand Down Expand Up @@ -73,6 +75,7 @@ void setup() {
gw.present(CHILD_ID_HUM,S_HUM);

gw.present(CHILD_ID_BATT, S_POWER);
switchClock(1<<CLKPS2);
}


Expand All @@ -81,7 +84,8 @@ void loop() {
measureCount ++;
bool forceTransmit = false;

if (measureCount > 30) {// Every 60th time we wake up, force a transmission on all sensors.
if (measureCount > FORCE_TRANSMIT_INTERVAL
) {// Every 60th time we wake up, force a transmission on all sensors.
forceTransmit = true;
measureCount = 0;
}
Expand All @@ -106,23 +110,19 @@ void sendTempHumidityMeasurements(bool force)
lastTemperature = -100;
}

float temperature = humiditySensor.getCelsiusHundredths()/10;

temperature = temperature / 10;
si7021_env data = humiditySensor.getHumidityAndTemperature();

int humidity = humiditySensor.getHumidityPercent();
float temperature = data.celsiusHundredths/100;

int humidity = data.humidityPercent;

if (lastTemperature != temperature) {
gw.send(msgTemp.set(temperature,1));
lastTemperature = temperature;
Serial.print("temperature ");
Serial.println(temperature);
}
if (lastHumidity != humidity) {
gw.send(msgHum.set(humidity));
lastHumidity = humidity;
Serial.print("Humidity ");
Serial.println(humidity);
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ long readVcc() {
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
ADcdMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif
Expand Down Expand Up @@ -188,4 +188,11 @@ void resetEEP()
}
}


void switchClock(unsigned char clk)
{
cli();

CLKPR = 1<<CLKPCE; // Set CLKPCE to enable clk switching
CLKPR = clk;
sei();
}
2 changes: 1 addition & 1 deletion libraries/SI7021/SI7021.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void SI7021::setHeater(bool on) {
// get humidity, then get temperature reading from humidity measurement
struct si7021_env SI7021::getHumidityAndTemperature() {
si7021_env ret = {0, 0, 0};
ret.humidityBasisPoints = getHumidityBasisPoints();
ret.humidityPercent = getHumidityPercent();
ret.celsiusHundredths = _getCelsiusPostHumidity();
ret.fahrenheitHundredths = (1.8 * ret.celsiusHundredths) + 3200;
return ret;
Expand Down
2 changes: 1 addition & 1 deletion libraries/SI7021/SI7021.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This program is licensed under the GNU GPL v2
typedef struct si7021_env {
int celsiusHundredths;
int fahrenheitHundredths;
unsigned int humidityBasisPoints;
unsigned int humidityPercent;
} si7021_env;

class SI7021
Expand Down