// Tactile6RX // // Gerard Paresys // 10 9 2023 // // Utilise la library Adafruit_DRV2605 // https://github.com/adafruit/Adafruit_DRV2605_Library/tree/master/examples/realtime // Utilise la library Adafruit BusIO // Utilise la library Adafruit RadioHead // https://github.com/adafruit/RadioHead // https://github.com/adafruit/RadioHead/tree/master/examples/feather/RadioHead69_RawDemo_TX // // OK Adafruit Feather M0 Radio + ADAFRUIT DRV2605L // // Pushbutton red from Pin 5 to ground // // rf69 demo tx rx.pde // -*- mode: C++ -*- // Example sketch showing how to create a simple messaging client // with the RH_RF69 class. RH_RF69 class does not provide for addressing // or reliability, so you should only use RH_RF69 if you do not need the // higher level messaging abilities. // It is designed to work with the other example RadioHead69_RawDemo_TX. // Demonstrates the use of AES encryption, setting the frequency and // modem configuration. #include #include // ************ Radio Setup *************** #define RF69_FREQ 868.0 // 868MHz (EU) ou 915MHz (US) #define RFM69_CS 8 #define RFM69_INT 3 #define RFM69_RST 4 #define LED 13 // Singleton instance of the radio driver RH_RF69 rf69(RFM69_CS, RFM69_INT); void setup() { Serial.begin(115200); // while (!Serial) delay(1); // Wait for Serial Console (comment out line if no computer) pinMode(LED, OUTPUT); pinMode(RFM69_RST, OUTPUT); digitalWrite(RFM69_RST, LOW); Serial.println("Sketch Tactile6RX.ino"); Serial.println(); // manual reset digitalWrite(RFM69_RST, HIGH); delay(10); digitalWrite(RFM69_RST, LOW); delay(10); if (!rf69.init()) { Serial.println("RFM69 radio init failed"); while (1); } Serial.println("RFM69 radio init OK!"); // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module) // No encryption if (!rf69.setFrequency(RF69_FREQ)) { Serial.println("setFrequency failed"); } // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the // ishighpowermodule flag set like this: rf69.setTxPower(20, true); // range from 14-20 for power, 2nd arg must be true for 69HCW // The encryption key has to be the same as the one in the server uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; rf69.setEncryptionKey(key); Serial.print("RFM69 radio @"); Serial.print((int)RF69_FREQ); Serial.println(" MHz"); } void loop() { if (rf69.available()) { // Should be a message for us now uint8_t buf[RH_RF69_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); if (rf69.recv(buf, &len)) { if (!len) return; buf[len] = 0; Serial.print("Received ["); Serial.print(len); Serial.print("]: "); Serial.println((char*)buf); Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC); // RSSI: Receiver Signal Strength Indicator -15 .. -80 if (strstr((char *)buf, "buttonRedOn")) { // Send a reply! uint8_t data[] = "And hello back to you"; rf69.send(data, sizeof(data)); rf69.waitPacketSent(); Serial.println("Sent a reply"); Blink(LED, 40, 3); // blink LED 3 times, 40ms between blinks } } else { Serial.println("Receive failed"); } } } void Blink(byte pin, byte delay_ms, byte loops) { while (loops--) { digitalWrite(pin, HIGH); delay(delay_ms); digitalWrite(pin, LOW); delay(delay_ms); } }