diff --git a/temp_sensor/platformio.ini b/temp_sensor/platformio.ini index 04c117d..c5ce189 100644 --- a/temp_sensor/platformio.ini +++ b/temp_sensor/platformio.ini @@ -15,3 +15,12 @@ framework = arduino lib_extra_dirs = ../libraries ~/Arduino/libraries +upload_protocol = stk500v1 +; each flag in a new line +upload_flags = + -P$UPLOAD_PORT + -b$UPLOAD_SPEED + +; edit these lines +upload_port = /dev/ttyACM0 +upload_speed = 19200 diff --git a/temp_sensor/src/temp_sensor.cpp b/temp_sensor/src/temp_sensor.cpp index c1d4402..d2a4dc3 100644 --- a/temp_sensor/src/temp_sensor.cpp +++ b/temp_sensor/src/temp_sensor.cpp @@ -1,16 +1,18 @@ #include #include +#include #include #define DEBUG 0 +#define SEND_INTERVAL (int)(5*60/8) // Pins -#define SENDER 1 +#define SENDER PIN_B4 #define TEMP_PIN A1 #if DEBUG -#define RxD 3 -#define TxD 4 +#define RxD PIN_B3 +#define TxD PIN_B4 SoftwareSerial AttinySerial(RxD, TxD); #endif @@ -18,20 +20,28 @@ int readTemp(); TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER); -int counter = 0; +volatile int counter = 0; +volatile bool shouldSend = true; void setup() { #if DEBUG AttinySerial.begin(9600); + AttinySerial.println("starting..."); #endif sensor.setup(); analogReference(INTERNAL); + + TinyPower::setup(); + TinyPower::enableWdt(WDTO_8S); } void loop() { - sensor.sendTemp(readTemp()); - delay(60000L); + if (shouldSend) { + shouldSend = false; + sensor.sendTemp(readTemp()); + } + TinyPower::sleep(); } int readTemp() { @@ -53,3 +63,14 @@ int readTemp() { #endif return roundf(temperatureC * 10); } + +ISR(PCINT0_vect) { +} + +ISR(WDT_vect) { + counter++; + if (counter % SEND_INTERVAL == 0) { + shouldSend = true; + counter = 0; + } +}