first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
/*
* Demo for RF remote switch receiver.
* This example is for the new KaKu / Home Easy type of remotes!
*
* For details, see NewRemoteReceiver.h!
*
* With this sketch you can control a LED connected to digital pin 4,
* after the sketch learned the code. After start, the LED starts to blink,
* until a valid code has been received. The led stops blinking. Now you
* can control the LED with the remote.
*
* Note: only unit-switches are supported in this sketch, no group or dim.
*
* Arduino only!
*
* https://github.com/1technophile/NewRemoteSwitch
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
* ----------------------------------------------------------
* Mod by Little Satan. Have Fun!
* ----------------------------------------------------------
*
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <NewRemoteReceiver.h>
int pin = 0; // int for Receive pin.
int led = 4; // pin for Led.
boolean codeLearned = false;
unsigned long learnedAddress;
byte learnedUnit;
void setup() {
//CC1101 Settings: (Settings with "//" are optional!)
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.SetRx(); // set Receive on
// LED-pin as output
pinMode(led, OUTPUT);
// Init a new receiver on interrupt pin 0, minimal 2 identical repeats, and callback set to processCode.
NewRemoteReceiver::init(pin, 2, processCode);
}
void loop() {
// Blink led until a code has been learned
if (!codeLearned) {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
}
// Callback function is called only when a valid code is received.
void processCode(NewRemoteCode receivedCode) {
// A code has been received.
// Do we already know the code?
if (!codeLearned) {
// No! Let's learn the received code.
learnedAddress = receivedCode.address;
learnedUnit = receivedCode.unit;
codeLearned = true;
} else {
// Yes!
// Is the received code identical to the learned code?
if (receivedCode.address == learnedAddress && receivedCode.unit == learnedUnit) {
// Yes!
// Switch the LED off if the received code was "off".
// Anything else (on, dim, on_with_dim) will switch the LED on.
if (receivedCode.switchType == NewRemoteCode::off) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
}
}
}

View File

@@ -0,0 +1,81 @@
/**
* Demo for RF remote switch receiver.
* For details, see NewRemoteReceiver.h!
*
* Connect the transmitter to digital pin 6.
*
* This sketch demonstrates the use of the NewRemoteTransmitter class.
*
* When run, this sketch switches some pre-defined devices on and off in a loop.
*
* NOTE: the actual receivers have the address and group numbers in this example
* are only for demonstration! If you want to duplicate an existing remote, please
* try the "retransmitter"-example instead.
*
* To use this actual example, you'd need to "learn" the used code in the receivers
* This sketch is unsuited for that.
*
*
* https://github.com/1technophile/NewRemoteSwitch
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
* ----------------------------------------------------------
* Mod by Little Satan. Have Fun!
* ----------------------------------------------------------
*
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <NewRemoteTransmitter.h>
int pin; // int for Transmit pin.
void setup() {
#ifdef ESP32
pin = 2; // for esp32! Transmit on GPIO pin 2.
#elif ESP8266
pin = 5; // for esp8266! Transmit on pin 5 = D1
#else
pin = 6; // for Arduino! Transmit on pin 6.
#endif
//CC1101 Settings: (Settings with "//" are optional!)
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.SetTx(); // cc1101 set Transmit on
}
void loop() {
// Create a transmitter on address 123, using digital pin 6 to transmit,
// with a period duration of 260ms (default), repeating the transmitted
// code 2^3=8 times.
NewRemoteTransmitter transmitter(123, pin, 260, 3);
// Switch unit 2 off
transmitter.sendUnit(2, false);
// Switch all devices in the group off
transmitter.sendGroup(false);
// Set unit 1 to dim-level 3 (range 0-15)
transmitter.sendDim(1, 3);
// Wait 5 seconds
delay(5000);
// Switch unit 2 on
transmitter.sendUnit(2, true);
// Switch all devices in the group on
transmitter.sendGroup(true);
// Set unit 1 to dim-level 15, full brightness.
transmitter.sendDim(1, 15);
// Wait 5 seconds
delay(5000);
}

View File

@@ -0,0 +1,115 @@
/*
* Demo for RF remote switch receiver.
* For details, see NewRemoteReceiver.h!
*
*
* When run, this sketch waits for a valid code from a new-style the receiver,
* decodes it, and retransmits it after 1 seconds.
*
*
* https://github.com/1technophile/NewRemoteSwitch
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
* ----------------------------------------------------------
* Written by Roman.(Arduino Forum) THX!
* Mod by Little Satan. Have Fun!
* ----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <NewRemoteReceiver.h>
#include <NewRemoteTransmitter.h>
int pinTx; // int for Receive pin.
int pinRx; // int for Receive pin.
int Interr = 2; // Interrupt Numer
int Anz = 3; // number of retransmissions
int Tw = 0; // Wait Miliseconds before sending
int debug = 1; // Debugmode ein (1)/aus(0)
void setup() {
Serial.begin(115200);
#ifdef ESP32
pinRx = 4; pinTx = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
#elif ESP8266
pinRx = 4; pinTx = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
#else
pinRx = 0; pinTx = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. Transmit on pin 6.
#endif
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
Serial.println("Connection OK");
}else{
Serial.println("Connection Error");
}
//CC1101 Settings: (Settings with "//" are optional!)
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.SetRx(); // set Receive on
// See example ShowReceivedCode for info on this
NewRemoteReceiver::init(pinRx, Interr, ReTrans);
if (debug == 1) {Serial.println("Receiver initialized... ");}}
void loop() {
}
void ReTrans(unsigned int period, unsigned long address, unsigned long groupBit, unsigned long unit, unsigned long switchType){ // Disable the receiver; otherwise it might pick up the retransmit as well.
if (debug == 1) {
// Print the received code.
Serial.print("Receiver: ");
Serial.print("Code: ");
Serial.print(address);
Serial.print(" unit: ");
Serial.print(unit);
Serial.print(" switchType: ");
Serial.print(switchType);
Serial.print(" Period: ");
Serial.print(period);
Serial.print(" groupBit: ");
Serial.println(groupBit);
}
if (debug == 1) {Serial.print("Send: Receiver disable... ");}
NewRemoteReceiver::disable();
// Need interrupts for delay()
interrupts();
if (debug == 1) {Serial.print("Wait... ");}
// Wait 1 seconds before sending.
delay(Tw);
ELECHOUSE_cc1101.SetTx(); // set Transmit on
// Create a new transmitter with the received address and period, use digital pin as output pin
NewRemoteTransmitter transmitter(address, pinTx, period, Anz);
if (debug == 1) {Serial.print("Send: Addr " + String(address) + " unit " + String(unit)+" "+ String(switchType)+", period: "+String(period)+" " );}
// On/Off signal received
bool isOn = switchType == NewRemoteCode::on;
if (groupBit) {
// Send to the group
transmitter.sendGroup(isOn);
}
else {
// Send to a single unit
transmitter.sendUnit(unit, isOn);
}
if (debug == 1) {Serial.println("Receiver enable!");}
ELECHOUSE_cc1101.SetRx(); // set Receive on
NewRemoteReceiver::enable();
}

View File

@@ -0,0 +1,80 @@
/*
* Demo for RF remote switch receiver.
* For details, see NewRemoteReceiver.h!
*
*
* When run, this sketch waits for a valid code from a new-style the receiver,
* decodes it, and retransmits it after 5 seconds.
*
* Notes: Arduino only!!!
*
* https://github.com/1technophile/NewRemoteSwitch
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
* ----------------------------------------------------------
* Mod by Little Satan. Have Fun!
* ----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <NewRemoteReceiver.h>
#include <NewRemoteTransmitter.h>
void setup() {
//CC1101 Settings: (Settings with "//" are optional!)
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.SetRx(); // set Receive on
// See example ShowReceivedCode for info on this
NewRemoteReceiver::init(0, 2, retransmitter);
}
void loop() {
}
void retransmitter(NewRemoteCode receivedCode) {
// Disable the receiver; otherwise it might pick up the retransmit as well.
NewRemoteReceiver::disable();
// Need interrupts for delay()
interrupts();
// Wait 5 seconds before sending.
delay(5000);
// Create a new transmitter with the received address and period, use digital pin as output pin
ELECHOUSE_cc1101.SetTx(); // set Transmit on
NewRemoteTransmitter transmitter(receivedCode.address, 6, receivedCode.period);
if (receivedCode.switchType == NewRemoteCode::dim ||
(receivedCode.switchType == NewRemoteCode::on && receivedCode.dimLevelPresent)) {
// Dimmer signal received
if (receivedCode.groupBit) {
transmitter.sendGroupDim(receivedCode.dimLevel);
}
else {
transmitter.sendDim(receivedCode.unit, receivedCode.dimLevel);
}
}
else {
// On/Off signal received
bool isOn = receivedCode.switchType == NewRemoteCode::on;
if (receivedCode.groupBit) {
// Send to the group
transmitter.sendGroup(isOn);
}
else {
// Send to a single unit
transmitter.sendUnit(receivedCode.unit, isOn);
}
}
ELECHOUSE_cc1101.SetRx(); // set Receive on
NewRemoteReceiver::enable();
}

View File

@@ -0,0 +1,75 @@
/*
* Demo for RF remote switch receiver.
* For details, see RemoteReceiver.h!
*
* This sketch shows the received signals on the serial port.
* Connect the receiver to digital pin 2 on arduino and digital pin 1 on ESP8266.
*
*
*Detected codes example:
code: 8233372 Period: 273
unit: 1
groupBit: 0
switchType: 0
*
* https://github.com/1technophile/NewRemoteSwitch
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
* ----------------------------------------------------------
* Mod by Little Satan. Have Fun!
* ----------------------------------------------------------
*
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <NewRemoteReceiver.h>
int pin; // int for Receive pin.
void setup() {
Serial.begin(115200);
#ifdef ESP32
pin = 4; // for esp32! Receiver on GPIO pin 4.
#elif ESP8266
pin = 4; // for esp8266! Receiver on pin 4 = D2.
#else
pin = 0; // for Arduino! Receiver on interrupt 0 => that is pin #2
#endif
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
Serial.println("Connection OK");
}else{
Serial.println("Connection Error");
}
//CC1101 Settings: (Settings with "//" are optional!)
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.SetRx(); // set Receive on
NewRemoteReceiver::init(pin, 2, showCode);
Serial.println("Receiver initialized");
}
void loop() {
}
// Callback function is called only when a valid code is received.
void showCode(unsigned int period, unsigned long address, unsigned long groupBit, unsigned long unit, unsigned long switchType) {
// Print the received code.
Serial.print("Code: ");
Serial.print(address);
Serial.print(" Period: ");
Serial.println(period);
Serial.print(" unit: ");
Serial.println(unit);
Serial.print(" groupBit: ");
Serial.println(groupBit);
Serial.print(" switchType: ");
Serial.println(switchType);
}