Hello,
I have a probelm with my attiny13A and a 433mhz transmitter.
It should always sleep and only wake up if a button is pressed, external interupt, send data over 433mhz and go to sleep again.
I connected a LED to check if it wakes up, it does, but it doesn't send the 433mhz Code.
The 433mhz Code works if i only upload it to the attiny.
Something is causing a problem and I can't figure out what it is for the last few days.
Does someone has an idea whats wrong with my Code?
Here is my sketch:
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define PIN_TX (1<<PB3) // PB3 pin, goes to transmitter data pin
const int buttonPin = 0;
const int ledPin = 1;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
DDRB |= PIN_TX; // Set output direction on PIN_TX
}
void sleep() {
GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
PCMSK |= _BV(PCINT0); // Use PB0 as interrupt pin
ADCSRA &= ~_BV(ADEN); // ADC off ADCSRA &= ~(1<<ADEN);
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep
cli(); // Disable interrupts
PCMSK &= ~_BV(PCINT0); // Turn off PB3 as interrupt pin
sleep_disable(); // Clear SE bit
ADCSRA |= _BV(ADEN); // ADC on ADCSRA |= (1 << ADSC);
while (ADCSRA & (1 << ADSC)); // wait for completion
//sei(); // Enable interrupts
}
ISR(PCINT0_vect) {
// This is called when the interrupt occurs, but I don't need to do anything in it
}
void loop() {
sleep(); // sleep function called here
for (int i = 0; i < 3; i++) {
send("1011101000110101");
delay(150);
}
digitalWrite(ledPin, HIGH);
delay(150);
digitalWrite(ledPin, LOW);
}
The 433mhz code is in a second tab in the IDE:
I got it from here: ATtiny13-transmitter-433Mghz/transmitter.ino at master · rusty-labs/ATtiny13-transmitter-433Mghz · GitHub
#include <util/delay.h>
const short nPulseLength = 350;
const short nHighPulses_0 = (nPulseLength * 1);
const short nLowPulses_0 = (nPulseLength * 3);
const short nHighPulses_1 = (nPulseLength * 3);
const short nLowPulses_1 = (nPulseLength * 1);
const short nLowPulses_sync = (nPulseLength * 31);
void send(char* sCodeWord){
while (*sCodeWord != '\0') {
PORTB |= PIN_TX; // same as digitalWrite high
if(*sCodeWord == '0')
{
_delay_us(nHighPulses_0);
PORTB &= ~PIN_TX; // same as digitalWrite low
_delay_us(nLowPulses_0);
}
else {
_delay_us(nHighPulses_1);
PORTB &= ~PIN_TX;
_delay_us(nLowPulses_1);
}
++sCodeWord;
}
PORTB |= PIN_TX;
_delay_us(nHighPulses_0);
PORTB &= ~PIN_TX;
_delay_us(nLowPulses_sync);
}
If I upload the Code from the link (from github) to the attiny13a it works like it should, the 433mhz Code gets sent.