H3V4F ASK ワイヤレスモジュールを使う

ATmega328->ATtiny


H3V4Fの受信側だけをATtinyに変えて試してみました。
送信側はATmega328を使用し以下のスケッチを使用しました。
1秒おきに1→2→1→2を繰り返して送信します。
/*
  SendDemo - sends RF codes.
*/

#include <RCSwitch.h> // https://github.com/sui77/rc-switch
RCSwitch mySwitch = RCSwitch();

void setup() {
 
  // VCC  : 3.3V
  // GND  : GND
  // Data : 7
  // ANT  : in between the two headers!
 
  // Data
  pinMode(7, OUTPUT);  // Either way, we'll use pin 7 to drive the data pin of the transmitter.

  Serial.begin(9600);
 
  // Transmitter is connected to Arduino Pin #10 
  mySwitch.enableTransmit(7);
 
}

void loop() {
  static long value=1;  

//  mySwitch.send(value, 24);
  mySwitch.send(value, 32);
  value++;
  if (value == 3) value=1;
  delay(1000);
}


受信側のスケッチは以下の通りで、受信モジュールのDataピンを各ATtinyのINT0に接続します。
正しく受信するとLED1 LED2が交互に点灯します。
/*
  RF_Sniffer - receive RF codes.
*/

#include <RCSwitch.h> // https://github.com/sui77/rc-switch
RCSwitch mySwitch = RCSwitch();

#if defined(__AVR_ATmega328P__)
 #define LED1 8
 #define LED2 9
 #define INT0 0 // PD2
#elif defined(__AVR_ATtiny84__)
 #define LED1 3
 #define LED2 4
 #define INT0 0 // PB2
#elif defined(__AVR_ATtiny85__)
 #define LED1 3
 #define LED2 4
 #define INT0 0 // PB2
#elif defined(__AVR_ATtiny861__)
 #define LED1 4
 #define LED2 5
 #define INT0 0 // PB6
#elif defined(__AVR_ATtiny4313__)
 #define LED1 6
 #define LED2 7
 #define INT0 0 // PD2
#endif

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(INT0);
  Serial.println("mySwich start");
  pinMode(LED1,OUTPUT);
  pinMode(LED2,OUTPUT);
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
}

void loop() {
 
  if (mySwitch.available()) {
    
    int value = mySwitch.getReceivedValue();
    
    if (value == 0) {
      Serial.print("Unknown encoding");
    } else {
   
      Serial.print("Received ");
      Serial.print( mySwitch.getReceivedValue() );
      Serial.print(" / ");
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print("bit ");
      Serial.print("Protocol: ");
      Serial.println( mySwitch.getReceivedProtocol() );

      if (mySwitch.getReceivedValue() == 1) {
        digitalWrite(LED1,LOW);
        digitalWrite(LED2,HIGH);
      } else {
        digitalWrite(LED1,HIGH);
        digitalWrite(LED2,LOW);
      }
    }
    
    mySwitch.resetAvailable();
    
  }

}

使用するAddOnによって結果が変わりました。

ATtiny84

ATtinyCore(http://drazzy.com/package_drazzy.com_index.json)
コンパイルエラーとなります。
FemtoCow(https://github.com/FemtoCow/ATTinyCore/raw/master/Downloads/package_femtocow_attiny_index.json)
受信モジュールのDataピンをPB2(Pin#5)に接続します。正常に動作します。

ATtiny85

ATtinyCore(http://drazzy.com/package_drazzy.com_index.json)
コンパイルエラーとなります。
FemtoCow(https://github.com/FemtoCow/ATTinyCore/raw/master/Downloads/package_femtocow_attiny_index.json)
受信モジュールのDataピンをPB2(Pin#7)に接続します。正常に動作します。

ATtiny861

ATtinyCore(http://drazzy.com/package_drazzy.com_index.json)
FemtoCow(https://github.com/FemtoCow/ATTinyCore/raw/master/Downloads/package_femtocow_attiny_index.json)
受信モジュールのDataピンをPB6(Pin#9)に接続します。正常に動作します。
どちらのAddOnでも動きます。

ATtiny4313

ATtinyCore(http://drazzy.com/package_drazzy.com_index.json)
メモリーオーバーフローでコンパイルできません。

8MのATtinyではメモリがギリギリなので、実用にはなりません。

次回はRaspberryとATmega328の通信を試してみます。