first commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This sketch simply repeats data received from remote weather sensors made by Cresta.
|
||||
*
|
||||
* Setup:
|
||||
* - connect digital output of a 433MHz receiver to digital pin 2 of Arduino.
|
||||
* - connect transmitter input of a 433MHz transmitter to digital pin 11
|
||||
* - An LED on pin 13 will tell you if and when a signal has been received and transmitted.
|
||||
*
|
||||
* Library:
|
||||
* https://github.com/mattwire/arduino-dev/tree/master/libraries/RemoteSensor
|
||||
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <SensorReceiver.h>
|
||||
#include <SensorTransmitter.h>
|
||||
|
||||
int LED_PIN;
|
||||
int pinRx; // int for Receive pin.
|
||||
int pinTx; // int for Transmit pin.
|
||||
|
||||
void setup() {
|
||||
|
||||
#ifdef ESP32
|
||||
pinRx = 4; pinTx = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
|
||||
LED_PIN = 32; // set led on GPIO pin 32.
|
||||
#elif ESP8266
|
||||
pinRx = 4; pinTx = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
|
||||
LED_PIN = 16; // set led on pin 16 = D0.
|
||||
#else
|
||||
pinRx = 0; pinTx = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. Transmit on pin 6.
|
||||
LED_PIN = 4; // set led on pin D4.
|
||||
#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.
|
||||
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
// Since we're not instantiating SensorTransmitter, but only use the static methods of SensorTransmitter,
|
||||
// the pin mode must be set manually.
|
||||
pinMode(pinTx, OUTPUT);
|
||||
|
||||
// When no signal has been received, the LED is lit.
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
|
||||
// Init the receiver on interrupt pin 0 (digital pin 2).
|
||||
// Set the callback to function "retransmit", which is called
|
||||
// whenever valid sensor data has been received.
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
SensorReceiver::init(pinRx, retransmit);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void retransmit(byte *data) {
|
||||
// Data received
|
||||
|
||||
// Wait a second after a receiving. There's little point for decoding and sending the same signal multiple times.
|
||||
SensorReceiver::disable();
|
||||
interrupts(); // delay() requires that interrupts are enabled
|
||||
delay(1000);
|
||||
|
||||
// Flash LED when transmitting.
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
|
||||
// Transmit signal. Note: this is a static method, no object required!
|
||||
ELECHOUSE_cc1101.SetTx(); // set Transmit on
|
||||
SensorTransmitter::sendPackage(pinTx, data);
|
||||
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
|
||||
noInterrupts();
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
SensorReceiver::enable();
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This sketch receives and decodes data from a 433MHz thermo/hygro weather sensor.
|
||||
* The received data (temperature, humidity, channel) is echo
|
||||
*
|
||||
* Setup:
|
||||
* - Connect digital output of a 433MHz receiver to digital pin 2 of Arduino
|
||||
* - Enable the serial monitor at 115200 baud.
|
||||
*
|
||||
* Need library:
|
||||
* https://github.com/mattwire/arduino-dev/tree/master/libraries/RemoteSensor
|
||||
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
*
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <SensorReceiver.h>
|
||||
|
||||
int 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
|
||||
|
||||
// Init the receiver on interrupt pin 0 (digital pin 2).
|
||||
// Set the callback to function "showTempHumi", which is called
|
||||
// whenever valid sensor data has been received.
|
||||
SensorReceiver::init(pin, showTempHumi);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Empty! However, you can do other stuff here if you like.
|
||||
}
|
||||
|
||||
void showTempHumi(byte *data) {
|
||||
// is data a ThermoHygro-device?
|
||||
if ((data[3] & 0x1f) == 0x1e) {
|
||||
// Yes!
|
||||
|
||||
byte channel, randomId;
|
||||
int temp;
|
||||
byte humidity;
|
||||
|
||||
// Decode the data
|
||||
SensorReceiver::decodeThermoHygro(data, channel, randomId, temp, humidity);
|
||||
|
||||
// Print temperature. Note: temp is 10x the actual temperature!
|
||||
Serial.print("Temperature: ");
|
||||
Serial.print(temp / 10); // units
|
||||
Serial.print('.');
|
||||
Serial.print(temp % 10); // decimal
|
||||
|
||||
// Print humidity
|
||||
Serial.print(" deg, Humidity: ");
|
||||
Serial.print(humidity);
|
||||
Serial.print("% REL");
|
||||
|
||||
// Print channel
|
||||
Serial.print(", Channel: ");
|
||||
Serial.println(channel, DEC);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This sketch sends (bogus) thermo / hygro data to a remote weather sensors made by Cresta.
|
||||
*
|
||||
* Setup:
|
||||
* - connect transmitter input of a 433MHz transmitter to digital pin 11
|
||||
* - On the weather station, activate the "scan" function for channel 1.
|
||||
*
|
||||
* Library:
|
||||
* https://github.com/mattwire/arduino-dev/tree/master/libraries/RemoteSensor
|
||||
* https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
*
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <SensorTransmitter.h>
|
||||
|
||||
int 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
|
||||
|
||||
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.SetTx(); // Transmitt on
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Initializes a ThermoHygroTransmitter on pin 11, with "random" ID 0, on channel 1.
|
||||
ThermoHygroTransmitter transmitter(pin, 0, 1);
|
||||
|
||||
// Displays temperatures from -10 degrees Celsius to +20,
|
||||
// and humidity from 10% REL to 40% REL, with increments of 2
|
||||
for (int i = -10; i<=20; i+=2) {
|
||||
// Temperatures are passed at 10 times the real value,
|
||||
// to avoid using floating point math.
|
||||
transmitter.sendTempHumi(i * 10, i + 20);
|
||||
|
||||
// Wait two seconds before sending next.
|
||||
delay(2000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user