Open gitgaatachal opened 3 years ago
Hello, gitgaatachal, I can check fuses and situation tonight, I write here
Hello, gitgaatachal, I can check fuses and situation tonight, I write here
Thank you for super fast reply, surely will wait for your inputs
Hello again! Sorry for delay, I just forgot about it) So now I reproduce all steps to make attiny receive 433 MHz signal and switch an led. I remember important part for me was to connect receiver to PB1 (it is only hardware interrupt on ATTINY13 and only working pin for 433MHz receiver for me) :
After this I recommend to check attiny13 by uploading simple Blink sketch:
void setup() {
pinMode(PB4, OUTPUT);
}
void loop() {
digitalWrite(PB4, HIGH);
delay(1000);
digitalWrite(PB4, LOW);
delay(1000);
}
if this works - you can try upload this simplified verison of attiny Receiver Sketch (without transmitter response part), it works for me now:
volatile static int lastCode = 0;
void setup() { pinMode(rxPin, INPUT); pinMode(ledPin, OUTPUT); attachInterrupt(INT0, grab, CHANGE); //INT0 PB1 hardware interrupt interrupts(); }
void loop() { //codes from 0 to 4095 can be used if (lastCode == 2211) { // Serial.println(lastCode & 0xfff); digitalWrite(ledPin, HIGH); lastCode = 0; } if (lastCode == 2200) { // Serial.println(lastCode & 0xfff); digitalWrite(ledPin, LOW); lastCode = 0; }
}
// receiving code below:
volatile unsigned long prevtime; volatile unsigned int lolen, hilen, rxstate; volatile static byte cameCounter = 0; // count of bits stored volatile static int cameCode = 0; // code itself
boolean CheckValue(unsigned int base, unsigned int value) { return ((value == base) || ((value > base) && ((value - base) < MAX_DELTA)) || ((value < base) && ((base - value) < MAX_DELTA))); }
void grab() { rxstate = digitalRead(rxPin); if (rxstate == HIGH) lolen = micros() - prevtime; else hilen = micros() - prevtime; prevtime = micros();
if (rxstate == LOW) { if (CheckValue(320, hilen) && CheckValue(640, lolen)) { // valid 1 cameCode = (cameCode << 1) | 1; cameCounter++; } else if (CheckValue(640, hilen) && CheckValue(320, lolen)) { // valid 0 cameCode = (cameCode << 1) | 0; cameCounter++; } else cameCounter = 0; } else if (lolen > 1000 && (cameCounter == 12 || cameCounter == 13) && ((cameCode & 0xfff) != 0xfff)) { lastCode = cameCode & 0xfff; cameCounter = 0; cameCode = 0; } }
4.
to perform check with arduino (I use UNO), here is also simplified version of sketch to transmit only ON (code 2211) and OFF (code 2200) every 4 seconds :
int toggle = 0; unsigned long timer_1; void setup() { pinMode(txPin, OUTPUT);
Serial.begin(9600); // Serial.println("Came started"); }
void loop() {
if (millis() - timer_1 >= PERIOD_1) { timer_1 = millis(); if (toggle == 1) { SendCame4(2211); toggle = 0; } else { SendCame4(2200); toggle = 1; } } }
void SendCame4(long Code) { noInterrupts(); for (int j = 0; j < 10; j++) { // посылку посылаем 10 раза подряд. // время стартового импульса digitalWrite(txPin, HIGH); delayMicroseconds(320); digitalWrite(txPin, LOW); for (int i = 12; i > 0; i--) { byte b = bitRead(Code, i - 1); // побитово перебираем и посылаем код if (b) { digitalWrite(txPin, LOW); // 1 delayMicroseconds(640); digitalWrite(txPin, HIGH); delayMicroseconds(320); } else { digitalWrite(txPin, LOW); // 0 delayMicroseconds(320); digitalWrite(txPin, HIGH); delayMicroseconds(640); } } digitalWrite(txPin, LOW); delayMicroseconds(11520); } interrupts(); }
It works for me like this now from scratch , just small video of installation: https://youtu.be/g5D6kS9WsT0 Hope this helps, fell free to ask if I can help more
Hi,
I have tried flashing the sketch on attiny13a chip with the fuses set as lfuse 0x7A and hfuse 0xFF, however the sketch doesn't seem to work and the led on PB4 remains off all the time. The connections are made as per the pin configurations.
Is the sketch suppose to work without making any changes in the code? I mean the two function calls in the SendCame4 are sending codes 2266 and 2255 as opposed to the codes being checked in the if condition 2211 and 2200.
Thanks