Hello,
I'm trying to read temperature and send it over RF and then sleep. But code gets stuck (attiny85 won't call loop again, just once) when using both DallasTemperature and VirtualWire and I don't know why. When I remove either DallasTemperature or VirtualWire, code runs smoothly.
#include <VirtualWire.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define TX_PIN 0
#define TEMP_PIN 2
union {
float f;
byte ba[4];
} temp;
OneWire oneWire(TEMP_PIN);
DallasTemperature sensors(&oneWire);
uint8_t data[6] = {1, 4, 0, 0, 0, 0};
byte watchdog_counter = 0;
ISR(WDT_vect) {
//watchdog_counter++;
}
// the setup function runs once when you press reset or power the board
void setup() {
vw_set_tx_pin(TX_PIN);
vw_setup(2000);
sensors.begin();
set_sleep_mode(SLEEP_MODE_PWR_DOWN); //Power down everything, wake up from WDT
sleep_enable();
}
// the loop function runs over and over again forever
void loop() {
ADCSRA &= ~(1 << ADEN); //Disable ADC, saves ~230uA
setup_watchdog(); //Setup watchdog to go off after 8sec
sleep_mode(); //Go to sleep! Wake up 1sec later and check water
ADCSRA |= (1 << ADEN); //Enable ADC
wdt_disable();
sensors.requestTemperatures();
temp.f = sensors.getTempCByIndex(0); // i'm not doing anything yet with this
vw_send(data, 6);
vw_wait_tx(); // I think this waits forever when using DallasTemperatures
}
/**
Sleep for 8 seconds
*/
void setup_watchdog() {
//This order of commands is important and cannot be combined
MCUSR &= ~(1 << WDRF); //Clear the watch dog reset
WDTCR |= (1 << WDCE) | (1 << WDE); //Set WD_change enable, set WD enable
WDTCR = 33; //Set new watchdog timeout value, 8 seconds
WDTCR |= _BV(WDIE); //Set the interrupt enable, this will keep unit from resetting after each int
}