Help understanding and implementing sleep mode on ATTINY85

Dear friends,

I need your help with a project i am building.

I have an ATTINY85 running some code. what i want to do is to wake it up to execute the code it is tasked with and then go back to sleep until “called” to execute the code again.

Here are details about my project:
The Attiny85 is taped on serial line between two arduino uno.
Attiny85 arduino pin3 is attached on one software serial line and pin4 is attached to a 2nd software serial line.
I have them set as inputs so they do not interfere with the serial lines.
Now the “master” arduino pulls pin2 of the attily85 low (i use this as a short of interrupt) and then the execution of the code begins where the attiny will transmit a specific character on both software serial lines for as long as pin2 is help low. when pin2 goes back high then the attiny closes its software serial lines and sets them back as inputs. The UNO’s are programmed to expect that specific character from the attiny. I do all that in order to verify that the UNO’s are configured correctly to listen to each other in other words that both uno’s use the correct baud rate and use the correct software serial pins).

One may ask why i need to do that since the arduinos are usually set up to use a specific software or hardware serial port with fixed baud rate. Well that is not the case for my project and it is a quick method i came up to verify that all are ok.

Now back to the main question. How can i do the above and have the attiny sleep (minimum power consumption) while pin2 is high ?
You may notice that i use pin5 as RX for both software serials but that is okay since i do not use it at all.

#include <SoftwareSerial.h>

SoftwareSerial Serial1 (5, 3); // RX, TX 
SoftwareSerial Serial2 (5, 4);

void setup() 
  pinMode (3,INPUT);
  pinMode (4,INPUT);
  pinMode (2, INPUT_PULLUP);

void loop()
  while (digitalRead(2) == LOW)
    pinMode (3,OUTPUT);
    pinMode (4,OUTPUT);
    delay (100);
    delay (100);
    while (digitalRead(2) == LOW)
      Serial1.print ("A");
      Serial2.print ("A");
    delay (100);
    delay (100);
    pinMode (3,INPUT);
    pinMode (4,INPUT);
    delay (100);


Anyone, anything ?

Serial is a point-to-point connection, not a bus. That means one device transmitting to one other device. You can technically connect multiple receivers to one transmitter, but you can never connect multiple transmitters onto the same line. Never connect multiple outputs together, that’s just asking for trouble.

The ATtiny is unnecessary. If you just want to verify that communication works properly, you can do that entirely in the code of the two controllers themselves. For example:

Connect that “interrupt” line from the master to the slave instead of the ATtiny. When the master wants to test comms, it asserts that signal to make the slave enter COMMTEST mode. When the slave enters COMMTEST mode, it transmits a known bit of information to the master. After that, it will echo anything it receives back to the master until the COMMTEST is over.

From the masters perspective then, it will assert COMMTEST to the slave and listen for the known information from the slave. If it doesn’t get anything, or the bytes are wrong, then something is wrong with the slave and the COMMTEST failed. If it gets the correct bytes from the slave (verifying that slave->master transmission works), it then sends it’s own set of bytes to the slave (which will be echoed back), and compares the echoed data to what it sent. If it’s identical, COMMTEST passed. If they’re different, or the slave didn’t send anything back, then there’s something wrong with master->slave transmission and COMMTEST failed.

Thank you for taking time to answer me. Your way of thinking is excellent but that is not how my project works.
The way it works is complex and to be honest it does not really matter. My true question is how can i put the Attiny85 to sleep mode and wake it up say with an interrupt.
The reason i explained my project is that it is a rule of thumb when someone wants to help with something he has to give details about the nature of the project.
I do not want to change the way my project works, i would just like to learn how to use sleep mode on the attiny.

Again Thank You !

Reading back through my post i now realise that i may have mislead you into thinking that my main concern is how the project works while in fact my concern is how to put the Attiny85 in sleep mode. Im sorry for that.
I am going to use the Attiny sleep mode in other projects also :slight_smile:

So nobody knows how to put the attiny 85 to sleep ?

Please read his fantastic writeup on how to power save.

I use several ways, I use the ATMEGA chip but it should work the same.

  1. I put it to sleep, hook a sensor to one of the 2 interrupts. I set to go HIGH, when it does the interrupt fires my code.

  2. WatchDog, when I just need something to happen every so often I use the watchdog timer.

All of this information is contained in the link I provided.

Thank you so much for the information. I will read it and let you know. I doubt though that it will work the same on the attiny85...

Search this forum for “attiny85 sleep interrupt” for examples and problems. Using a pin change (i.e. not external) interrupt to wake the device is likely to give the best chance of success.

I will thank you.
If you have a link it would be even better.

Thank you.