-
-
Save eloo/517396236af87f29495d31fb0f868401 to your computer and use it in GitHub Desktop.
#include <avr/interrupt.h> | |
#include <avr/sleep.h> | |
// Arduino IDE settings | |
// BOD: 1.8V | |
// Clock: 1.2 MHz | |
// ATTiny13 pins/legs | |
// Leg 8: VCC | |
// Leg 4: GND | |
// Leg 6: TS0201 Button | |
// Pin 1 for TS0201 Button | |
volatile int button = 1; //pin 1 (ATtiny leg 6) | |
volatile int count = 0; | |
ISR(WDT_vect) { | |
count = count +1; | |
//93 with 1.2 internal oscillator, about 15 min | |
if(count > 93) | |
{ | |
pinMode(button, OUTPUT); | |
digitalWrite(button, LOW); // push button; when pushed, button is pulled down by 10k resistor in the device, so this should be safe | |
delay(100); // wait for 100ms | |
pinMode(button, INPUT); | |
digitalWrite(button, LOW); | |
count = 0; | |
} | |
//sleep_mode(); | |
} | |
void setup() { | |
// initialize the digital pin as an output. | |
pinMode(button, INPUT); | |
digitalWrite(button, LOW); //when released/default, button is pulled up by 100k resistor in the device | |
pinMode(2, INPUT_PULLUP); | |
pinMode(3, INPUT_PULLUP); | |
pinMode(4, INPUT_PULLUP); | |
pinMode(0, INPUT_PULLUP); | |
// prescale timer to 8s so we can measure current | |
WDTCR |= (1<<WDP3 )|(0<<WDP2 )|(0<<WDP1)|(1<<WDP0); // 8s | |
// Enable watchdog timer interrupts | |
WDTCR |= (1<<WDTIE); | |
// Disable ADC | |
ADCSRA &= ~(1<<ADEN); | |
ACSR = (1<<ACD); //Disable the analog comparator | |
DIDR0 = 0x3F; //Disable digital input buffers on all ADC0-ADC5 pins. | |
sei(); // Enable global interrupts | |
// Use the Power Down sleep mode | |
set_sleep_mode(SLEEP_MODE_PWR_DOWN); | |
for (;;) { | |
sleep_mode(); // go to sleep and wait for interrupt... | |
} | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
} |
Good job , thank ou , made it also on my. ( Modified only time to 5min , in reality there is ~4min 33s giving 31 value.)
I have a question regrding this
when pushed, button is pulled down by 10k resistor in the device
In TS0201 there is resistor 10k in series with button , but when ATTINY13 is conected like on the picture this resistor is not in the part of circuit...
Beetwen Pin 6 of ATTINY13 and Pin3 of P1 conector on TS0201 i put additional 10k resistor , and it still works.
sadly i'm not that familiar with the electronics of the ATTINY and this gist is mostly a saving point for the discussion in the zigbee2mqtt repo
Koenkk/zigbee2mqtt#4202 (comment)
maybe @jandy123 can give you more insights?
really appreciated your idea. it works great for me.
Connect the ATTiny legs like this:
![image](https://user-images.githubusercontent.com/2631895/147477707-6c98cc95-a2ae-47c9-ad69-4f64375d7dc1.png)
Leg8 - Red - VCC
Leg4- Grey - GND
Leg6 - Blue - Data/Button