Hello, I would like to ask for help. I am not very familiar with programming via arduino. I am using attiny85 and ds20b18 to read temperature each hour and send it to serial print, then device goes to deep sleep so save energy. What I need to do is to connect button (somehow) and on button press wake up attiny85 and print to serial immediatelly message "button is pressed", then continue in deep sleep again (e.g. after 10 minutes in deep sleep I push button, then it prints to serial and then it goes/continues to deep sleep for 50minutes, so it continues in original loop).
Any idea please how should I edit my code to be able to achieve this?
this is my code:
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "tinysnore.h" // Include TinySnore Library for deep sleep
#define RX 3 // *** D3, Pin 2
#define TX 4 // *** D4, Pin 3
SoftwareSerial mySerial(RX, TX);
#define ONE_WIRE_BUS 1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors (&oneWire);
static uint32_t counter = 0;
void setup() {
//init
mySerial.begin(9600);
mySerial.println("Dallas Temperature IC Control Library Initializing...");
sensors.begin();
mySerial.println("Initialization complete.");
}
void loop() {
//sensor temperature reading
sensors.requestTemperatures();
double tempC = sensors.getTempCByIndex(0);
double tempF = sensors.getTempFByIndex(0);
mySerial.print(counter); mySerial.print(": "); mySerial.print(tempC, 1); mySerial.print("C, "); mySerial.print(tempF, 1); mySerial.println("F");
counter++;
snore(3600000); //in ms, Deep sleeps for 1 second=1000, then resumes from here
}
What I need to do is to connect button (somehow) and on button press wake up attiny85 and print to serial immediatelly message "button is pressed", then continue in deep sleep again (e.g. after 10 minutes in deep sleep I push button, then it prints to serial and then it goes/continues to deep sleep for 50minutes, so it continues in original loop).
This is theoretically possible although a "deep sleep" of more than 8 secs is not possible without additional hardware. This is not really a problem as your TinySnore library (you forgot the link to it!) is handling that limitation and just wakes up every 8 secs and immediately goes to sleep again if the configured time hasn't passed yet.
You have to make sure that the button generates a level interrupt on INT0 or a pin change interrupt to get the ATtiny to wake up from sleeping.
What I need to do with button is to just print all values stored in eeprom to serial monitor on button press. I have no idea how should I modify my code to accept button press (I know how to print eeprom values). Any sample code please?
There are thousands of sample codes on the internet to read a button. Not all use the same method as that depends on the hardware setup used. Usually a button read is simply a digitalRead() and a state variable to know when the state changed. In your case you might have to use an interrupt anyway so you can change the state in the interrupt handler. Don't do anything more there as that would probably freeze your Tiny.
In your case, start by storing the sensor values into EEPROM and read the complete EEPROM content after every write and send it to the serial interface. The post your code and post a wiring diagram of your hardware (including the button).