DROID8622 / ATtiny13-433MHz-Receiver-Transmitter

5 stars 0 forks source link

The ATTINY13-433MHzRemoteSwitch.ino sketch doesn't seem to work out of the box #1

Open gitgaatachal opened 2 years ago

gitgaatachal commented 2 years ago

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

DROID8622 commented 2 years ago

Hello, gitgaatachal, I can check fuses and situation tonight, I write here

gitgaatachal commented 2 years ago

Hello, gitgaatachal, I can check fuses and situation tonight, I write here

Thank you for super fast reply, surely will wait for your inputs

DROID8622 commented 2 years ago

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) :

687474703a2f2f692e696d6775722e636f6d2f4a7362677550562e6a7067

  1. About fuses : I use only Arduino IDE, so I just put settings below (on screenshot) and hit Burn Bootloader, it burns fuses :

bootloader

  1. 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);
    }

  2. if this works - you can try upload this simplified verison of attiny Receiver Sketch (without transmitter response part), it works for me now:

define rxPin PB1 //receiver

define ledPin PB4 // LED or relay

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:

define MAX_DELTA 200 // impulse lenght may vary of battery and so on, max deviation is 200

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 :

define txPin 3 //

define PERIOD_1 4000

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

Foster11071989 commented 2 years ago

Как изменить скетч для Attiny13 для приема кода пульта 24 bit? Сможете помочь? Received 1394001 / 24bit Protocol: 1 data bits of pulse train duration: 38648 proposed protocol: { 399, { 1, 30 }, { 1, 3 }, { 3, 1 }, false }

first level down 12084 756 1172 436 1156 432 1168 1200 396 420 1180 1196 404 412 1188 1192 408 408 1188 1196 400 412 1188 416 1180 416 1180 1200 400 408 1192 1180 416 404 1188 1184 412 400 1196 1180 416 400 1192 404 1188 408 1184 1192 404 408