Add files via upload

This commit is contained in:
ESPboy 2020-10-26 15:35:36 +03:00 committed by GitHub
commit 76a040aab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
79 changed files with 7399 additions and 0 deletions

71
ESPboyInit.cpp Normal file
View file

@ -0,0 +1,71 @@
/*
ESPboy_Init class
for www.ESPboy.com project by RomanS
https://hackaday.io/project/164830-espboy-games-iot-stem-for-education-fun
v1.0
*/
#include "ESPboyInit.h"
ESPboyInit::ESPboyInit(){};
void ESPboyInit::begin(char *appName) {
//Serial.begin(115200); //serial init
WiFi.mode(WIFI_OFF); // to safe battery power
//DAC init and backlit off
dac.begin(MCP4725address);
delay (100);
dac.setVoltage(0, false);
//mcp23017 init for buttons, LED LOCK and TFT Chip Select pins
mcp.begin(MCP23017address);
delay(100);
for (int i=0;i<8;i++){
mcp.pinMode(i, INPUT);
mcp.pullUp(i, HIGH);}
//sound init and test
pinMode(SOUNDPIN, OUTPUT);
playTone(200, 100);
delay(100);
playTone(100, 100);
delay(100);
noPlayTone();
//LCD TFT init
mcp.pinMode(CSTFTPIN, OUTPUT);
mcp.digitalWrite(CSTFTPIN, LOW);
tft.begin();
delay(100);
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
//draw ESPboylogo
tft.drawXBitmap(30, 24, ESPboyLogo, 68, 64, TFT_YELLOW);
tft.setTextSize(1);
tft.setTextColor(TFT_YELLOW);
tft.drawString (appName, (128-(strlen(appName)*6))/2, 102);
//LCD backlit fading on
for (uint16_t bcklt=300; bcklt<4095; bcklt+=30){
dac.setVoltage(bcklt, false);
delay(10);}
//clear TFT and backlit on high
dac.setVoltage(4095, true);
tft.fillScreen(TFT_BLACK);
//LED pin LOCK OFF
mcp.pinMode(LEDLOCK, OUTPUT);
mcp.digitalWrite(LEDLOCK, HIGH);
};
void ESPboyInit::playTone(uint16_t frq, uint16_t dur) { tone(SOUNDPIN, frq, dur); }
void ESPboyInit::playTone(uint16_t frq) { tone(SOUNDPIN, frq); }
void ESPboyInit::noPlayTone() { noTone(SOUNDPIN); }
uint8_t ESPboyInit::getKeys() { return (~mcp.readGPIOAB() & 255); }

56
ESPboyInit.h Normal file
View file

@ -0,0 +1,56 @@
/*
ESPboy_Init class
for www.ESPboy.com project by RomanS
https://hackaday.io/project/164830-espboy-games-iot-stem-for-education-fun
v1.0
*/
#ifndef ESPboy_Init
#define ESPboy_Init
#include <Arduino.h>
#include <Adafruit_MCP23017.h> //to control buttons
#include <Adafruit_MCP4725.h> //to control the LCD display backlit
#include <TFT_eSPI.h> //to draw at LCD TFT
#include <ESP8266WiFi.h> //to control WiFi
#include "lib/ESPboyLogo.h"
#include <FS.h>
using fs::FS;
#define MCP23017address 0 // actually it's 0x20 but in <Adafruit_MCP23017.h> lib there is (x|0x20) :)
#define MCP4725address 0x60
#define LEDPIN D4
#define SOUNDPIN D3
#define LEDLOCK 9
#define CSTFTPIN 8 //Chip Select pin for LCD (it's on the MCP23017 GPIO expander GPIO8)
#define PAD_LEFT 0x01
#define PAD_UP 0x02
#define PAD_DOWN 0x04
#define PAD_RIGHT 0x08
#define PAD_ACT 0x10
#define PAD_ESC 0x20
#define PAD_LFT 0x40
#define PAD_RGT 0x80
#define PAD_ANY 0xff
class ESPboyInit{
public:
Adafruit_MCP23017 mcp;
Adafruit_MCP4725 dac;
TFT_eSPI tft;
ESPboyInit();
void begin(char *appName);
uint8_t getKeys();
void playTone(uint16_t frq, uint16_t dur);
void playTone(uint16_t frq);
void noPlayTone();
};
#endif

118
ESPboyLED.cpp Normal file
View file

@ -0,0 +1,118 @@
/*
ESPboy LED class
for www.ESPboy.com project by RomanS
*/
#include "ESPboyLED.h"
void ESPboyLED::begin(Adafruit_MCP23017 *mcpGUI){
mcp = mcpGUI;
pinMode(LEDPIN, OUTPUT);
mcp->pinMode(LEDLOCK, OUTPUT);
LEDflagOnOff = 1;
LEDr = 0;
LEDg = 0;
LEDb = 0;
ledset(LEDr, LEDg, LEDb);
}
void ESPboyLED::off(){
LEDflagOnOff = 0;
ledset(0, 0, 0);
}
void ESPboyLED::on(){
LEDflagOnOff = 1;
ledset(LEDr, LEDg, LEDb);
}
uint8_t ESPboyLED::getState(){
return (LEDflagOnOff);
}
void ESPboyLED::setRGB (uint8_t red, uint8_t green, uint8_t blue){
LEDr = red;
LEDg = green;
LEDb = blue;
if (LEDflagOnOff) ledset(LEDr, LEDg, LEDb);
}
void ESPboyLED::setR (uint8_t red){
LEDr = red;
if (LEDflagOnOff) ledset(LEDr, LEDg, LEDb);
}
void ESPboyLED::setG (uint8_t green){
LEDg = green;
if (LEDflagOnOff) ledset(LEDr, LEDg, LEDb);
}
void ESPboyLED::setB (uint8_t blue){
LEDb = blue;
if (LEDflagOnOff) ledset(LEDr, LEDg, LEDb);
}
uint32_t ESPboyLED::getRGB(){
return (((uint32_t)LEDb<<16) + ((uint32_t)LEDg<<8) + ((uint32_t)LEDr) );
}
uint8_t ESPboyLED::getR(){
return (LEDr);
}
uint8_t ESPboyLED::getG(){
return (LEDg);
}
uint8_t ESPboyLED::getB(){
return (LEDb);
}
void ICACHE_RAM_ATTR ESPboyLED::ledset(uint8_t rled, uint8_t gled, uint8_t bled) {
static uint_fast32_t i, t, c, startTime, pixel, mask, t0h, t1h, ttot;
static uint8_t cpuFreq;
static const uint32_t pinMask = 1<<LEDPIN;
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask);
delay(1);
mcp->digitalWrite(LEDLOCK, HIGH);
cpuFreq = ESP.getCpuFreqMHz()/80;
t0h = 32*cpuFreq; // 0.4us
t1h = 64*cpuFreq; // 0.8us
ttot = 100*cpuFreq; // 1.25us
pixel = (gled<<16) + (rled<<8) + bled;
mask = 0x800000;
startTime = 0;
os_intr_lock();
for (i=0; i<24; i++){
if (pixel & mask) t = t1h;
else t = t0h;
while (((c=ESP.getCycleCount()) - startTime) < ttot);// Wait for the previous bit to finish
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // digitalWrite HIGH
startTime = c;
while (((c=ESP.getCycleCount()) - startTime) < t); // Wait for high time to finish
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // digitalWrite LOW
mask>>=1;
}
os_intr_unlock();
delay(1);
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask);
mcp->digitalWrite(LEDLOCK, LOW);
}

38
ESPboyLED.h Normal file
View file

@ -0,0 +1,38 @@
/*
ESPboy LED class
for www.ESPboy.com project by RomanS
*/
#include <Arduino.h>
#include <Adafruit_MCP23017.h> //to control LED lock
#ifndef ESPboy_LED
#define ESPboy_LED
#define LEDPIN D4
#define LEDLOCK 9
class ESPboyLED{
private:
Adafruit_MCP23017 *mcp;
uint8_t LEDr, LEDg, LEDb, LEDflagOnOff;
void ledset(uint8_t rled, uint8_t gled, uint8_t bled);
public:
void begin(Adafruit_MCP23017 *mcpGUI);
void off();
void on();
uint8_t getState();
void setRGB (uint8_t red, uint8_t green, uint8_t blue);
void setR (uint8_t red);
void setG (uint8_t green);
void setB (uint8_t blue);
uint32_t getRGB();
uint8_t getR();
uint8_t getG();
uint8_t getB();
};
#endif

316
ESPboyTerminalGUI.cpp Normal file
View file

@ -0,0 +1,316 @@
/*
ESPboyTerminalGUI class
for www.ESPboy.com project by RomanS
https://hackaday.io/project/164830-espboy-games-iot-stem-for-education-fun
v2.1
*/
#include "ESPboyTerminalGUI.h"
#define SOUNDPIN D3
const uint8_t ESPboyTerminalGUI::keybOnscr[2][3][21] PROGMEM = {
{"+1234567890abcdefghi", "jklmnopqrstuvwxyz -=", "?!@$%&*()_[]\":;.,^<E",},
{"+1234567890ABCDEFGHI", "JKLMNOPQRSTUVWXYZ -=", "?!@$%&*()_[]\":;.,^<E",}
};
ESPboyTerminalGUI::ESPboyTerminalGUI(TFT_eSPI *tftGUI, Adafruit_MCP23017 *mcpGUI) {
keybParam.renderLine = 0;
keybParam.displayMode = 0;
keybParam.shiftOn = 0;
keybParam.selX = 0;
keybParam.selY = 0;
keybParam.typing = "";
tft = tftGUI;
mcp = mcpGUI;
#ifdef U8g2
u8f = new U8g2_for_TFT_eSPI;
u8f->begin(*tft);
u8f->setFontMode(1); // use u8g2 none transparent mode
u8f->setBackgroundColor(TFT_BLACK);
u8f->setFontDirection(0); // left to right
u8f->setFont(u8g2_font_4x6_t_cyrillic);
#endif
consoleStringsVector.push_back(consoleStringS());
consoleStringsVector.back().consoleString = "";
consoleStringsVector.back().consoleStringColor = TFT_BLACK;
toggleDisplayMode(1);
}
uint8_t ESPboyTerminalGUI::keysAction() {
uint8_t longActPress = 0;
uint8_t keyState = getKeys();
if (keyState) {
#ifdef buttonclicks
tone(SOUNDPIN, 100, 10);
#endif
if (!keybParam.displayMode) {
if (keyState & GUI_PAD_LEFT && keyState & GUI_PAD_UP) { // shift
keybParam.shiftOn = !keybParam.shiftOn;
drawKeyboard(keybParam.selX, keybParam.selY, 0);
waitKeyUnpressed();
} else {
if ((keyState & GUI_PAD_RIGHT) && keybParam.selX < 20) keybParam.selX++;
if ((keyState & GUI_PAD_LEFT) && keybParam.selX > -1) keybParam.selX--;
if ((keyState & GUI_PAD_DOWN) && keybParam.selY < 3) keybParam.selY++;
if ((keyState & GUI_PAD_UP) && keybParam.selY > -1) keybParam.selY--;
if ((keyState & GUI_PAD_LEFT) && keybParam.selX == -1) keybParam.selX = 19;
if ((keyState & GUI_PAD_RIGHT) && keybParam.selX == 20) keybParam.selX = 0;
if ((keyState & GUI_PAD_UP) && keybParam.selY == -1) keybParam.selY = 2;
if ((keyState & GUI_PAD_DOWN) && keybParam.selY == 3) keybParam.selY = 0;
}
if ((keyState&GUI_PAD_ACT && keyState&GUI_PAD_ESC) || (keyState&GUI_PAD_RGT && keyState&GUI_PAD_LFT)) {
if (keybParam.renderLine > consoleStringsVector.size() - GUI_MAX_STRINGS_ONSCREEN_FULL)
keybParam.renderLine = consoleStringsVector.size() - GUI_MAX_STRINGS_ONSCREEN_FULL;
toggleDisplayMode(1);
waitKeyUnpressed();
} else if (keyState&GUI_PAD_RGT && keybParam.renderLine) {
keybParam.renderLine--;
drawConsole(0);
} else if (keyState&GUI_PAD_LFT && keybParam.renderLine < consoleStringsVector.size() - GUI_MAX_STRINGS_ONSCREEN_SMALL) {
keybParam.renderLine++;
drawConsole(0);
}
if ((((keyState & GUI_PAD_ACT) && (keybParam.selX == 19 && keybParam.selY == 2)) || (keyState & GUI_PAD_RGT && keyState & GUI_PAD_LFT))) { // enter
if (keybParam.typing.length() > 0) longActPress = 1;
} else if ((keyState & GUI_PAD_ACT) && (keybParam.selX == 18 && keybParam.selY == 2)) { // back space
if (keybParam.typing.length() > 0) keybParam.typing.remove(keybParam.typing.length() - 1);
} else if ((keyState & GUI_PAD_ACT) && (keybParam.selX == 17 && keybParam.selY == 1)) { // SPACE
if (keybParam.typing.length() < GUI_MAX_TYPING_CHARS) keybParam.typing += " ";
} else if ((keyState & GUI_PAD_ACT) && (keybParam.selX == 17 && keybParam.selY == 2)) {
keybParam.shiftOn = !keybParam.shiftOn;
drawKeyboard(keybParam.selX, keybParam.selY, 0);
waitKeyUnpressed();
} else if (keyState & GUI_PAD_ACT){
if (waitKeyUnpressed() > GUI_KEY_PRESSED_DELAY_TO_SEND)
longActPress = 1;
else if (keybParam.typing.length() < GUI_MAX_TYPING_CHARS)
keybParam.typing += (char)pgm_read_byte(&keybOnscr[keybParam.shiftOn][keybParam.selY][keybParam.selX]);
}
if (keyState & GUI_PAD_ESC) {
if (waitKeyUnpressed() > GUI_KEY_PRESSED_DELAY_TO_SEND)
keybParam.typing = "";
else if (keybParam.typing.length() > 0)
keybParam.typing.remove(keybParam.typing.length() - 1);
}
}
else {
if ((keyState & GUI_PAD_ACT && keyState & GUI_PAD_ESC) || (keyState & GUI_PAD_RGT && keyState & GUI_PAD_LFT)) {
toggleDisplayMode(0);
waitKeyUnpressed();
} else
if (((keyState & GUI_PAD_RGT || keyState & GUI_PAD_RIGHT || keyState & GUI_PAD_DOWN)) && keybParam.renderLine > 0) {
keybParam.renderLine--;
drawConsole(0);
} else
if (((keyState&GUI_PAD_LFT || keyState & GUI_PAD_LEFT || keyState&GUI_PAD_UP)) && keybParam.renderLine < consoleStringsVector.size() - GUI_MAX_STRINGS_ONSCREEN_FULL) {
keybParam.renderLine++;
drawConsole(0);
} else
if (keyState & GUI_PAD_ESC)
toggleDisplayMode(0);
}
if (!keybParam.displayMode) drawKeyboard(keybParam.selX, keybParam.selY, 1);
}
if (!keybParam.displayMode) drawBlinkingCursor();
return (longActPress);
}
void ESPboyTerminalGUI::toggleDisplayMode(uint8_t mode) {
keybParam.displayMode = mode;
tft->fillScreen(TFT_BLACK);
tft->drawRect(0, 0, 128, 128, TFT_NAVY);
if (!keybParam.displayMode) {
tft->drawRect(0, 128 - 3 * 8 - 5, 128, 3 * 8 + 5, TFT_NAVY);
tft->drawRect(0, 0, 128, 86, TFT_NAVY);
}
if (!keybParam.displayMode) {
drawKeyboard(keybParam.selX, keybParam.selY, 0);
}
drawConsole(0);
}
String ESPboyTerminalGUI::getUserInput() {
String userInput;
toggleDisplayMode(0);
while (1) {
while (!keysAction()) delay(GUI_KEYB_CALL_DELAY);
if (keybParam.typing != "") break;
}
toggleDisplayMode(1);
userInput = keybParam.typing;
keybParam.typing = "";
return (userInput);
}
void ESPboyTerminalGUI::printConsole(String bfrstr, uint16_t color, uint8_t ln, uint8_t noAddLine) {
String toprint;
keybParam.renderLine = 0;
if(bfrstr == "") bfrstr = " ";
if (!ln)
if (bfrstr.length() > ((128-4)/GUI_FONT_WIDTH)) {
bfrstr = bfrstr.substring(0, ((128-4)/GUI_FONT_WIDTH));
toprint = bfrstr;
}
for (uint8_t i = 0; i <= ((bfrstr.length()-1) / ((128-4)/GUI_FONT_WIDTH)); i++) {
toprint = bfrstr.substring(i * (128-4)/GUI_FONT_WIDTH);
toprint = toprint.substring(0, (128-4)/GUI_FONT_WIDTH);
if (!noAddLine) consoleStringsVector.push_back(consoleStringS());
consoleStringsVector.back().consoleString = toprint;
consoleStringsVector.back().consoleStringColor = color;
}
drawConsole(noAddLine);
if (consoleStringsVector.size() > GUI_MAX_CONSOLE_STRINGS){
consoleStringsVector.erase(consoleStringsVector.begin());
consoleStringsVector.shrink_to_fit();
}
}
void ESPboyTerminalGUI::drawConsole(uint8_t onlyLastLine) {
uint16_t lines;
uint16_t offsetY;
uint16_t quantityLinesToDraw;
int16_t startVectorToDraw;
if (keybParam.displayMode) lines = GUI_MAX_STRINGS_ONSCREEN_FULL;
else lines = GUI_MAX_STRINGS_ONSCREEN_SMALL;
#ifndef U8g2
if (!onlyLastLine) tft->fillRect(1, 4, 126, lines * GUI_FONT_HEIGHT, TFT_BLACK);
else tft->fillRect(1, (lines-1) * GUI_FONT_HEIGHT+4, 126, GUI_FONT_HEIGHT, TFT_BLACK);
#else
if (!onlyLastLine) tft->fillRect(1, 1, 126, lines * GUI_FONT_HEIGHT, TFT_BLACK);
else tft->fillRect(1, (lines-1) * GUI_FONT_HEIGHT, 126, GUI_FONT_HEIGHT+1, TFT_BLACK);
#endif
#ifndef U8g2
offsetY = lines * GUI_FONT_HEIGHT - 4;
#else
offsetY = lines * GUI_FONT_HEIGHT;
#endif
if(consoleStringsVector.size() < lines ) quantityLinesToDraw = consoleStringsVector.size();
else quantityLinesToDraw = lines;
startVectorToDraw = consoleStringsVector.size()-1-keybParam.renderLine;
for (uint8_t i = 0; i< quantityLinesToDraw; i++) {
#ifndef U8g2
tft->setTextColor(consoleStringsVector[startVectorToDraw].consoleStringColor, TFT_BLACK);
tft->drawString(consoleStringsVector[startVectorToDraw].consoleString, 3, offsetY);
#else
u8f->setForegroundColor(consoleStringsVector[startVectorToDraw].consoleStringColor);
u8f->drawStr(2, offsetY, consoleStringsVector[startVectorToDraw].consoleString.c_str());
#endif
offsetY -= GUI_FONT_HEIGHT;
startVectorToDraw--;
if(startVectorToDraw<0) startVectorToDraw=0;
}
}
uint8_t ESPboyTerminalGUI::getKeys() { return (~mcp->readGPIOAB() & 255); }
uint32_t ESPboyTerminalGUI::waitKeyUnpressed() {
uint32_t timerStamp = millis();
while (getKeys() && (millis() - timerStamp) < GUI_KEY_UNPRESSED_TIMEOUT) delay(1);
return (millis() - timerStamp);
}
void ESPboyTerminalGUI::drawKeyboard(uint8_t slX, uint8_t slY, uint8_t onlySelected) {
static char chr[2]={0,0};
static uint8_t prevX = 0, prevY = 0;
if (!onlySelected) {
tft->fillRect(1, 128 - 24, 126, 23, TFT_BLACK);
tft->setTextColor(TFT_YELLOW, TFT_BLACK);
for (uint8_t j = 0; j < 3; j++)
for (uint8_t i = 0; i < 20; i++) {
chr[0] = pgm_read_byte(&keybOnscr[keybParam.shiftOn][j][i]);
tft->drawString(&chr[0], i * 6 + 4, 128 - 2 - 8 * (3 - j));
}
}
tft->setTextColor(TFT_YELLOW, TFT_BLACK);
chr[0] = pgm_read_byte(&keybOnscr[keybParam.shiftOn][prevY][prevX]);
tft->drawString(&chr[0], prevX * 6 + 4, 128 - 24 + prevY * 8 - 2);
tft->setTextColor(TFT_WHITE, TFT_BLACK);
tft->drawString("^<E", 6 * 17 + 4, 128 - 24 + 2 * 8 - 2);
tft->setTextColor(TFT_YELLOW, TFT_RED);
chr[0] = pgm_read_byte(&keybOnscr[keybParam.shiftOn][slY][slX]);
tft->drawString(&chr[0], slX * 6 + 4, 128 - 24 + slY * 8 - 2);
prevX = slX;
prevY = slY;
drawTyping(0);
}
void ESPboyTerminalGUI::drawTyping(uint8_t changeCursor) {
static char cursorType[2] = {220, '_'};
static uint8_t cursorTypeFlag=0;
if(changeCursor) cursorTypeFlag=!cursorTypeFlag;
tft->fillRect(1, 128 - 5 * 8, 126, 10, TFT_BLACK);
if (keybParam.typing.length() < 20) {
tft->setTextColor(TFT_WHITE, TFT_BLACK);
tft->drawString(keybParam.typing + cursorType[cursorTypeFlag], 4, 128 - 5 * 8 + 1);
} else {
tft->setTextColor(TFT_WHITE, TFT_BLACK);
tft->drawString("<" + keybParam.typing.substring(keybParam.typing.length() - 18) +cursorType[cursorTypeFlag], 4, 128 - 5 * 8 + 1);
}
}
void ESPboyTerminalGUI::drawOwnTypingLine(String typingLine, uint16_t colorLine){
keybParam.typing = typingLine;
toggleDisplayMode(0);
keybParam.typing = typingLine;
tft->fillRect(1, 128 - 5 * 8, 126, 10, TFT_BLACK);
tft->setTextColor(colorLine, TFT_BLACK);
tft->drawString(keybParam.typing, 4, 128 - 5 * 8 + 1);
}
void ESPboyTerminalGUI::drawBlinkingCursor() {
static uint32_t cursorBlinkMillis = 0;
if (millis() > (cursorBlinkMillis + GUI_CURSOR_BLINKING_PERIOD)) {
cursorBlinkMillis = millis();
drawTyping(1);
}
}
void ESPboyTerminalGUI::SetKeybParamTyping(String str){
keybParam.typing = str;
}

104
ESPboyTerminalGUI.h Normal file
View file

@ -0,0 +1,104 @@
/*
ESPboyTerminalGUI class
for www.ESPboy.com project by RomanS
https://hackaday.io/project/164830-espboy-games-iot-stem-for-education-fun
v2.1
*/
//!!!!!!!!!!!!!!!!!
#define U8g2 //if defined then using font 4x6, if commented using font 6x8
#define buttonclicks //if defined - button are clicking but it takes more than 1kb RAM, if commented - no clicks and more free RAM
//!!!!!!!!!!!!!!!!!
#ifndef ESPboy_TerminalGUI
#define ESPboy_TerminalGUI
#define CSTFTPIN 8
#include <Adafruit_MCP23017.h>
#include <TFT_eSPI.h>
#include <FS.h>
using fs::FS;
#ifdef U8g2
#include "U8g2_for_TFT_eSPI.h"
#endif
#ifdef U8g2
#define GUI_FONT_WIDTH 4
#define GUI_FONT_HEIGHT 6
#else
#define GUI_FONT_WIDTH 6
#define GUI_FONT_HEIGHT 8
#endif
#define GUI_MAX_CONSOLE_STRINGS 100
#define GUI_MAX_STRINGS_ONSCREEN_FULL ((128-2)/GUI_FONT_HEIGHT)
#define GUI_MAX_STRINGS_ONSCREEN_SMALL ((128-44)/GUI_FONT_HEIGHT)
#define GUI_MAX_TYPING_CHARS 60
#define GUI_KEY_UNPRESSED_TIMEOUT 700
#define GUI_KEY_PRESSED_DELAY_TO_SEND 500
#define GUI_CURSOR_BLINKING_PERIOD 500
#define GUI_KEYB_CALL_DELAY 150 //auto repeat
#define GUI_PAD_LEFT 0x01
#define GUI_PAD_UP 0x02
#define GUI_PAD_DOWN 0x04
#define GUI_PAD_RIGHT 0x08
#define GUI_PAD_ACT 0x10
#define GUI_PAD_ESC 0x20
#define GUI_PAD_LFT 0x40
#define GUI_PAD_RGT 0x80
#define GUI_PAD_ANY 0xff
class ESPboyTerminalGUI{
private:
Adafruit_MCP23017 *mcp;
TFT_eSPI *tft;
#ifdef U8g2
U8g2_for_TFT_eSPI *u8f;
#endif
struct consoleStringS {
String consoleString;
uint16_t consoleStringColor;
};
std::vector <consoleStringS> consoleStringsVector;
struct keyboardParameters{
int16_t renderLine;
uint8_t displayMode;
uint8_t shiftOn;
int8_t selX;
int8_t selY;
String typing;
}keybParam;
const static uint8_t keybOnscr[2][3][21] PROGMEM;
uint8_t keysAction();
void drawConsole(uint8_t onlyLastLine);
void drawKeyboard(uint8_t slX, uint8_t slY, uint8_t onlySelected);
void drawBlinkingCursor();
void drawTyping(uint8_t);
public:
ESPboyTerminalGUI(TFT_eSPI *tftGUI, Adafruit_MCP23017 *mcpGUI);
void SetKeybParamTyping(String str);
uint8_t getKeys();
uint32_t waitKeyUnpressed();
void printConsole(String bfrstr, uint16_t color, uint8_t ln, uint8_t noAddLine);
String getUserInput();
void toggleDisplayMode(uint8_t mode);
void drawOwnTypingLine(String typingLine, uint16_t colorLine);
};
#endif

186
ESPboy_Sub1GHz.ino Normal file
View file

@ -0,0 +1,186 @@
#include "ESPboyInit.h"
#include "ESPboyTerminalGUI.h"
#include "ESPboyLED.h"
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
#define CC1101riceivePin 3
#define CC1101chipSelectPin D8
#define TFTchipSelectPin 8
RCSwitch mySwitch;
ESPboyInit myESPboy;
ESPboyTerminalGUI* terminalGUIobj = NULL;
ESPboyLED myLED;
uint32_t counter;
String bin2tri(uint32_t dec) {
uint8_t pos = 0;
String returnVal="";
String bin;
bin = String(dec,BIN);
while (pos < (bin.length()-1)) {
if (bin[pos]=='0' && bin[pos+1]=='0') returnVal += '0';
else
if (bin[pos]=='1' && bin[pos+1]=='1') returnVal += '1';
else
if (bin[pos]=='0' && bin[pos+1]=='1') returnVal += 'F';
else return "NO";
pos += 2;
}
return returnVal;
}
void output() {
String toPrint;
uint32_t *rawData;
uint32_t dec, lengthval, rssi, lqi;
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
myESPboy.mcp.digitalWrite(CC1101chipSelectPin, LOW);
delay(10);
dec = mySwitch.getReceivedValue();
lengthval = mySwitch.getReceivedBitlength();
rssi = ELECHOUSE_cc1101.getRssi();
lqi = ELECHOUSE_cc1101.getLqi();
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
myESPboy.mcp.digitalWrite(CC1101chipSelectPin, HIGH);
delay(10);
terminalGUIobj->printConsole(" ", TFT_MAGENTA, 1, 1);
terminalGUIobj->printConsole(" ", TFT_MAGENTA, 1, 0);
terminalGUIobj->printConsole(F("-------------------------------"), TFT_YELLOW, 1, 0);
terminalGUIobj->printConsole(F("DETECTED! DECODE:"), TFT_RED, 1, 0);
terminalGUIobj->printConsole(F("-------------------------------"), TFT_YELLOW, 1, 0);
//toPrint = "RSSI/LQI: ";
//toPrint += (String)rssi;
//toPrint += "/";
//toPrint += (String)lqi;
//terminalGUIobj->printConsole(toPrint, TFT_YELLOW, 1, 0);
toPrint="DEC: ";
toPrint+=(String)dec;
toPrint+=" (";
toPrint+= (String)lengthval;
toPrint+= " Bit)";
terminalGUIobj->printConsole(toPrint, TFT_GREEN, 1, 0);
toPrint="BIN: ";
toPrint+= String (dec,BIN);
terminalGUIobj->printConsole(toPrint, TFT_GREEN, 1, 0);
toPrint="TRI: ";
toPrint+= bin2tri(dec);
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
toPrint="PULSE LEN: ";
toPrint+=(String)mySwitch.getReceivedDelay();
toPrint+=" ms";
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
toPrint="FIRST LEV: ";
if (mySwitch.getReceivedLevelInFirstTiming()) toPrint += "HIGH";
else toPrint+= "LOW";
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
toPrint="PROTOCOL: ";
toPrint+=(String)mySwitch.getReceivedProtocol();
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
toPrint="IS INV: ";
if (mySwitch.getReceivedInverted()) toPrint+="YES";
else toPrint+="NO";
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
terminalGUIobj->printConsole(F("DATA: "), TFT_YELLOW, 1, 0);
toPrint="";
rawData = mySwitch.getReceivedRawdata();
for (unsigned int i=0; i<= lengthval*2; i++) toPrint+=((String)rawData[i]+",");
toPrint = toPrint.substring(0,toPrint.length()-1);
terminalGUIobj->printConsole(toPrint, TFT_BLUE, 1, 0);
terminalGUIobj->printConsole(F("-------------------------------"), TFT_YELLOW, 1, 0);
terminalGUIobj->printConsole("", TFT_BLACK, 1, 0);
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
myESPboy.mcp.digitalWrite(CC1101chipSelectPin, LOW);
delay(10);
}
void setup(){
myESPboy.begin("ESPboy Sub1GHz module");
myLED.begin(&myESPboy.mcp);
terminalGUIobj = new ESPboyTerminalGUI(&myESPboy.tft, &myESPboy.mcp);
terminalGUIobj->printConsole(F("Sub1GHz module v1.0"), TFT_MAGENTA, 1, 0);
terminalGUIobj->printConsole("", TFT_BLACK, 1, 0);
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
digitalWrite(CC1101chipSelectPin, LOW);
delay(10);
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.setMHZ(433.92); //The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ.
mySwitch.enableReceive(CC1101riceivePin); // Receiver on interrupt 0 => that is pin #2
ELECHOUSE_cc1101.SetRx(); // set Receive on
}
void loop(){
static String str="";
static uint8_t ledFlag = 1;
if (mySwitch.available()) {
myLED.setRGB(0,20,0);
ledFlag = 1;
counter=millis();
str=".";
myESPboy.playTone(100,100);
output();
mySwitch.resetAvailable();
}
if(millis()-counter>2000){
counter=millis();
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
digitalWrite(CC1101chipSelectPin, HIGH);
delay(10);
terminalGUIobj->printConsole(str, TFT_MAGENTA, 1, 1);
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
digitalWrite(CC1101chipSelectPin, LOW);
str+=".";
if (str.length()>20) str="";
delay(10);
}
if(ledFlag){
ledFlag=0;
myLED.setRGB(0,0,0);
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
digitalWrite(CC1101chipSelectPin, HIGH);
delay(10);
terminalGUIobj->printConsole(F("Listening..."), TFT_MAGENTA, 1, 0);
terminalGUIobj->printConsole(F(""), TFT_MAGENTA, 1, 0);
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
digitalWrite(CC1101chipSelectPin, LOW);
delay(10);
}
delay(1);
}

50
lib/ESPboyLogo.h Normal file
View file

@ -0,0 +1,50 @@
const uint8_t ESPboyLogo[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0,
0x01, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x83, 0x1F, 0xFC, 0x00, 0x00, 0x00,
0x00, 0x00, 0xD0, 0xC3, 0x3F, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0,
0xE3, 0x7F, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE1, 0x7F, 0x78,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x7F, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xA0, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA0, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x7F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x41, 0x3E, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0xF0, 0x83, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
0x03, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x03, 0x00, 0xF4,
0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x03, 0x0F, 0xEC, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0x81, 0x1F, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1E, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1D, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0x01, 0x0F, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
0x03, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x03, 0x0F, 0xF4, 0x00, 0x00, 0x00,
0x00, 0x00, 0xB0, 0x83, 0x1F, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0,
0x81, 0x1F, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1E, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1D, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1E, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xC0, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xC0, 0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3D, 0x40, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3B, 0xC0, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x80, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x07, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
0x0F, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x7E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x0F, 0x00, 0x7A, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC0, 0x0E, 0x00, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x07, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0xE7, 0xF7, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF7,
0xF7, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x30, 0x30, 0xF6, 0xF1,
0xCC, 0x00, 0x00, 0x00, 0xE0, 0xF3, 0x31, 0xF6, 0xFB, 0xCD, 0x00, 0x00,
0x00, 0xE0, 0xE3, 0xF3, 0x37, 0x9B, 0xCD, 0x00, 0x00, 0x00, 0xE0, 0xC0,
0xF7, 0x33, 0x9B, 0xCD, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x36, 0x30, 0x9B,
0xCD, 0x00, 0x00, 0x00, 0xE0, 0xF7, 0x37, 0xF0, 0xFB, 0xFD, 0x00, 0x00,
0x00, 0xE0, 0xF7, 0x33, 0xF0, 0xF1, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00,
};

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,183 @@
/*
ELECHOUSE_CC1101.cpp - CC1101 module library
Copyright (c) 2010 Michael.
Author: Michael, <www.elechouse.com>
Version: November 12, 2010
This library is designed to use CC1101/CC1100 module on Arduino platform.
CC1101/CC1100 module is an useful wireless module.Using the functions of the
library, you can easily send and receive data by the CC1101/CC1100 module.
Just have fun!
For the details, please refer to the datasheet of CC1100/CC1101.
----------------------------------------------------------------------------------------------------------------
cc1101 Driver for RC Switch. Mod by Little Satan. With permission to modify and publish Wilson Shen (ELECHOUSE).
----------------------------------------------------------------------------------------------------------------
*/
#ifndef ELECHOUSE_CC1101_SRC_DRV_h
#define ELECHOUSE_CC1101_SRC_DRV_h
#include <Arduino.h>
//***************************************CC1101 define**************************************************//
// CC1101 CONFIG REGSITER
#define CC1101_IOCFG2 0x00 // GDO2 output pin configuration
#define CC1101_IOCFG1 0x01 // GDO1 output pin configuration
#define CC1101_IOCFG0 0x02 // GDO0 output pin configuration
#define CC1101_FIFOTHR 0x03 // RX FIFO and TX FIFO thresholds
#define CC1101_SYNC1 0x04 // Sync word, high INT8U
#define CC1101_SYNC0 0x05 // Sync word, low INT8U
#define CC1101_PKTLEN 0x06 // Packet length
#define CC1101_PKTCTRL1 0x07 // Packet automation control
#define CC1101_PKTCTRL0 0x08 // Packet automation control
#define CC1101_ADDR 0x09 // Device address
#define CC1101_CHANNR 0x0A // Channel number
#define CC1101_FSCTRL1 0x0B // Frequency synthesizer control
#define CC1101_FSCTRL0 0x0C // Frequency synthesizer control
#define CC1101_FREQ2 0x0D // Frequency control word, high INT8U
#define CC1101_FREQ1 0x0E // Frequency control word, middle INT8U
#define CC1101_FREQ0 0x0F // Frequency control word, low INT8U
#define CC1101_MDMCFG4 0x10 // Modem configuration
#define CC1101_MDMCFG3 0x11 // Modem configuration
#define CC1101_MDMCFG2 0x12 // Modem configuration
#define CC1101_MDMCFG1 0x13 // Modem configuration
#define CC1101_MDMCFG0 0x14 // Modem configuration
#define CC1101_DEVIATN 0x15 // Modem deviation setting
#define CC1101_MCSM2 0x16 // Main Radio Control State Machine configuration
#define CC1101_MCSM1 0x17 // Main Radio Control State Machine configuration
#define CC1101_MCSM0 0x18 // Main Radio Control State Machine configuration
#define CC1101_FOCCFG 0x19 // Frequency Offset Compensation configuration
#define CC1101_BSCFG 0x1A // Bit Synchronization configuration
#define CC1101_AGCCTRL2 0x1B // AGC control
#define CC1101_AGCCTRL1 0x1C // AGC control
#define CC1101_AGCCTRL0 0x1D // AGC control
#define CC1101_WOREVT1 0x1E // High INT8U Event 0 timeout
#define CC1101_WOREVT0 0x1F // Low INT8U Event 0 timeout
#define CC1101_WORCTRL 0x20 // Wake On Radio control
#define CC1101_FREND1 0x21 // Front end RX configuration
#define CC1101_FREND0 0x22 // Front end TX configuration
#define CC1101_FSCAL3 0x23 // Frequency synthesizer calibration
#define CC1101_FSCAL2 0x24 // Frequency synthesizer calibration
#define CC1101_FSCAL1 0x25 // Frequency synthesizer calibration
#define CC1101_FSCAL0 0x26 // Frequency synthesizer calibration
#define CC1101_RCCTRL1 0x27 // RC oscillator configuration
#define CC1101_RCCTRL0 0x28 // RC oscillator configuration
#define CC1101_FSTEST 0x29 // Frequency synthesizer calibration control
#define CC1101_PTEST 0x2A // Production test
#define CC1101_AGCTEST 0x2B // AGC test
#define CC1101_TEST2 0x2C // Various test settings
#define CC1101_TEST1 0x2D // Various test settings
#define CC1101_TEST0 0x2E // Various test settings
//CC1101 Strobe commands
#define CC1101_SRES 0x30 // Reset chip.
#define CC1101_SFSTXON 0x31 // Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1).
// If in RX/TX: Go to a wait state where only the synthesizer is
// running (for quick RX / TX turnaround).
#define CC1101_SXOFF 0x32 // Turn off crystal oscillator.
#define CC1101_SCAL 0x33 // Calibrate frequency synthesizer and turn it off
// (enables quick start).
#define CC1101_SRX 0x34 // Enable RX. Perform calibration first if coming from IDLE and
// MCSM0.FS_AUTOCAL=1.
#define CC1101_STX 0x35 // In IDLE state: Enable TX. Perform calibration first if
// MCSM0.FS_AUTOCAL=1. If in RX state and CCA is enabled:
// Only go to TX if channel is clear.
#define CC1101_SIDLE 0x36 // Exit RX / TX, turn off frequency synthesizer and exit
// Wake-On-Radio mode if applicable.
#define CC1101_SAFC 0x37 // Perform AFC adjustment of the frequency synthesizer
#define CC1101_SWOR 0x38 // Start automatic RX polling sequence (Wake-on-Radio)
#define CC1101_SPWD 0x39 // Enter power down mode when CSn goes high.
#define CC1101_SFRX 0x3A // Flush the RX FIFO buffer.
#define CC1101_SFTX 0x3B // Flush the TX FIFO buffer.
#define CC1101_SWORRST 0x3C // Reset real time clock.
#define CC1101_SNOP 0x3D // No operation. May be used to pad strobe commands to two
// INT8Us for simpler software.
//CC1101 STATUS REGSITER
#define CC1101_PARTNUM 0x30
#define CC1101_VERSION 0x31
#define CC1101_FREQEST 0x32
#define CC1101_LQI 0x33
#define CC1101_RSSI 0x34
#define CC1101_MARCSTATE 0x35
#define CC1101_WORTIME1 0x36
#define CC1101_WORTIME0 0x37
#define CC1101_PKTSTATUS 0x38
#define CC1101_VCO_VC_DAC 0x39
#define CC1101_TXBYTES 0x3A
#define CC1101_RXBYTES 0x3B
//CC1101 PATABLE,TXFIFO,RXFIFO
#define CC1101_PATABLE 0x3E
#define CC1101_TXFIFO 0x3F
#define CC1101_RXFIFO 0x3F
//************************************* class **************************************************//
class ELECHOUSE_CC1101
{
private:
void SpiStart(void);
void SpiEnd(void);
void GDO_Set (void);
void Reset (void);
void setSpi(void);
void RegConfigSettings(void);
void Calibrate(void);
void Split_PKTCTRL0(void);
void Split_PKTCTRL1(void);
void Split_MDMCFG1(void);
void Split_MDMCFG2(void);
void Split_MDMCFG4(void);
public:
void Init(void);
byte SpiReadStatus(byte addr);
void setSpiPin(byte sck, byte miso, byte mosi, byte ss);
void setGDO(byte gdo0, byte gdo2);
void setCCMode(bool s);
void setModulation(byte m);
void setPA(int p);
void setMHZ(float mhz);
void setChannel(byte chnl);
void setChsp(float f);
void setRxBW(float f);
void setDRate(float d);
void setDeviation(float d);
void SetTx(void);
void SetRx(void);
void SetTx(float mhz);
void SetRx(float mhz);
int getRssi(void);
byte getLqi(void);
void setSres(void);
void SendData(byte *txBuffer, byte size);
void SendData(char *txchar);
void SendData(byte *txBuffer, byte size, int t);
void SendData(char *txchar, int t);
byte CheckReceiveFlag(void);
byte ReceiveData(byte *rxBuffer);
bool CheckCRC(void);
void SpiStrobe(byte strobe);
void SpiWriteReg(byte addr, byte value);
void SpiWriteBurstReg(byte addr, byte *buffer, byte num);
byte SpiReadReg(byte addr);
void SpiReadBurstReg(byte addr, byte *buffer, byte num);
void setClb(byte b, byte s, byte e);
void setSyncWord(byte sh, byte sl);
void setAddr(byte v);
void setWhiteData(bool v);
void setPktFormat(byte v);
void setCrc(bool v);
void setLengthConfig(byte v);
void setPacketLength(byte v);
void setDcFilterOff(bool v);
void setManchester(bool v);
void setSyncMode(byte v);
void setFEC(bool v);
void setPQT(byte v);
void setCRC_AF(bool v);
void setAppendStatus(bool v);
void setAdrChk(byte v);
bool CheckRxFifo(int t);
};
extern ELECHOUSE_CC1101 ELECHOUSE_cc1101;
#endif

View file

@ -0,0 +1,22 @@
----------------------------------------------------------------------------------------------------------------
cc1101 Driver for RC Switch. Mod by Little Satan. With permission to modify and publish Wilson Shen (ELECHOUSE).
----------------------------------------------------------------------------------------------------------------
ELECHOUSE_CC1101.cpp - CC1101 module library
Copyright (c) 2010 Michael.
Author: Michael, <www.elechouse.com>
Version: November 12, 2010
This library is designed to use CC1101/CC1100 module on Arduino platform.
CC1101/CC1100 module is an useful wireless module.Using the functions of the
library, you can easily send and receive data by the CC1101/CC1100 module.
Just have fun!
For the details, please refer to the datasheet of CC1100/CC1101.
notes: The whole stuff that is not directly related to Rc_Switch,
NewRemoteSwitch or Elechouse_cc1101 Lib is Copyright (c) 2018 - 2020 by Little Satan.
Example calculator codes in the driver lib.
And so on...
You can freely use, edit or distribute it with reference to the source.
For everything else, the rights of the respective owners apply!

View file

@ -0,0 +1,568 @@
# SmartRC-CC1101-Driver-Lib_V2.5.2
Note: Find out about the laws in your country.
Use at your own risk.
---------------------------------------------
Announcements / other
---------------------------------------------
For debug and advanced functions: https://github.com/LSatan/CC1101-Debug-Service-Tool
new library Simu_Remote: https://github.com/LSatan/Simu_Remote_CC1101
---------------------------------------------
Install:
---------------------------------------------
Can be downloaded directly from the Arduino library manager. Just search for cc1101.
---------------------------------------------
Foreword:
---------------------------------------------
First of all, thanks to Elechouse that I can make the modified library accessible to everyone.
Link: http://www.elechouse.com/elechouse/
The library has been redesigned and some improvements have been made.
Among other things, you can now also use the internal send / receive function.
I would be happy to receive your suggestions for further examples from other libraries.
All examples included are listed in the next field.
---------------------------------------------
Containing examples:
---------------------------------------------
1.Elechouse CC1101:
-
Description: CC1101 Internal send / receive examples. Supported modulations 2-FSK, GFSK, ASK/OOK, 4-FSK, MSK.
2.Rc-Switch:
-
<p>Description: Arduino lib to operate 433/315Mhz devices like power outlet sockets.</p>
<p>Link: https://github.com/sui77/rc-switch</p>
3.NewRemoteswitch:
-
<p>Description: This library provides an easy class for Arduino, to send and receive signals used by some common "new style" 433MHz remote control switches.</p>
<p>Link: https://github.com/1technophile/NewRemoteSwitch</p>
4.RemoteSensor library:
-
<p>Description: This library provides an easy class for Arduino, to send and receive signals used by some common weather stations using -remote 433MHz sensors.</p>
<p>Link: https://github.com/mattwire/arduino-dev/tree/master/libraries/RemoteSensor</p>
5.ESPiLight:
-
<p>Description:This Arduino library is a port of the pilight 433.92MHz protocols to the Arduino platform. It was tested with a ESP8266. The aim is to transmit, receive and parse many 433.92MHz protocols, by providing a simple Arduino friendly API. This should help to implement IoT bridges between the 434MHz-RF band and internet protocols.</p>
<p>Link:https://github.com/puuu/ESPiLight</p>
---------------------------------------------
Instructions / Description:
---------------------------------------------
This driver library can be used for many libraries that use a simple RF ASK module,
with the advantages of the cc1101 module.It offers many direct setting options as in
SmartRF Studio and calculates settings such as MHz directly.
The most important functions at a glance:
ELECHOUSE_cc1101.Init(); //Initialize the cc1101. Must be set first!
ELECHOUSE_cc1101.setPA(PA); //Set transmission power.
ELECHOUSE_cc1101.setMHZ(MHZ); //Set the basic frequency.
ELECHOUSE_cc1101.SetTx(); //Set transmit on.
ELECHOUSE_cc1101.SetTx(MHZ); //Sets transmit on and changes the frequency.
ELECHOUSE_cc1101.SetRX(); //Set receive on.
ELECHOUSE_cc1101.SetRx(MHZ); //Sets receive on and changes the frequency.
ELECHOUSE_cc1101.setRxBW(RXBW); //Set Receive filter bandwidth
ELECHOUSE_cc1101.setGDO(GDO0, GDO2); //Put the Gdo pins. For libraries that address the gdo pins directly.
ELECHOUSE_cc1101.setSpiPin(SCK, MISO, MOSI, CSN); //custom SPI pins. Set your own Spi Pins.Or to switch between multiple cc1101. Must be set before init and before changing the cc1101.
ELECHOUSE_cc1101.setChannel(chnl); //Set Channel from 0 to 255. default = 0(basic frequency).
ELECHOUSE_cc1101.setClb(fband, cal1, cal2); //Optionally enter Offset Callibration. Requirements: Sketch Calibrate_frequency.ino below [CC1101-Debug-Service-Tool](https://github.com/LSatan/CC1101-Debug-Service-Tool/tree/master/Calibrate_frequency).A SDR receiver and SDR software.
All can also be used in a loop and are applied directly.
---------------------------------------------
Wiring:
---------------------------------------------
Notes: A logic level converter is recommended for arduino. It also works well without. Use at your own risk.
<img src="https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/img/Nano_CC1101.png"/>
<img src="https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/img/MEGA_CC1101.png"/>
<img src="https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/img/Esp8266_CC1101.png"/>
<img src="https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/img/Esp32_CC1101.png"/>
<img src="https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/img/TXS0108E_CC1101.png"/>
<img src="https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/img/Wiring_CC1101.png"/>
---------------------------------------------
Donation
---------------------------------------------
If you like the library, I would be happy about a star.
you can support me with a donation.
https://www.paypal.me/LittleSatan666
Thank You!
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.2
---------------------------------------------
01.10.2020
Driver Library :SpiWriteReg, SpiReadReg, SpiWriteBurstReg and SpiReadBurstReg change to public. Allows additional modifications from sketch.
Driver Library :Setrx no longer has to be set to receive.(internal transmission methods)
Driver Library :Gdo pins are now set to input / output with set gdo instead of Init.
Driver Library :Added new sending method. Allows sending without a gdo0 pin.
notes :The new internal send and receive methods now work completely without an additional gdo pin.
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.1
---------------------------------------------
18.08.2020
Driver Library :When changing from receiving to sending, the program freezes (internal send functions). fixed!
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.0
---------------------------------------------
16.08.2020
Driver Library :Rssi was calculated incorrectly.Fixed Thanks to zapquiyou!
Driver Library :New receiving method for internal examples added. Allows several actions to be carried out in the loop.
Driver Library :Internal Crc check added for internal examples.
Driver Library :Simplification to send char added for internal transfer examples.
Driver Library :A lot of new settings added for internal transmission examples. Everything can be set as in SmartRF Studio and is calculated automatically. An overview: setDeviation, setChsp, setRxBW, setDRate, setSyncMode, setSyncWord, setAdrChk, setAddr, setWhiteData, setPktFormat, setLengthConfig, setPacketLength, setCrc, setCRC_AF, setDcFilterOff, setManchester, setFEC, setPQT, setAppendStatus. description in the examples!
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.4.0
---------------------------------------------
07.05.2020
Driver Library :frequency calculator has been simplified. error-free calculations and less variables.
Driver Library :Added frequency calibration option.
Driver Library :Certain frequencies could not be set. Fixed! Big thanks to gusgorman402!
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.3.5
---------------------------------------------
14.04.2020
Driver Library :setChsp has been removed to save space. This function is available in the Service / Debug Tool as an extended function.
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.3.4
---------------------------------------------
01.04.2020
Driver Library :set AGCCTRL2 from 0x07 to 0xC7. Reception is significantly improved!
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.3.3
---------------------------------------------
01.04.2020
Driver Library :set FSCTRL1 from 0x08 to 0x06. for better receive.
Driver Library :set SpiWriteReg to public. Make it fit for debug tool!
Driver Library :set SpiStrobe to public. Make it fit for debug tool!
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.3.2
---------------------------------------------
24.03.2020
Driver Library :Set gdo2 from input to output. Errors in libraries that use the pins directly.
examples :Set gdo2 from setting 2 to 0 in default examples. Gdo2 is not required for these examples.
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.3.1
---------------------------------------------
18.03.2020
Driver Library :ESP8266/32 core panik. Fixed! The cc1101 must be initialized before setting options!
examples :all examples have been adapted.
examples :internal cc1101 examples have been adapted for esp8266/32.
examples :ESPiLight examples added.
---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.3
---------------------------------------------
18.03.2020
Driver Library :"RcSwitch-cc1101-driver-lib" becomes "SmartRC-cc1101-driver-lib".
Pull request :#20 Removed unnecessary initializations when setting Tx or Rx mode. Agreed / accepted improves speed when changing rx / tx. Special thanks to fleibede.
Pull request :#19 Added spi state after SPI pins have been set for default pins. The problem was solved differently. Special thanks to fleibede.
Pull request :#18 Updated AVR types conditional defines. Agreed / accepted. Special thanks to fleibede.
Driver Library :Frequency calculator certain frequencies were calculated incorrectly. fixed!
Driver Library :Intelligent Pa Table system added. When changing the band The corresponding table is set via setTx / Rx and the frequency set to basic calibrated. All module internal transmission powers can now be set according to the band.
Driver Library :Newly calibrated base frequency on chan 0 according to the SmartRF Studio.
Driver Library :Channel spacing calculator can enter directly the spacing area in khz.
Driver Library :Modulation setting added for internal transmission methods
Driver Library :ESP32 reception improvements.
Driver Library :Direct conversion of the RSSI level in the library.
Driver Library :Correction of version numbering.
examples :New examples added "RemoteSensor library".
examples :New examples added "Elechouse CC1101 default examples"
examples :Remote Fusion has been removed and given an extra library.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V2.2.1
---------------------------------------------
[Download Release V2.2.1](https://drive.google.com/file/d/1YHFpp2GQC96-GKcg67Tym9wt1E4CBdFc/view?usp=sharing)
20.01.2019
Driver Library :Spi options have been removed. (Problems with ESP32) FIXED!
notes :everything was checked again. D-SUN module on esp8266 / 32 and so on.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V2.2
---------------------------------------------
17.01.2019
Version notes :Spi was reconfigured for fix some issuses.
Driver Library :HotFix for cc1101 module with "8pins"(example DSun). Transmitting on Esp8266 based bords not work. FIXED!
Driver Library :Change "SpiReadStatus" to public. Now can read RSSI Level!
Driver Library :Spi transfer rate was limited to cc1101 max transfer rate (10mhz).
Driver Library :After using Spi, it will now be disabled. (receive data from serial monitor and rx pin was not working on Esp 8266/32) FIXED!
Add Examples :ReceiveDemo_Simple_with_RSSI_cc1101.ino (Shows reception strength)
Add Examples :Frequency_Scanner_cc1101.ino (Scans Transmitting frequency of your remotes. No good results with cc1101-DSun)
Add Examples :ProtocolAnalyzeDemo_cc1101.ino (for scan unknown protokolls. Requires: link is in sketch!)
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V2.1
---------------------------------------------
3.1.2019
Driver Library :Spi corrections for esp32. Spi Pin changes did not work on esp32. FIXED!
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V2.0
---------------------------------------------
18.12.2018
Driver Library :Own Spi pin settings possible. Allows the use of other microcontrollers. Allows you to use multiple CC1101s. More information in the commands.txt
Add TXT :driver lib commands and examples.txt
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.9.3
---------------------------------------------
27.11.2018
Driver Library :setESP8266 has been removed. Pins are set automatically with the init command.
Driver Library :Arduino mega SPI pins added.
Driver Library :Added setGDO pins (For libraries that directly address the GDO pins).Like this https://github.com/EinfachArne/Somfy_Remote .
Example ELECHOUSE_CC1101.setGDO(2, 4); // (pin2 = GDO0, pin4 = GDO2).
Add Wiring TXT :WIRING MEGA.txt
Add Wiring JPG :WIRING MEGA.jpg
LICENSE :LICENSE.txt Update.
notes :setGDO is not compatible with RC_Switch / NewRemotSwitch.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.9.2
---------------------------------------------
16.11.2018
Fixes Remotes Fusion :Receive mode and Repeater mode frequency, changes to the transmitter frequency after pressing on a transmitter. (RemotesFusion.ino)Fixed!
NewRemoteSwitch :LearnCode_cc1101.ino (corrections).
Added :Keywords.txt added.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.9.1
---------------------------------------------
07.11.2018
New Sketch :Clear_EEPROM.ino (if there are problems with the access point password or if you want to use your ESP for other projects).
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.9
---------------------------------------------
18.10.2018
New Sketch :RemotesFusion.ino.
New Apk´s :RemotesFusion_V1_en.apk / RemotesFusion_V1_de.apk.
Add Docs :Docs and manuals for RemotesFusion.
Changes :channel spacing and channel set was removed from the examples. unnecessary because exact frequency can be set.
notes :RemotesFusion is an application with which Rc-Switch and NewRemoteSwitch can be controlled at the same time.
A universal remote control APP with many possibilities. Only for Esp 8266/32 modules! For more information, watch the docs.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.8
---------------------------------------------
[Download Release V1.8](https://drive.google.com/file/d/1ADKOmW0SrUoomeoDskFrm0J2SdwCLB_O/view?usp=sharing)
02.09.2018
Driver Library :Added pin settings for esp32.
Examples :Added pin settings for esp32 examples.
Add Wiring JPG :Add Wiring JPG esp32.
Add Wiring TXT :Add Wiring TXT esp32.
Add Wiring JPG :Add Wiring JPG esp32 for Receive_Send_Decimal_Demo_Simple.ino.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.7.2
---------------------------------------------
[Download Release V1.7.2](https://drive.google.com/file/d/1sfMvQw2JaGARTaYXZevOjB20BFOMS0tw/view?usp=sharing)
16.08.2018
Examples :All NewRemoteSwitch examples are compatible with ESP. Exception Retransmitter_cc1101.ino.
Driver Library :Frequency calculator calibrated. Difference -0.01 MHz. (Fixed!) Frequency is now accurate.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.7.1
---------------------------------------------
[Download Release V1.7.1](https://drive.google.com/file/d/1PXa1k0AIDY8bTMxFyyQMbOljijhIn1ke/view?usp=sharing)
10.08.2018
Driver Library :Now you can Switch the frequency in loop. Examples: ELECHOUSE_cc1101.SetTx(433.92); and ELECHOUSE_cc1101.SetRx(433.92);.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.7
---------------------------------------------
[Download Release V1.7](https://drive.google.com/file/d/1uxACfe1ZUrkL4S3_NPVN0DmUfzbxt6oQ/view?usp=sharing)
09.08.2018
Driver Library :Now you can enter your base frequency directly.The library calculates the settings automatically. example(433.92)
Driver Library :Remove freq2, freq1 and freq0 Settings.
Driver Library :Removed unnecessary entries. the library shrank from 32,8kb(.cpp) and 9,38kb(.h) to 17,0kb(.cpp) and 7,87kb(.h).
New Example :(NewRemoteSwitch Library) NewRemoteRepeater.ino. Repeat the Received signal 1to1. Best thanks to Roman for write it.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.6.1
---------------------------------------------
[Download Release V1.6.1](https://drive.google.com/file/d/1q8FV5kDnhAj1SMZf6DS0wDcm5xo4E-5-/view?usp=sharing)
05.08.2018
Examples Fix (rc-switch):Fix auto receive pulse. Received pulse don´t transmit. Fixed!(Repeater.ino and Receive_Send_Decimal_Demo_Simple.ino).
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.6
---------------------------------------------
[Download Release V1.6](https://drive.google.com/file/d/1p_iAxh7ZWlNWhFoqMM_tlLTLdyGK07-a/view?usp=sharing)
03.08.2018
Esp8266 :Compatibility for all RC switch examples.
Driver Library :Add the GDO2 pin for Receive. Change GDO0 to send.
Wiring changes :Description in jpg's and txt's.
Examples :All examples have been adjusted.
Examples :Esp and Arduino are set automatically.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.5
---------------------------------------------
[Download Release V1.5](https://drive.google.com/file/d/1XcGPbvI5v2PcpnVBbjtOFwtuJtx3jMK4/view?usp=sharing)
31.07.2018
New :Supportet NewRemoteSwitch Library. For wireless sockets by trust smart home, Smappee, DI-O Chacon, Intertechno and others.
You want to use it? Then you need that https://github.com/1technophile/NewRemoteSwitch
Add Examples :NewRemoteSwitch Compatible examples.
Driver Library :You can now switch directly from Tx to Rx in the loop. Without resetting the cc1101.
Add Examples :New Repeater Example for Rc-switch. For example, to increase the range of your remote control.
Example changes :Receive_Send_Decimal_Demo_Simple.ino (remove unnecessary commands).
Examples Fix :Rc-Switch examples fix TypeA, TypeB and TypeD (missing from semicolon to SetTx).
Notes :NewRemoteSwitch examples Retransmitter_cc1101.ino and LightShow_cc1101.ino only Arduino!!!
Notes :Rc-switch example Repeater_cc1101.ino only Arduino!!!
Notes :Rc-switch example Receive_Send_Decimal_Demo_Simple.ino only Arduino!!!
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.4
---------------------------------------------
[Download Release V1.4](https://drive.google.com/file/d/1nAPGeQSutfskirJsng44adB4sXU1YU6A/view?usp=sharing)
26.07.2018
Driver Library :esp8266 Compatibility (Tested with Wemos d1 mini).
Driver Library :Change default Receive filter bandwidth to 812khz (max).
Driver Library :Change default Tx Power to PA10 (max).
Examples :Add set esp command and pin settings.
Examples :Diskription change.
Demo Example :Add auto Recive and Send pulse length. (Receive_Send_Decimal_Demo_Simple.ino)
Add Wiring JPG :Add Wiring JPG esp8266.
Add Wiring TXT :Add Wiring TXT esp8266.
Notes :esp8266 pin D4 don´t work with receive, Transmit and receive is set to D2.
Notes :esp8266 don´t work with Receive_Send_Decimal_Demo_Simple.ino (freezes when reset cc1101).
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.3.1
---------------------------------------------
[Download Release V1.3.1](https://drive.google.com/file/d/1iKmagldd14O1Boa9Z_PDpXbHRECYUPdt/view?usp=sharing)
30.03.2018:
Driver Library Fix :no effect set by transmission power.
Driver Library :Transmitting power can be adjusted via frequency(example in the sketches).
Examples :Command Tx Power cleared.
Examples Fix :set Receive filter bandwidth (command incomplete) Fixed.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.3
---------------------------------------------
[Download Release V1.3](https://drive.google.com/file/d/1q56Qewk8-Aquv1epss1gd7Gc05q4GrbO/view?usp=sharing)
25.03.2018:
Driver Library :Add Channel List. Now you can set channel numbers 0-255.
Driver Library :Add bandwidth can be adjusted
Driver Library :transmission power can be adjusted
Driver Library :can set your own frequency settings (freq2, freq1, freq0)
Driver Library :Channel spacing can be set.
Examples :Add set new commands
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.2
---------------------------------------------
[Download Release V1.2](https://drive.google.com/file/d/1KLJt8ygszj9rqcttiEMt5zCnJKHc_qe3/view?usp=sharing)
20.03.2018:
Driver Library :Add 315Mhz Support.
Driver Library :Add Channel command for finetune (80khz steps) from 420mhz - 440mhz / 302mhz - 322mhz.
Examples :Add set channel command in examples.
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.1
---------------------------------------------
[Download Release V1.1](https://drive.google.com/file/d/1uZzcY4uoduiUjFZzXdxA-ucLoA_TtC1f/view?usp=sharing)
19.03.2018:
Driver Library Fix :Calibrated Frequency from 433.86 to 433.92 - 433.93 Mhz.
Driver Library :cc1101 reset command added (allows switching between send and receive.)
New Demo Example :Receive_Send_Decimal_Demo_Simple.ino (Sends last received decimal code)
To illustrate the change between RX and TX (press button = send / do not press button = receive)
Add Wiring JPG :Wiring for Receive_Send_Decimal_Demo_Simple.ino
Add Wiring JPG :Wiring for Nano / Uno
---------------------------------------------
Changelog: RCSwitch-CC1101-Driver-Lib_V1.0
---------------------------------------------
[Download Release V1.0](https://drive.google.com/file/d/14538RtiEakZ_8yioXJT32XneheSjDqxi/view?usp=sharing)
18.03.2018:
cc1101 Compatibility for RC-Switch.
cc1101 RC-Switch Compatible examples.

View file

@ -0,0 +1,74 @@
//New receiving method. This method checks the Rx Fifo for any data it contains.
//It allows you to do several things in a loop.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
void setup(){
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
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.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.
Serial.println("Rx Mode");
}
byte buffer[61] = {0};
void loop(){
//Checks whether something has been received.
//When something is received we give some time to receive the message in full.(time in millis)
if (ELECHOUSE_cc1101.CheckRxFifo(100)){
//CRC Check. If "setCrc(false)" crc returns always OK!
if (ELECHOUSE_cc1101.CheckCRC()){
//Rssi Level in dBm
Serial.print("Rssi: ");
Serial.println(ELECHOUSE_cc1101.getRssi());
//Link Quality Indicator
Serial.print("LQI: ");
Serial.println(ELECHOUSE_cc1101.getLqi());
//Get received Data and calculate length
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
buffer[len] = '\0';
//Print received in char format.
Serial.println((char *) buffer);
//Print received in bytes format.
for (int i = 0; i<len; i++){
Serial.print(buffer[i]);
Serial.print(",");
}
Serial.println();
}
}
}

View file

@ -0,0 +1,44 @@
//New receiving method. This method checks the Rx Fifo for any data it contains.
//It allows you to do several things in a loop.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
void setup(){
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
Serial.println("Rx Mode");
}
byte buffer[61] = {0};
void loop(){
//Checks whether something has been received.
//When something is received we give some time to receive the message in full.(time in millis)
if (ELECHOUSE_cc1101.CheckRxFifo(100)){
if (ELECHOUSE_cc1101.CheckCRC()){ //CRC Check. If "setCrc(false)" crc returns always OK!
Serial.print("Rssi: ");
Serial.println(ELECHOUSE_cc1101.getRssi());
Serial.print("LQI: ");
Serial.println(ELECHOUSE_cc1101.getLqi());
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
buffer[len] = '\0';
Serial.println((char *) buffer);
for (int i = 0; i<len; i++){
Serial.print(buffer[i]);
Serial.print(",");
}
Serial.println();
}
}
}

View file

@ -0,0 +1,59 @@
//New transmission method.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
byte transmitt_byte[11] = {72,101,108,108,111,32,87,111,114,108,100};
char *transmitt_char = "Hello World";
void setup() {
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
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.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.
Serial.println("Tx Mode");
}
void loop() {
//3 different methods to send data without gdo
//When sending, we give a little time to completely transmit the message (time in millis).
//You can shorten the time. It depends on the data rate and the packet length. Just try it out for fine tuning.
//Transmitt "Hello World" from byte format.
ELECHOUSE_cc1101.SendData(transmitt_byte, 11, 100);
delay(2000);
//Transmitt "Hello World" from char format.
ELECHOUSE_cc1101.SendData(transmitt_char, 100);
delay(2000);
//Transmitt "Hello World" from char format directly.
ELECHOUSE_cc1101.SendData("Hello World", 100);
delay(2000);
}

View file

@ -0,0 +1,41 @@
//New transmission method.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
byte transmitt_byte[11] = {72,101,108,108,111,32,87,111,114,108,100};
char *transmitt_char = "Hello World";
void setup() {
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
// 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.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
Serial.println("Tx Mode");
}
void loop() {
//3 different methods to send data without gdo
//When sending, we give a little time to completely transmit the message (time in millis).
//You can shorten the time. It depends on the data rate and the packet length. Just try it out for fine tuning.
//Transmitt "Hello World" from byte format.
ELECHOUSE_cc1101.SendData(transmitt_byte, 11, 100);
delay(2000);
//Transmitt "Hello World" from char format.
ELECHOUSE_cc1101.SendData(transmitt_char, 100);
delay(2000);
//Transmitt "Hello World" from char format directly.
ELECHOUSE_cc1101.SendData("Hello World", 100);
delay(2000);
}

View file

@ -0,0 +1,60 @@
//New transmission method.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
const int n = 61;
byte buffer[n] = "";
void setup() {
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
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.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.
Serial.println("Tx Mode");
}
void loop() {
//When sending, we give a little time to completely transmit the message (time in millis).
//You can shorten the time. It depends on the data rate and the packet length. Just try it out for fine tuning.
if (Serial.available()) {
int len = Serial.readBytesUntil('\n', buffer, n);
buffer[len] = '\0';
Serial.println((char *)buffer);
ELECHOUSE_cc1101.SendData(buffer, len, 100);
Serial.print("Buffer: ");
for (int i = 0; i<len; i++){
Serial.println(buffer[i]);
}
Serial.print("len: ");
Serial.println(len);
}
}

View file

@ -0,0 +1,42 @@
//New transmission method.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
const int n = 61;
byte buffer[n] = "";
void setup() {
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
// 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.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
Serial.println("Tx Mode");
}
void loop() {
//When sending, we give a little time to completely transmit the message (time in millis).
//You can shorten the time. It depends on the data rate and the packet length. Just try it out for fine tuning.
if (Serial.available()) {
int len = Serial.readBytesUntil('\n', buffer, n);
buffer[len] = '\0';
Serial.println((char *)buffer);
ELECHOUSE_cc1101.SendData(buffer, len, 100);
Serial.print("Buffer: ");
for (int i = 0; i<len; i++){
Serial.println(buffer[i]);
}
Serial.print("len: ");
Serial.println(len);
}
}

View file

@ -0,0 +1,82 @@
// These examples are from the Electronics Cookbook by Simon Monk
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
// mod by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int gdo0;
void setup(){
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
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.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.
Serial.println("Rx Mode");
}
byte buffer[61] = {0};
void loop(){
//Checks whether something has been received.
if (ELECHOUSE_cc1101.CheckReceiveFlag()){
//CRC Check. If "setCrc(false)" crc returns always OK!
if (ELECHOUSE_cc1101.CheckCRC()){
//Rssi Level in dBm
Serial.print("Rssi: ");
Serial.println(ELECHOUSE_cc1101.getRssi());
//Link Quality Indicator
Serial.print("LQI: ");
Serial.println(ELECHOUSE_cc1101.getLqi());
//Get received Data and calculate length
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
buffer[len] = '\0';
//Print received in char format.
Serial.println((char *) buffer);
//Print received in bytes format.
for (int i = 0; i<len; i++){
Serial.print(buffer[i]);
Serial.print(",");
}
Serial.println();
}
}
}

View file

@ -0,0 +1,51 @@
// These examples are from the Electronics Cookbook by Simon Monk
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
// mod by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int gdo0;
void setup(){
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
Serial.println("Rx Mode");
}
byte buffer[61] = {0};
void loop(){
if (ELECHOUSE_cc1101.CheckReceiveFlag()){
if (ELECHOUSE_cc1101.CheckCRC()){ //CRC Check. If "setCrc(false)" crc returns always OK!
Serial.print("Rssi: ");
Serial.println(ELECHOUSE_cc1101.getRssi());
Serial.print("LQI: ");
Serial.println(ELECHOUSE_cc1101.getLqi());
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
buffer[len] = '\0';
Serial.println((char *) buffer);
for (int i = 0; i<len; i++){
Serial.print(buffer[i]);
Serial.print(",");
}
Serial.println();
}
}
}

View file

@ -0,0 +1,68 @@
// These examples are from the Electronics Cookbook by Simon Monk
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
// mod by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int gdo0;
byte transmitt_byte[11] = {72,101,108,108,111,32,87,111,114,108,100};
char *transmitt_char = "Hello World";
void setup() {
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
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.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.
Serial.println("Tx Mode");
}
void loop() {
//3 different methods to send data
//Transmitt "Hello World" from byte format.
ELECHOUSE_cc1101.SendData(transmitt_byte, 11);
delay(2000);
//Transmitt "Hello World" from char format.
ELECHOUSE_cc1101.SendData(transmitt_char);
delay(2000);
//Transmitt "Hello World" from char format directly.
ELECHOUSE_cc1101.SendData("Hello World");
delay(2000);
}

View file

@ -0,0 +1,48 @@
// These examples are from the Electronics Cookbook by Simon Monk
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
// mod by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int gdo0;
byte transmitt_byte[11] = {72,101,108,108,111,32,87,111,114,108,100};
char *transmitt_char = "Hello World";
void setup() {
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
// 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.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
Serial.println("Tx Mode");
}
void loop() {
//3 different methods to send data
//Transmitt "Hello World" from byte format.
ELECHOUSE_cc1101.SendData(transmitt_byte, 11);
delay(2000);
//Transmitt "Hello World" from char format.
ELECHOUSE_cc1101.SendData(transmitt_char);
delay(2000);
//Transmitt "Hello World" from char format directly.
ELECHOUSE_cc1101.SendData("Hello World");
delay(2000);
}

View file

@ -0,0 +1,67 @@
// These examples are from the Electronics Cookbook by Simon Monk
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
// mod by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int gdo0;
const int n = 61;
byte buffer[n] = "";
void setup() {
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
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.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.
Serial.println("Tx Mode");
}
void loop() {
if (Serial.available()) {
int len = Serial.readBytesUntil('\n', buffer, n);
buffer[len] = '\0';
Serial.println((char *)buffer);
ELECHOUSE_cc1101.SendData(buffer, len);
Serial.print("Buffer: ");
for (int i = 0; i<len; i++){
Serial.println(buffer[i]);
}
Serial.print("len: ");
Serial.println(len);
}
}

View file

@ -0,0 +1,48 @@
// These examples are from the Electronics Cookbook by Simon Monk
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
// mod by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int gdo0;
const int n = 61;
byte buffer[n] = "";
void setup() {
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
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.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
// 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.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
Serial.println("Tx Mode");
}
void loop() {
if (Serial.available()) {
int len = Serial.readBytesUntil('\n', buffer, n);
buffer[len] = '\0';
Serial.println((char *)buffer);
ELECHOUSE_cc1101.SendData(buffer, len);
Serial.print("Buffer: ");
for (int i = 0; i<len; i++){
Serial.println(buffer[i]);
}
Serial.print("len: ");
Serial.println(len);
}
}

View file

@ -0,0 +1,59 @@
/*
Basic ESPiLight receive raw (pulse train) signal example
https://github.com/puuu/espilight
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <ESPiLight.h>
int RECEIVER_PIN; // any intterupt able pin
int TRANSMITTER_PIN;
ESPiLight rf(TRANSMITTER_PIN); // use -1 to disable transmitter
// callback function. It is called on successfully received and parsed rc signal
void rfRawCallback(const uint16_t* codes, size_t length) {
// print pulse lengths
Serial.print("RAW signal: ");
for (unsigned int i = 0; i < length; i++) {
Serial.print(codes[i]);
Serial.print(' ');
}
Serial.println();
// format of pilight USB Nano
String data = rf.pulseTrainToString(codes, length);
Serial.print("string format: ");
Serial.print(data);
Serial.println();
}
void setup() {
Serial.begin(115200);
#ifdef ESP32
RECEIVER_PIN = 4; TRANSMITTER_PIN = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
#elif ESP8266
RECEIVER_PIN = 4; TRANSMITTER_PIN = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
#else
RECEIVER_PIN = 0; TRANSMITTER_PIN = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. 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.SetRx(); // set Receive on
// set callback funktion for raw messages
rf.setPulseTrainCallBack(rfRawCallback);
// inittilize receiver
rf.initReceiver(RECEIVER_PIN);
}
void loop() {
// process input queue and may fire calllback
rf.loop();
delay(10);
}

View file

@ -0,0 +1,75 @@
/*
Basic ESPilight receive example
https://github.com/puuu/espilight
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <ESPiLight.h>
int RECEIVER_PIN; // any intterupt able pin
int TRANSMITTER_PIN;
ESPiLight rf(TRANSMITTER_PIN); // use -1 to disable transmitter
// callback function. It is called on successfully received and parsed rc signal
void rfCallback(const String &protocol, const String &message, int status,
size_t repeats, const String &deviceID) {
Serial.print("RF signal arrived [");
Serial.print(protocol); // protocoll used to parse
Serial.print("][");
Serial.print(deviceID); // value of id key in json message
Serial.print("] (");
Serial.print(status); // status of message, depending on repeat, either:
// FIRST - first message of this protocoll within the
// last 0.5 s
// INVALID - message repeat is not equal to the
// previous message
// VALID - message is equal to the previous message
// KNOWN - repeat of a already valid message
Serial.print(") ");
Serial.print(message); // message in json format
Serial.println();
// check if message is valid and process it
if (status == VALID) {
Serial.print("Valid message: [");
Serial.print(protocol);
Serial.print("] ");
Serial.print(message);
Serial.println();
}
}
void setup() {
Serial.begin(115200);
#ifdef ESP32
RECEIVER_PIN = 4; TRANSMITTER_PIN = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
#elif ESP8266
RECEIVER_PIN = 4; TRANSMITTER_PIN = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
#else
RECEIVER_PIN = 0; TRANSMITTER_PIN = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. 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.SetRx(); // set Receive on
// set callback funktion
rf.setCallback(rfCallback);
// inittilize receiver
rf.initReceiver(RECEIVER_PIN);
}
void loop() {
// process input queue and may fire calllback
rf.loop();
delay(10);
}

View file

@ -0,0 +1,52 @@
/*
Basic ESPiLight transmit RAW signal example
https://github.com/puuu/espilight
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <ESPiLight.h>
int TRANSMITTER_PIN;
void setup() {
Serial.begin(115200);
#ifdef ESP32
TRANSMITTER_PIN = 2; // for esp32! Transmit on GPIO pin 2.
#elif ESP8266
TRANSMITTER_PIN = 5; // for esp8266! Transmit on pin 5 = D1.
#else
TRANSMITTER_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
ESPiLight rf(TRANSMITTER_PIN);
int length = 0;
uint16_t codes[MAXPULSESTREAMLENGTH];
// get pulse train from string (format see: pilight USB Nano)
length = rf.stringToPulseTrain(
"c:102020202020202020220202020020202200202200202020202020220020202203;p:"
"279,2511,1395,9486@",
codes, MAXPULSESTREAMLENGTH);
// transmit the pulse train
rf.sendPulseTrain(codes, length);
}
// Toggle state of elro 800 switch evrey 2 s
void loop() {
// stop
}

View file

@ -0,0 +1,41 @@
/*
Basic ESPiLight transmit example
https://github.com/puuu/espilight
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <ESPiLight.h>
int TRANSMITTER_PIN;
void setup() {
Serial.begin(115200);
#ifdef ESP32
TRANSMITTER_PIN = 2; // for esp32! Transmit on GPIO pin 2.
#elif ESP8266
TRANSMITTER_PIN = 5; // for esp8266! Transmit on pin 5 = D1.
#else
TRANSMITTER_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
}
// Toggle state of elro 800 switch evrey 2 s
void loop() {
ESPiLight rf(TRANSMITTER_PIN);
rf.send("elro_800_switch", "{\"systemcode\":17,\"unitcode\":1,\"on\":1}");
delay(2000);
rf.send("elro_800_switch", "{\"systemcode\":17,\"unitcode\":1,\"off\":1}");
delay(2000);
}

View file

@ -0,0 +1,101 @@
/*
Basic ESPiLight pilight_debug example
This example mimic the output of the piligh_debug tool.
https://github.com/puuu/espilight
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <ESPiLight.h>
#define PULSE_DIV 34
int RECEIVER_PIN; // any intterupt able pin
int TRANSMITTER_PIN;
ESPiLight rf(TRANSMITTER_PIN); // use -1 to disable transmitter
unsigned int normalize(unsigned int i, unsigned int pulselen) {
double x;
x = (double)i / pulselen;
return (unsigned int)(round(x));
}
// callback function. It is called on successfully received and parsed rc signal
void rfRawCallback(const uint16_t* pulses, size_t length) {
uint16_t pulse;
uint16_t pulselen = pulses[length - 1] / PULSE_DIV;
if (pulselen > 25) {
for (unsigned int i = 3; i < length; i++) {
if ((pulses[i] / pulselen) >= 2) {
pulse = pulses[i];
break;
}
}
if (normalize(pulse, pulselen) > 0 && length > 25) {
/* Print everything */
Serial.println("--[RESULTS]--");
Serial.println();
Serial.print("time:\t\t");
Serial.print(millis());
Serial.println(" ms");
Serial.println("hardware:\tESPiLight");
Serial.print("pulse:\t\t");
Serial.println(normalize(pulse, pulselen));
Serial.print("rawlen:\t\t");
Serial.println(length);
Serial.printf("pulselen:\t");
Serial.println(pulselen);
Serial.println();
Serial.println("Raw code:");
for (unsigned int i = 0; i < length; i++) {
Serial.print(pulses[i]);
Serial.print(" ");
}
Serial.println();
}
}
}
void setup() {
Serial.begin(115200);
#ifdef ESP32
RECEIVER_PIN = 4; TRANSMITTER_PIN = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
#elif ESP8266
RECEIVER_PIN = 4; TRANSMITTER_PIN = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
#else
RECEIVER_PIN = 0; TRANSMITTER_PIN = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. 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.SetRx(); // set Receive on
// set callback funktion for raw messages
rf.setPulseTrainCallBack(rfRawCallback);
// inittilize receiver
rf.initReceiver(RECEIVER_PIN);
Serial.println(
"Press and hold one of the buttons on your remote or wait until");
Serial.println("another device such as a weather station has sent new codes");
Serial.println(
"The debugger will automatically reset itself after one second of");
Serial.println(
"failed leads. It will keep running until you explicitly stop it.");
}
void loop() {
// process input queue and may fire calllback
rf.loop();
delay(10);
}

View file

@ -0,0 +1,61 @@
/*
Basic ESPiLight pilight_raw example
This example mimic the output of the piligh_raw tool.
https://github.com/puuu/espilight
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <ESPiLight.h>
int RECEIVER_PIN; // any intterupt able pin
int TRANSMITTER_PIN;
ESPiLight rf(TRANSMITTER_PIN); // use -1 to disable transmitter
// callback function. It is called on successfully received and parsed rc signal
void rfRawCallback(const uint16_t* pulses, size_t length) {
Serial.print("ESPiLight:");
for (unsigned int i = 0; i < length; i++) {
Serial.print(" ");
Serial.print(pulses[i]);
if (pulses[i] > 5100) {
Serial.printf(" -# ");
Serial.println(i);
}
}
}
void setup() {
Serial.begin(115200);
#ifdef ESP32
RECEIVER_PIN = 4; TRANSMITTER_PIN = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
#elif ESP8266
RECEIVER_PIN = 4; TRANSMITTER_PIN = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
#else
RECEIVER_PIN = 0; TRANSMITTER_PIN = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. 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.SetRx(); // set Receive on
// set callback funktion for raw messages
rf.setPulseTrainCallBack(rfRawCallback);
// inittilize receiver
rf.initReceiver(RECEIVER_PIN);
}
void loop() {
// process input queue and may fire calllback
rf.loop();
delay(10);
}

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,109 @@
/*
* 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
//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,69 @@
/*
* 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
//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);
}

View file

@ -0,0 +1,125 @@
/*
Example for analyzing and proposing unknown new protocols
Requires modified rc-switch branch "protocollessreceiver"
with ReceivedInverted() function exposed.
https://github.com/Martin-Laclaustra/rc-switch/tree/protocollessreceiver
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
CC1101 Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Receive pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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
//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.
mySwitch.enableReceive(pin); // Receiver on
ELECHOUSE_cc1101.SetRx(); // set Receive on
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
int databuffer[64]; // get a copy of the received timings before they are overwritten
int numberoftimings = 2 * mySwitch.getReceivedBitlength() + 2;
if(numberoftimings > 64) numberoftimings = 64;
for (int i = 0; i < numberoftimings; i++) {
databuffer[i] = mySwitch.getReceivedRawdata()[i];
}
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
unsigned int databitsoffset = abs( (int)mySwitch.getReceivedLevelInFirstTiming() - (int)mySwitch.getReceivedInverted());
//Serial.println( mySwitch.getReceivedLevelInFirstTiming() );
//Serial.println( mySwitch.getReceivedInverted() );
//Serial.println( databitsoffset );
unsigned long dataduration = 0;
for (unsigned int i = 1 + databitsoffset; i < numberoftimings - 1 + databitsoffset; i++) {
dataduration += databuffer[i];
}
Serial.print("data bits of pulse train duration: ");
Serial.println( dataduration );
unsigned int averagebitduration = (int)(0.5 + ((double)dataduration)/mySwitch.getReceivedBitlength());
unsigned int protocolratio = (unsigned int)(0.5 + ((double)(averagebitduration - mySwitch.getReceivedDelay())) / (double)mySwitch.getReceivedDelay());
Serial.print("proposed protocol: { ");
Serial.print(mySwitch.getReceivedDelay());
Serial.print(", { ");
Serial.print( (databitsoffset==0) ?
(int) (0.5 + (double)databuffer[2*mySwitch.getReceivedBitlength()+1]/(double)mySwitch.getReceivedDelay())
:
(int) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay())
);
Serial.print(", ");
Serial.print( (databitsoffset==0) ?
(int) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay())
:
(int) (0.5 + (double)databuffer[1]/(double)mySwitch.getReceivedDelay())
);
Serial.print(" }, { ");
Serial.print("1");
Serial.print(", ");
Serial.print(protocolratio);
Serial.print(" }, { ");
Serial.print(protocolratio);
Serial.print(", ");
Serial.print("1");
Serial.print(" }, ");
Serial.print((mySwitch.getReceivedInverted()) ? "true" : "false" );
Serial.println(" }");
// raw signal
Serial.println("====");
Serial.print("first level ");
Serial.println((mySwitch.getReceivedLevelInFirstTiming() == 0) ? "down" : "up" );
for (int i = 0; i < 2*mySwitch.getReceivedBitlength()+2 - 1 + databitsoffset; i++) {
Serial.print(databuffer[i]);
Serial.print(" ");
if((i - databitsoffset) % 16 == 0) Serial.println("");
}
if ((2*mySwitch.getReceivedBitlength()+2 - 1 + databitsoffset - 1) % 16 != 0) Serial.println("");
if (databitsoffset != 1) Serial.println(databuffer[2*mySwitch.getReceivedBitlength()+1]);
// plot signal in spreadsheet
Serial.println("====");
}
mySwitch.resetAvailable();
}
}

View file

@ -0,0 +1,47 @@
/*
Example for receiving
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
If you want to visualize a telegram copy the raw data and
paste it into http://test.sui.li/oszi/
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Receive pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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
//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.
mySwitch.enableReceive(pin); // Receiver on interrupt 0 => that is pin #2
ELECHOUSE_cc1101.SetRx(); // set Receive on
}
void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}

View file

@ -0,0 +1,70 @@
static const char* bin2tristate(const char* bin);
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength);
void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
const char* b = dec2binWzerofill(decimal, length);
Serial.print("Decimal: ");
Serial.print(decimal);
Serial.print(" (");
Serial.print( length );
Serial.print("Bit) Binary: ");
Serial.print( b );
Serial.print(" Tri-State: ");
Serial.print( bin2tristate( b) );
Serial.print(" PulseLength: ");
Serial.print(delay);
Serial.print(" microseconds");
Serial.print(" Protocol: ");
Serial.println(protocol);
Serial.print("Raw data: ");
for (unsigned int i=0; i<= length*2; i++) {
Serial.print(raw[i]);
Serial.print(",");
}
Serial.println();
Serial.println();
}
static const char* bin2tristate(const char* bin) {
static char returnValue[50];
int pos = 0;
int pos2 = 0;
while (bin[pos]!='\0' && bin[pos+1]!='\0') {
if (bin[pos]=='0' && bin[pos+1]=='0') {
returnValue[pos2] = '0';
} else if (bin[pos]=='1' && bin[pos+1]=='1') {
returnValue[pos2] = '1';
} else if (bin[pos]=='0' && bin[pos+1]=='1') {
returnValue[pos2] = 'F';
} else {
return "not applicable";
}
pos = pos+2;
pos2++;
}
returnValue[pos2] = '\0';
return returnValue;
}
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) {
static char bin[64];
unsigned int i=0;
while (Dec > 0) {
bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
Dec = Dec >> 1;
}
for (unsigned int j = 0; j< bitLength; j++) {
if (j >= bitLength - i) {
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
} else {
bin[j] = '0';
}
}
bin[bitLength] = '\0';
return bin;
}

View file

@ -0,0 +1,54 @@
/*
Simple example for receiving
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Receive pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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
//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.
mySwitch.enableReceive(pin); // Receiver on
ELECHOUSE_cc1101.SetRx(); // set Receive on
}
void loop() {
if (mySwitch.available()){
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
mySwitch.resetAvailable();
}
}

View file

@ -0,0 +1,56 @@
/*
Simple example for receiving with Rssi output.
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Receive pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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
//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.
mySwitch.enableReceive(pin); // Receiver on
ELECHOUSE_cc1101.SetRx(); // set Receive on
}
void loop() {
if (mySwitch.available()){
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
Serial.print("RSSI: ");
Serial.println(ELECHOUSE_cc1101.getRssi());
mySwitch.resetAvailable();
}
}

View file

@ -0,0 +1,112 @@
/*
Simple example for Receiving and Transmit decimal code for cc1101
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pinRx; // int for Receive pin.
int pinTx; // int for Transmit pin.
RCSwitch mySwitch = RCSwitch();
int buttonPin; // for button pin.
int buttonState = 0; // button state
int ccSetRx = 0; // reset state for Receive
int long value = 5393; // int to save value
int bits = 24; // int to save bit number
int prot = 1; // int to save Protocol number
int puls = 320; // int to save pulse length
void setup() {
Serial.begin(9600);
#ifdef ESP32
pinRx = 4; pinTx = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
buttonPin = 34; // set button on GPIO pin 34.
#elif ESP8266
pinRx = 4; pinTx = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
buttonPin = 16; // set button on pin 16 = D0.
#else
pinRx = 0; pinTx = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. Transmit on pin 6.
buttonPin = 4; // set button on pin D4.
#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.
pinMode(buttonPin, INPUT); // set pin4 as input
}
void loop() {
buttonState = digitalRead(buttonPin); // read digital pin and save the state to int
if (buttonState == HIGH) { // the button is pressed. Set transmit on.
ccSetRx = 0; // set resetstate to 0 for next reinit to Recive
ELECHOUSE_cc1101.SetTx(); // set Transmit on
mySwitch.disableReceive(); // Receiver off
mySwitch.enableTransmit(pinTx); // Transmit on
mySwitch.setRepeatTransmit(3); // transmission repetitions.
mySwitch.setProtocol(prot); // send Received Protocol
mySwitch.setPulseLength(puls);// send Received Delay
mySwitch.send(value, bits); // send Received value/bits
Serial.print("Transmit ");
Serial.print( value );
Serial.print(" / ");
Serial.print( bits );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.print( prot );
Serial.print(" Delay: ");
Serial.println( puls );
}
if (buttonState == LOW && ccSetRx == 0){ //the button is not pressed. set cc1101 to Receive.
ELECHOUSE_cc1101.SetRx(); // set Receive on
mySwitch.disableTransmit(); // set Transmit off
mySwitch.enableReceive(pinRx); // Receiver on
ccSetRx = 1;
}
if (buttonState == LOW && ccSetRx == 1) { //the button is not pressed and set receive is finish. Receive values.
if (mySwitch.available()){
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.print( mySwitch.getReceivedProtocol() );
Serial.print(" Delay: ");
Serial.println( mySwitch.getReceivedDelay() );
value = mySwitch.getReceivedValue(); // save received Value
bits = mySwitch.getReceivedBitlength(); // save received Bitlength
prot = mySwitch.getReceivedProtocol(); // save received Protocol
puls = mySwitch.getReceivedDelay(); // save received pulse length
mySwitch.resetAvailable();
}
}
}

View file

@ -0,0 +1,103 @@
/*
Simple example for repeating decimal code for cc1101
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pinRx; // int for Receive pin.
int pinTx; // int for Transmit pin.
RCSwitch mySwitch = RCSwitch();
int number = 15; // set number of transmission repetitions.
int TIME = 3000; // set delay befor repeat. For direct repetition after receive set 0.
int long value; // int to save value
int bits; // int to save bit number
int prot; // int to save Protocol number
int puls; // int to save pulse length
void setup() {
Serial.begin(9600);
#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
//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
mySwitch.enableReceive(pinRx); // Receiver on
}
void loop() {
if (value > 0) {
ELECHOUSE_cc1101.SetTx(); // set Transmit on
mySwitch.disableReceive(); // Receiver off
mySwitch.enableTransmit(pinTx); // Transmit on
mySwitch.setRepeatTransmit(number); // transmission repetitions.
mySwitch.setProtocol(prot); // send Received Protocol
mySwitch.setPulseLength(puls); // send Received Delay
mySwitch.send(value, bits); // send Received value/bits
Serial.print("Transmit ");
Serial.print( value );
Serial.print(" / ");
Serial.print( bits );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.print( prot );
Serial.print(" Delay: ");
Serial.println( puls );
ELECHOUSE_cc1101.SetRx(); // set Receive on
mySwitch.disableTransmit(); // set Transmit off
mySwitch.enableReceive(pinRx); // Receiver on
value = 0; // Reset value after transmit for receive.
}
else{
if (mySwitch.available()){
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.print( mySwitch.getReceivedProtocol() );
Serial.print(" Delay: ");
Serial.println( mySwitch.getReceivedDelay() );
value = mySwitch.getReceivedValue(); // save received Value
bits = mySwitch.getReceivedBitlength(); // save received Bitlength
prot = mySwitch.getReceivedProtocol(); // save received Protocol
puls = mySwitch.getReceivedDelay(); // save received pulse length
mySwitch.resetAvailable();
delay(TIME);
}
}
}

View file

@ -0,0 +1,78 @@
/*
Example for different sending methods
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Transmit pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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.
// Transmitter on
mySwitch.enableTransmit(pin);
// cc1101 set Transmit on
ELECHOUSE_cc1101.SetTx();
// Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
// Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15);
}
void loop() {
/* See Example: TypeA_WithDIPSwitches */
mySwitch.switchOn("11111", "00010");
delay(1000);
mySwitch.switchOff("11111", "00010");
delay(1000);
/* Same switch as above, but using decimal code */
mySwitch.send(5393, 24);
delay(1000);
mySwitch.send(5396, 24);
delay(1000);
/* Same switch as above, but using binary code */
mySwitch.send("000000000001010100010001");
delay(1000);
mySwitch.send("000000000001010100010100");
delay(1000);
/* Same switch as above, but tri-state code */
mySwitch.sendTriState("00000FFF0F0F");
delay(1000);
mySwitch.sendTriState("00000FFF0FF0");
delay(1000);
delay(20000);
}

View file

@ -0,0 +1,65 @@
/*
Example for outlets which are configured with a 10 pole DIP switch.
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Transmit pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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.
// Transmitter on
mySwitch.enableTransmit(pin);
// cc1101 set Transmit on
ELECHOUSE_cc1101.SetTx();
// Optional set pulse length.
// mySwitch.setPulseLength(320);
}
void loop() {
// Switch on:
// The first parameter represents the setting of the first 5 DIP switches.
// In this example it's ON-ON-OFF-OFF-ON.
//
// The second parameter represents the setting of the last 5 DIP switches.
// In this example the last 5 DIP switches are OFF-ON-OFF-ON-OFF.
mySwitch.switchOn("11001", "01010");
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff("11001", "01010");
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,64 @@
/*
Example for outlets which are configured with two rotary/sliding switches.
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Transmit pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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.
// Transmitter on
mySwitch.enableTransmit(pin);
// cc1101 set Transmit on
ELECHOUSE_cc1101.SetTx();
// Optional set pulse length.
// mySwitch.setPulseLength(320);
}
void loop() {
// Switch on:
// The first parameter represents the setting of the first rotary switch.
// In this example it's switched to "1" or "A" or "I".
//
// The second parameter represents the setting of the second rotary switch.
// In this example it's switched to "4" or "D" or "IV".
mySwitch.switchOn(1, 4);
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff(1, 4);
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,64 @@
/*
Example for Intertechno outlets
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Transmit pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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.
// Transmitter on
mySwitch.enableTransmit(pin);
// cc1101 set Transmit on
ELECHOUSE_cc1101.SetTx();
// Optional set pulse length.
// mySwitch.setPulseLength(320);
}
void loop() {
// Switch on:
// The first parameter represents the familycode (a, b, c, ... f)
// The second parameter represents the group number
// The third parameter represents the device number
//
// In this example it's family 'b', group #3, device #2
mySwitch.switchOn('b', 3, 2);
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff('b', 3, 2);
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,65 @@
/*
Example for REV outlets (e.g. 8342L)
https://github.com/sui77/rc-switch/
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
Need help? http://forum.ardumote.com
----------------------------------------------------------
Mod by Little Satan. Have Fun!
----------------------------------------------------------
*/
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>
int pin; // int for Transmit pin.
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
#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.
// Transmitter on
mySwitch.enableTransmit(pin);
// cc1101 set Transmit on
ELECHOUSE_cc1101.SetTx();
// set pulse length.
mySwitch.setPulseLength(360);
}
void loop() {
// Switch on:
// The first parameter represents the channel (a, b, c, d)
// The second parameter represents the device number
//
// In this example it's family 'd', device #2
mySwitch.switchOn('d', 2);
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff('d', 2);
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,81 @@
/*
* 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
//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();
}

View file

@ -0,0 +1,74 @@
/*
* 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
//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);
}
}

View file

@ -0,0 +1,50 @@
/*
* 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
//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);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

View file

@ -0,0 +1,45 @@
ELECHOUSE_CC1101_SRC_DRV KEYWORD1
ELECHOUSE_cc1101 KEYWORD1
Init KEYWORD2
SpiReadStatus KEYWORD2
SpiStrobe KEYWORD2
SpiWriteReg KEYWORD2
SpiWriteBurstReg KEYWORD2
SpiReadReg KEYWORD2
SpiReadBurstReg KEYWORD2
setSpiPin KEYWORD2
setGDO KEYWORD2
setCCMode KEYWORD2
setModulation KEYWORD2
setPA KEYWORD2
setMHZ KEYWORD2
setRxBW KEYWORD2
setChannel KEYWORD2
SetTx KEYWORD2
SetRx KEYWORD2
getRssi KEYWORD2
getLqi KEYWORD2
setSres KEYWORD2
SendData KEYWORD2
CheckReceiveFlag KEYWORD2
CheckRxFifo KEYWORD2
CheckCRC KEYWORD2
ReceiveData KEYWORD2
setClb KEYWORD2
setChsp KEYWORD2
setDRate KEYWORD2
setDeviation KEYWORD2
setSyncMode KEYWORD2
setAdrChk KEYWORD2
setAddr KEYWORD2
setWhiteData KEYWORD2
setPktFormat KEYWORD2
setLengthConfig KEYWORD2
setPacketLength KEYWORD2
setCrc KEYWORD2
setCRC_AF KEYWORD2
setDcFilterOff KEYWORD2
setManchester KEYWORD2
setFEC KEYWORD2
setPQT KEYWORD2
setAppendStatus KEYWORD2

View file

@ -0,0 +1,19 @@
{
"name": "SmartRC-CC1101-Driver-Lib",
"description": "This driver library can be used for many libraries that use a simple RF ASK module, with the advantages of the cc1101 module.It offers many direct setting options as in SmartRF Studio and calculates settings such as MHz directly.",
"keywords": "rf, radio, wireless, cc1101",
"authors":
{
"name": "Little Satan"
},
"repository":
{
"type": "git",
"url": "https://github.com/LSatan/SmartRC-CC1101-Driver-Lib"
},
"version": "2.5.2",
"frameworks": [
"arduino"
],
"platforms": "*"
}

View file

@ -0,0 +1,10 @@
name=SmartRC-CC1101-Driver-Lib
version=2.5.2
author=LSatan
maintainer=LSatan <littlesatan.666.ls@gmail.com>
sentence=Driver for cc1101.
paragraph=This driver library can be used for many libraries that use a simple RF ASK module,with the advantages of the cc1101 module.It offers many direct setting options as in SmartRF Studio and calculates settings such as MHz directly.
category=Device Control
url=https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
architectures=avr,esp8266,esp32
includes=ELECHOUSE_CC1101_SRC_DRV.h

View file

@ -0,0 +1,868 @@
/*
RCSwitch - Arduino libary for remote control outlet switches
Copyright (c) 2011 Suat Özgür. All right reserved.
Contributors:
- Andre Koehler / info(at)tomate-online(dot)de
- Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
- Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46
- Dominik Fischer / dom_fischer(at)web(dot)de
- Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
- Andreas Steinel / A.<lastname>(at)gmail(dot)com
- Max Horn / max(at)quendi(dot)de
- Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com
- Johann Richard / <first name>.<last name>(at)gmail(dot)com
- Vlad Gheorghe / <first name>.<last name>(at)gmail(dot)com https://github.com/vgheo
- Martin Laclaustra / <first name>.<last name>(at)gmail(dot)com
Project home: https://github.com/sui77/rc-switch/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "RCSwitch.h"
#ifdef RaspberryPi
// PROGMEM and _P functions are for AVR based microprocessors,
// so we must normalize these for the ARM processor:
#define PROGMEM
#define memcpy_P(dest, src, num) memcpy((dest), (src), (num))
#endif
#ifdef ESP8266
// interrupt handler and related code must be in RAM on ESP8266,
// according to issue #46.
#define RECEIVE_ATTR ICACHE_RAM_ATTR
#else
#define RECEIVE_ATTR
#endif
/* Format for protocol definitions:
* {pulselength, Sync bit, "0" bit, "1" bit}
*
* pulselength: pulse length in microseconds, e.g. 350
* Sync bit: {1, 31} means 1 high pulse and 31 low pulses
* (perceived as a 31*pulselength long pulse, total length of sync bit is
* 32*pulselength microseconds), i.e:
* _
* | |_______________________________ (don't count the vertical bars)
* "0" bit: waveform for a data bit of value "0", {1, 3} means 1 high pulse
* and 3 low pulses, total length (1+3)*pulselength, i.e:
* _
* | |___
* "1" bit: waveform for a data bit of value "1", e.g. {3,1}:
* ___
* | |_
*
* These are combined to form Tri-State bits when sending or receiving codes.
*/
#ifdef ESP8266
static const RCSwitch::Protocol proto[] = {
#else
static const RCSwitch::Protocol PROGMEM proto[] = {
#endif
{ 350, { 1, 31 }, { 1, 3 }, { 3, 1 }, false }, // protocol 1
{ 650, { 1, 10 }, { 1, 2 }, { 2, 1 }, false }, // protocol 2
{ 100, { 30, 71 }, { 4, 11 }, { 9, 6 }, false }, // protocol 3
{ 380, { 1, 6 }, { 1, 3 }, { 3, 1 }, false }, // protocol 4
{ 500, { 6, 14 }, { 1, 2 }, { 2, 1 }, false }, // protocol 5
{ 450, { 23, 1 }, { 1, 2 }, { 2, 1 }, true } // protocol 6 (HT6P20B)
};
enum {
numProto = sizeof(proto) / sizeof(proto[0])
};
#if not defined( RCSwitchDisableReceiving )
volatile unsigned long RCSwitch::nReceivedValue = 0;
volatile unsigned int RCSwitch::nReceivedBitlength = 0;
volatile unsigned int RCSwitch::nReceivedDelay = 0;
volatile unsigned int RCSwitch::nReceivedProtocol = 0;
bool RCSwitch::nReceivedInverted = false;
unsigned int RCSwitch::nReceivedLevelInFirstTiming = 0;
int RCSwitch::nReceiveTolerance = 60;
const unsigned int RCSwitch::nSeparationLimit = 2200;
// separationLimit: minimum microseconds the first long part of the sync bit lasts.
// set to 110% the longest bit duration known so far.
// protocol 2: (650 * (1 + 2))=1950 ... x 110% ... ~ 2200
// with this limit, in protocols 5 and 6, the high part of the sync bit will be recognized
// as timing 0 which causes problems in timing 1 and in decoding interpretation
unsigned int RCSwitch::firstperiodlevel;
unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES];
int RCSwitch::nStaticReceiverPin; // needed because nReceiverInterrupt (receiver pin) can not be read from handleInterrupt because it is static
#endif
RCSwitch::RCSwitch() {
this->nTransmitterPin = -1;
this->setRepeatTransmit(10);
this->setProtocol(1);
#if not defined( RCSwitchDisableReceiving )
this->nReceiverInterrupt = -1;
this->setReceiveTolerance(60);
RCSwitch::nReceivedValue = 0;
#endif
}
/**
* Sets the protocol to send.
*/
void RCSwitch::setProtocol(Protocol protocol) {
this->protocol = protocol;
}
/**
* Sets the protocol to send, from a list of predefined protocols
*/
void RCSwitch::setProtocol(int nProtocol) {
if (nProtocol < 1 || nProtocol > numProto) {
nProtocol = 1; // TODO: trigger an error, e.g. "bad protocol" ???
}
#ifdef ESP8266
this->protocol = proto[nProtocol-1];
#else
memcpy_P(&this->protocol, &proto[nProtocol-1], sizeof(Protocol));
#endif
}
/**
* Sets the protocol to send with pulse length in microseconds.
*/
void RCSwitch::setProtocol(int nProtocol, int nPulseLength) {
setProtocol(nProtocol);
this->setPulseLength(nPulseLength);
}
/**
* Sets pulse length in microseconds
*/
void RCSwitch::setPulseLength(int nPulseLength) {
this->protocol.pulseLength = nPulseLength;
}
/**
* Sets Repeat Transmits
*/
void RCSwitch::setRepeatTransmit(int nRepeatTransmit) {
this->nRepeatTransmit = nRepeatTransmit;
}
/**
* Set Receiving Tolerance
*/
#if not defined( RCSwitchDisableReceiving )
void RCSwitch::setReceiveTolerance(int nPercent) {
RCSwitch::nReceiveTolerance = nPercent;
}
#endif
/**
* Enable transmissions
*
* @param nTransmitterPin Arduino Pin to which the sender is connected to
*/
void RCSwitch::enableTransmit(int nTransmitterPin) {
this->nTransmitterPin = nTransmitterPin;
pinMode(this->nTransmitterPin, OUTPUT);
}
/**
* Disable transmissions
*/
void RCSwitch::disableTransmit() {
this->nTransmitterPin = -1;
}
/**
* Switch a remote switch on (Type D REV)
*
* @param sGroup Code of the switch group (A,B,C,D)
* @param nDevice Number of the switch itself (1..3)
*/
void RCSwitch::switchOn(char sGroup, int nDevice) {
this->sendTriState( this->getCodeWordD(sGroup, nDevice, true) );
}
/**
* Switch a remote switch off (Type D REV)
*
* @param sGroup Code of the switch group (A,B,C,D)
* @param nDevice Number of the switch itself (1..3)
*/
void RCSwitch::switchOff(char sGroup, int nDevice) {
this->sendTriState( this->getCodeWordD(sGroup, nDevice, false) );
}
/**
* Switch a remote switch on (Type C Intertechno)
*
* @param sFamily Familycode (a..f)
* @param nGroup Number of group (1..4)
* @param nDevice Number of device (1..4)
*/
void RCSwitch::switchOn(char sFamily, int nGroup, int nDevice) {
this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, true) );
}
/**
* Switch a remote switch off (Type C Intertechno)
*
* @param sFamily Familycode (a..f)
* @param nGroup Number of group (1..4)
* @param nDevice Number of device (1..4)
*/
void RCSwitch::switchOff(char sFamily, int nGroup, int nDevice) {
this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, false) );
}
/**
* Switch a remote switch on (Type B with two rotary/sliding switches)
*
* @param nAddressCode Number of the switch group (1..4)
* @param nChannelCode Number of the switch itself (1..4)
*/
void RCSwitch::switchOn(int nAddressCode, int nChannelCode) {
this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, true) );
}
/**
* Switch a remote switch off (Type B with two rotary/sliding switches)
*
* @param nAddressCode Number of the switch group (1..4)
* @param nChannelCode Number of the switch itself (1..4)
*/
void RCSwitch::switchOff(int nAddressCode, int nChannelCode) {
this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, false) );
}
/**
* Deprecated, use switchOn(const char* sGroup, const char* sDevice) instead!
* Switch a remote switch on (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param nChannelCode Number of the switch itself (1..5)
*/
void RCSwitch::switchOn(const char* sGroup, int nChannel) {
const char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };
this->switchOn(sGroup, code[nChannel]);
}
/**
* Deprecated, use switchOff(const char* sGroup, const char* sDevice) instead!
* Switch a remote switch off (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param nChannelCode Number of the switch itself (1..5)
*/
void RCSwitch::switchOff(const char* sGroup, int nChannel) {
const char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };
this->switchOff(sGroup, code[nChannel]);
}
/**
* Switch a remote switch on (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
*/
void RCSwitch::switchOn(const char* sGroup, const char* sDevice) {
this->sendTriState( this->getCodeWordA(sGroup, sDevice, true) );
}
/**
* Switch a remote switch off (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
*/
void RCSwitch::switchOff(const char* sGroup, const char* sDevice) {
this->sendTriState( this->getCodeWordA(sGroup, sDevice, false) );
}
/**
* Returns a char[13], representing the code word to be send.
*
*/
char* RCSwitch::getCodeWordA(const char* sGroup, const char* sDevice, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
for (int i = 0; i < 5; i++) {
sReturn[nReturnPos++] = (sGroup[i] == '0') ? 'F' : '0';
}
for (int i = 0; i < 5; i++) {
sReturn[nReturnPos++] = (sDevice[i] == '0') ? 'F' : '0';
}
sReturn[nReturnPos++] = bStatus ? '0' : 'F';
sReturn[nReturnPos++] = bStatus ? 'F' : '0';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* Encoding for type B switches with two rotary/sliding switches.
*
* The code word is a tristate word and with following bit pattern:
*
* +-----------------------------+-----------------------------+----------+------------+
* | 4 bits address | 4 bits address | 3 bits | 1 bit |
* | switch group | switch number | not used | on / off |
* | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | FFF | on=F off=0 |
* +-----------------------------+-----------------------------+----------+------------+
*
* @param nAddressCode Number of the switch group (1..4)
* @param nChannelCode Number of the switch itself (1..4)
* @param bStatus Whether to switch on (true) or off (false)
*
* @return char[13], representing a tristate code word of length 12
*/
char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
if (nAddressCode < 1 || nAddressCode > 4 || nChannelCode < 1 || nChannelCode > 4) {
return 0;
}
for (int i = 1; i <= 4; i++) {
sReturn[nReturnPos++] = (nAddressCode == i) ? '0' : 'F';
}
for (int i = 1; i <= 4; i++) {
sReturn[nReturnPos++] = (nChannelCode == i) ? '0' : 'F';
}
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = bStatus ? 'F' : '0';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* Like getCodeWord (Type C = Intertechno)
*/
char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
int nFamily = (int)sFamily - 'a';
if ( nFamily < 0 || nFamily > 15 || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) {
return 0;
}
// encode the family into four bits
sReturn[nReturnPos++] = (nFamily & 1) ? 'F' : '0';
sReturn[nReturnPos++] = (nFamily & 2) ? 'F' : '0';
sReturn[nReturnPos++] = (nFamily & 4) ? 'F' : '0';
sReturn[nReturnPos++] = (nFamily & 8) ? 'F' : '0';
// encode the device and group
sReturn[nReturnPos++] = ((nDevice-1) & 1) ? 'F' : '0';
sReturn[nReturnPos++] = ((nDevice-1) & 2) ? 'F' : '0';
sReturn[nReturnPos++] = ((nGroup-1) & 1) ? 'F' : '0';
sReturn[nReturnPos++] = ((nGroup-1) & 2) ? 'F' : '0';
// encode the status code
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = bStatus ? 'F' : '0';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* Encoding for the REV Switch Type
*
* The code word is a tristate word and with following bit pattern:
*
* +-----------------------------+-------------------+----------+--------------+
* | 4 bits address | 3 bits address | 3 bits | 2 bits |
* | switch group | device number | not used | on / off |
* | A=1FFF B=F1FF C=FF1F D=FFF1 | 1=0FF 2=F0F 3=FF0 | 000 | on=10 off=01 |
* +-----------------------------+-------------------+----------+--------------+
*
* Source: http://www.the-intruder.net/funksteckdosen-von-rev-uber-arduino-ansteuern/
*
* @param sGroup Name of the switch group (A..D, resp. a..d)
* @param nDevice Number of the switch itself (1..3)
* @param bStatus Whether to switch on (true) or off (false)
*
* @return char[13], representing a tristate code word of length 12
*/
char* RCSwitch::getCodeWordD(char sGroup, int nDevice, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
// sGroup must be one of the letters in "abcdABCD"
int nGroup = (sGroup >= 'a') ? (int)sGroup - 'a' : (int)sGroup - 'A';
if ( nGroup < 0 || nGroup > 3 || nDevice < 1 || nDevice > 3) {
return 0;
}
for (int i = 0; i < 4; i++) {
sReturn[nReturnPos++] = (nGroup == i) ? '1' : 'F';
}
for (int i = 1; i <= 3; i++) {
sReturn[nReturnPos++] = (nDevice == i) ? '1' : 'F';
}
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = bStatus ? '1' : '0';
sReturn[nReturnPos++] = bStatus ? '0' : '1';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* @param sCodeWord a tristate code word consisting of the letter 0, 1, F
*/
void RCSwitch::sendTriState(const char* sCodeWord) {
// turn the tristate code word into the corresponding bit pattern, then send it
unsigned long code = 0;
unsigned int length = 0;
for (const char* p = sCodeWord; *p; p++) {
code <<= 2L;
switch (*p) {
case '0':
// bit pattern 00
break;
case 'F':
// bit pattern 01
code |= 1L;
break;
case '1':
// bit pattern 11
code |= 3L;
break;
}
length += 2;
}
this->send(code, length);
}
/**
* @param sCodeWord a binary code word consisting of the letter 0, 1
*/
void RCSwitch::send(const char* sCodeWord) {
// turn the tristate code word into the corresponding bit pattern, then send it
unsigned long code = 0;
unsigned int length = 0;
for (const char* p = sCodeWord; *p; p++) {
code <<= 1L;
if (*p != '0')
code |= 1L;
length++;
}
this->send(code, length);
}
/**
* Transmit the first 'length' bits of the integer 'code'. The
* bits are sent from MSB to LSB, i.e., first the bit at position length-1,
* then the bit at position length-2, and so on, till finally the bit at position 0.
*/
void RCSwitch::send(unsigned long code, unsigned int length) {
if (this->nTransmitterPin == -1)
return;
#if not defined( RCSwitchDisableReceiving )
// make sure the receiver is disabled while we transmit
int nReceiverInterrupt_backup = nReceiverInterrupt;
if (nReceiverInterrupt_backup != -1) {
this->disableReceive();
}
#endif
for (int nRepeat = 0; nRepeat < nRepeatTransmit; nRepeat++) {
for (int i = length-1; i >= 0; i--) {
if (code & (1L << i))
this->transmit(protocol.one);
else
this->transmit(protocol.zero);
}
this->transmit(protocol.syncFactor);
}
#if not defined( RCSwitchDisableReceiving )
// enable receiver again if we just disabled it
if (nReceiverInterrupt_backup != -1) {
this->enableReceive(nReceiverInterrupt_backup);
}
#endif
}
/**
* Transmit a single high-low pulse.
*/
void RCSwitch::transmit(HighLow pulses) {
uint8_t firstLogicLevel = (this->protocol.invertedSignal) ? LOW : HIGH;
uint8_t secondLogicLevel = (this->protocol.invertedSignal) ? HIGH : LOW;
digitalWrite(this->nTransmitterPin, firstLogicLevel);
delayMicroseconds( this->protocol.pulseLength * pulses.high);
digitalWrite(this->nTransmitterPin, secondLogicLevel);
delayMicroseconds( this->protocol.pulseLength * pulses.low);
}
#if not defined( RCSwitchDisableReceiving )
/**
* Enable receiving data
*/
void RCSwitch::enableReceive(int interrupt) {
#ifdef RaspberryPi
int receiverpin = interrupt;
#else
// learn which digital pin corresponds to that interrupt
int receiverpin = -1;
for(int i = 0; i < 40; i++) {
if (digitalPinToInterrupt(i) == interrupt) {
receiverpin = i;
break;
}
}
#endif
this->nReceiverInterrupt = interrupt;
RCSwitch::nStaticReceiverPin = receiverpin;
this->enableReceive();
}
void RCSwitch::enableReceive() {
if (this->nReceiverInterrupt != -1) {
RCSwitch::nReceivedValue = 0;
RCSwitch::nReceivedBitlength = 0;
#if defined(RaspberryPi) // Raspberry Pi
wiringPiISR(this->nReceiverInterrupt, INT_EDGE_BOTH, &handleInterrupt);
#else // Arduino
attachInterrupt(this->nReceiverInterrupt, handleInterrupt, CHANGE);
#endif
}
}
/**
* Disable receiving data
*/
void RCSwitch::disableReceive() {
#if not defined(RaspberryPi) // Arduino
detachInterrupt(this->nReceiverInterrupt);
#endif // For Raspberry Pi (wiringPi) you can't unregister the ISR
this->nReceiverInterrupt = -1;
}
bool RCSwitch::available() {
return RCSwitch::nReceivedValue != 0;
}
void RCSwitch::resetAvailable() {
RCSwitch::nReceivedValue = 0;
}
unsigned long RCSwitch::getReceivedValue() {
return RCSwitch::nReceivedValue;
}
unsigned int RCSwitch::getReceivedBitlength() {
return RCSwitch::nReceivedBitlength;
}
unsigned int RCSwitch::getReceivedDelay() {
return RCSwitch::nReceivedDelay;
}
unsigned int RCSwitch::getReceivedProtocol() {
return RCSwitch::nReceivedProtocol;
}
unsigned int* RCSwitch::getReceivedRawdata() {
return RCSwitch::timings;
}
bool RCSwitch::getReceivedInverted() {
return RCSwitch::nReceivedInverted;
}
unsigned int RCSwitch::getReceivedLevelInFirstTiming() {
return RCSwitch::nReceivedLevelInFirstTiming;
}
/* helper function for the receiveProtocol method */
static inline unsigned int diff(int A, int B) {
return abs(A - B);
}
/**
*
*/
bool RECEIVE_ATTR RCSwitch::receiveProtocol(const int p, unsigned int changeCount) {
int finalp = 0; // no protocol recognized
unsigned int tmpfirstperiodlevel = RCSwitch::firstperiodlevel; // store it before it is overwritten
// ignore very short transmissions: no device sends them, so this must be noise
if (changeCount < 8) return false; // also ensure avoiding 0 division later
// changeCount is the number of stored durations
// timings positions span from 0 ... (changeCount - 1)
//
// non-inverted protocols with recorded...
// signals starting low: data bits timings from positions 1 ... (changeCount - 2)
// sync bit timings[changeCount - 1], timings[0]
// non-inverted protocols with recorded...
// signals starting high: data bits timings from positions 2 ... (changeCount - 1)
// sync bit timings[0], timings[1]
// This version takes into account both options by advancing 1 position for the later
//
// inverted protocols with recorded...
// signals starting low: data bits timings from positions 2 ... (changeCount - 1)
// sync bit timings[changeCount - 1], timings[0]
// inverted protocols with recorded...
// signals starting high: data bits timings from positions 1 ... (changeCount - 2)
// sync bit timings[0], timings[1]
// This version stores an alternate phase for decoding to cope with inverted protocols
unsigned int numberofdatabits = (changeCount - 2) / 2;
unsigned int dataduration = 0;
unsigned long squareddataduration = 0; // preparation for variance calculation
unsigned long code = 0;
unsigned int delay = 0; // all appearances of delay can be removed if, in future versions, it is decided to drop backwards compatibility
unsigned int alternatedataduration = 0;
unsigned long alternatesquareddataduration = 0; // preparation for variance calculation
unsigned long alternatecode = 0;
unsigned int alternatedelay = 0; // all appearances of delay can be removed if, in future versions, it is decided to drop backwards compatibility
// calculate average of data bits duration
// calculate variance of data bits duration
// decode bit sequence,
// get delay as average of the shorter level timings (for backwards compatibility)
// calculate for alternate positions (shifted one timing) as well
for (unsigned int i = 1; i < changeCount - 2; i += 2) {
unsigned int thisbitDuration = RCSwitch::timings[i]+RCSwitch::timings[i + 1];
dataduration += thisbitDuration;
squareddataduration += (unsigned long)thisbitDuration*(unsigned long)thisbitDuration;
code <<= 1;
if (RCSwitch::timings[i] < RCSwitch::timings[i + 1]) {
// zero
// sum accumulated duration of shorter level timings
delay += RCSwitch::timings[i];
// all appearances of delay can be removed if dropping backwards compatibility
} else {
// one
code |= 1;
// sum accumulated duration of shorter level timings
delay += RCSwitch::timings[i + 1];
// all appearances of delay can be removed if dropping backwards compatibility
}
// for inverted protocols - timings are shifted
unsigned int alternatebitDuration = RCSwitch::timings[i + 1]+RCSwitch::timings[i + 2];
alternatedataduration += alternatebitDuration;
alternatesquareddataduration += (unsigned long)alternatebitDuration*(unsigned long)alternatebitDuration;
alternatecode <<= 1;
if (RCSwitch::timings[i + 1] < RCSwitch::timings[i + 2]) {
// zero
// sum accumulated duration of shorter level timings
alternatedelay += RCSwitch::timings[i + 1];
// all appearances of delay can be removed if dropping backwards compatibility
} else {
// one
alternatecode |= 1;
// sum accumulated duration of shorter level timings
alternatedelay += RCSwitch::timings[i + 2];
// all appearances of delay can be removed if dropping backwards compatibility
}
}
unsigned long variancebitduration = (squareddataduration - (unsigned long)dataduration*(unsigned long)dataduration/numberofdatabits)/(numberofdatabits-1);
unsigned long alternatevariancebitduration = (alternatesquareddataduration - (unsigned long)alternatedataduration*(unsigned long)alternatedataduration/numberofdatabits)/(numberofdatabits-1);
// decide whether databits are represented by timings 1+2 or 2+3
bool databitsstartinone = variancebitduration < alternatevariancebitduration;
// Value true when NOT INVERTED
// PITFALL: occasionally (depending on the combination of bits) an inverted signal could be identified as direct signal
unsigned int averagebitduration = 0;
unsigned long squaredaveragebitduration = 0;
if(databitsstartinone) {
averagebitduration = (int)(0.5 + ((double)dataduration)/numberofdatabits);
squaredaveragebitduration = (unsigned long)averagebitduration * (unsigned long)averagebitduration;
} else {
averagebitduration = (int)(0.5 + ((double)alternatedataduration)/numberofdatabits);
squaredaveragebitduration = (unsigned long)averagebitduration * (unsigned long)averagebitduration;
variancebitduration = alternatevariancebitduration;
code = alternatecode;
delay = alternatedelay;
}
// check whether all bits durations are similar, discard otherwise
// a coefficient of variation (standard deviation/average) threshold of 5% should be adequate
// that means rejecting if standard deviation > average * 5 / 100
// in the squared scale is variance > squared average * 25 / 10000
if (variancebitduration * 10000 > squaredaveragebitduration * 25 ) {
return false;
}
bool invertedprotocoldecoded = !((!databitsstartinone) ^ (tmpfirstperiodlevel == 0));
// get delay as average of the shorter level timings
delay = (int)(0.5 + ((double)delay)/numberofdatabits);
// ratio between long and short timing
unsigned int protocolratio = (unsigned int)(0.5 + ((double)(averagebitduration - delay)) / (double)delay);
// improved pulselenght (delay) calculation
int normalizedpulselength = (int)(0.5 + (double)averagebitduration/(double)(protocolratio+1));
// store results
RCSwitch::nReceivedValue = code;
RCSwitch::nReceivedBitlength = numberofdatabits;
RCSwitch::nReceivedDelay = normalizedpulselength;
RCSwitch::nReceivedInverted = invertedprotocoldecoded;
RCSwitch::nReceivedLevelInFirstTiming = tmpfirstperiodlevel;
// for compatibility: check which protocol fits the data
// this can be completely removed from the receiver part of the library
// and let the programer check if the received code is from the protocol
// that was expected
const unsigned int delayTolerance = delay * RCSwitch::nReceiveTolerance / 100;
for(unsigned int i = 1; i <= numProto; i++) {
#ifdef ESP8266
const Protocol &pro = proto[i-1];
#else
Protocol pro;
memcpy_P(&pro, &proto[i-1], sizeof(Protocol));
#endif
if (invertedprotocoldecoded == pro.invertedSignal && // protocol inversion is correct AND
diff(delay, pro.pulseLength) < delayTolerance && // pulse length is correct AND
protocolratio == (int)(0.5 + (double)pro.one.high/(double)pro.one.low) && // long vs short ratio is correct AND
( (databitsstartinone) ?
diff(RCSwitch::timings[0], pro.syncFactor.low * delay) < (pro.syncFactor.low * delayTolerance) // the sync timing is correct
:
diff(RCSwitch::timings[1], pro.syncFactor.low * delay) < (pro.syncFactor.low * delayTolerance) // the sync timing is correct
) &&
( (databitsstartinone) ?
diff(RCSwitch::timings[changeCount-1], pro.syncFactor.high * delay) < (pro.syncFactor.high * delayTolerance ) // the sync timing is correct
:
diff(RCSwitch::timings[0], pro.syncFactor.high * delay) < (pro.syncFactor.high * delayTolerance ) // the sync timing is correct
)
)
{ // the sync timing is correct
finalp = i;
break;
}
}
/* For protocols that start low, the sync period looks like
* _________
* _____________| |XXXXXXXXXXXX|
*
* |--1st dur--|-2nd dur-|-Start data-|
*
* The 3rd saved duration starts the data.
*
* For protocols that start high, the sync period looks like
*
* ______________
* | |____________|XXXXXXXXXXXXX|
*
* |-filtered out-|--1st dur--|--Start data--|
*
* The 2nd saved duration starts the data
*/
RCSwitch::nReceivedProtocol = finalp; // will be 0 if the code is recognized but it is of an unknown protocol
return true;
}
void RECEIVE_ATTR RCSwitch::handleInterrupt() {
static unsigned int changeCount = 0;
static unsigned long lastTime = 0;
static unsigned int repeatCount = 0;
const long time = micros();
const unsigned int duration = time - lastTime;
if (duration > RCSwitch::nSeparationLimit & changeCount != 1 ) {
// A long stretch without signal level change occurred. This could
// be the gap between two transmission.
// It allows a second long duration to be stored
// to accomodate for protocols with long high-level (first part) sync duration
if (diff(duration, RCSwitch::timings[0]) < 200) {
// This long signal is close in length to the long signal which
// started the previously recorded timings; this suggests that
// it may indeed by a a gap between two transmissions (we assume
// here that a sender will send the signal multiple times,
// with roughly the same gap between them).
repeatCount++;
if (repeatCount == 2) {
receiveProtocol(1,changeCount);
repeatCount = 0;
}
}
changeCount = 0;
// store the opposite level, because the time recorded is the one of the previous level
RCSwitch::firstperiodlevel = ! digitalRead(RCSwitch::nStaticReceiverPin);
}
// detect overflow
if (changeCount >= RCSWITCH_MAX_CHANGES) {
changeCount = 0;
// store the opposite level, because the time recorded is the one of the previous level
RCSwitch::firstperiodlevel = ! digitalRead(RCSwitch::nStaticReceiverPin);
repeatCount = 0;
}
RCSwitch::timings[changeCount++] = duration;
lastTime = time;
}
#endif

View file

@ -0,0 +1,190 @@
/*
RCSwitch - Arduino libary for remote control outlet switches
Copyright (c) 2011 Suat Özgür. All right reserved.
Contributors:
- Andre Koehler / info(at)tomate-online(dot)de
- Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
- Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46
- Dominik Fischer / dom_fischer(at)web(dot)de
- Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
- Max Horn / max(at)quendi(dot)de
- Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com
Project home: https://github.com/sui77/rc-switch/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _RCSwitch_h
#define _RCSwitch_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#elif defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
#include "Energia.h"
#elif defined(RPI) // Raspberry Pi
#define RaspberryPi
// Include libraries for RPi:
#include <string.h> /* memcpy */
#include <stdlib.h> /* abs */
#include <wiringPi.h>
#elif defined(SPARK)
#include "application.h"
#else
#include "WProgram.h"
#endif
#include <stdint.h>
// At least for the ATTiny X4/X5, receiving has to be disabled due to
// missing libm depencies (udivmodhi4)
#if defined( __AVR_ATtinyX5__ ) or defined ( __AVR_ATtinyX4__ )
#define RCSwitchDisableReceiving
#endif
// Number of maximum high/Low changes per packet.
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
#define RCSWITCH_MAX_CHANGES 67
class RCSwitch {
public:
RCSwitch();
void switchOn(int nGroupNumber, int nSwitchNumber);
void switchOff(int nGroupNumber, int nSwitchNumber);
void switchOn(const char* sGroup, int nSwitchNumber);
void switchOff(const char* sGroup, int nSwitchNumber);
void switchOn(char sFamily, int nGroup, int nDevice);
void switchOff(char sFamily, int nGroup, int nDevice);
void switchOn(const char* sGroup, const char* sDevice);
void switchOff(const char* sGroup, const char* sDevice);
void switchOn(char sGroup, int nDevice);
void switchOff(char sGroup, int nDevice);
void sendTriState(const char* sCodeWord);
void send(unsigned long code, unsigned int length);
void send(const char* sCodeWord);
#if not defined( RCSwitchDisableReceiving )
void enableReceive(int interrupt);
void enableReceive();
void disableReceive();
bool available();
void resetAvailable();
unsigned long getReceivedValue();
unsigned int getReceivedBitlength();
unsigned int getReceivedDelay();
unsigned int getReceivedProtocol();
unsigned int* getReceivedRawdata();
bool getReceivedInverted();
unsigned int getReceivedLevelInFirstTiming();
#endif
void enableTransmit(int nTransmitterPin);
void disableTransmit();
void setPulseLength(int nPulseLength);
void setRepeatTransmit(int nRepeatTransmit);
#if not defined( RCSwitchDisableReceiving )
void setReceiveTolerance(int nPercent);
#endif
/**
* Description of a single pulse, which consists of a high signal
* whose duration is "high" times the base pulse length, followed
* by a low signal lasting "low" times the base pulse length.
* Thus, the pulse overall lasts (high+low)*pulseLength
*/
struct HighLow {
uint8_t high;
uint8_t low;
};
/**
* A "protocol" describes how zero and one bits are encoded into high/low
* pulses.
*/
struct Protocol {
/** base pulse length in microseconds, e.g. 350 */
uint16_t pulseLength;
HighLow syncFactor;
HighLow zero;
HighLow one;
/**
* If true, interchange high and low logic levels in all transmissions.
*
* By default, RCSwitch assumes that any signals it sends or receives
* can be broken down into pulses which start with a high signal level,
* followed by a a low signal level. This is e.g. the case for the
* popular PT 2260 encoder chip, and thus many switches out there.
*
* But some devices do it the other way around, and start with a low
* signal level, followed by a high signal level, e.g. the HT6P20B. To
* accommodate this, one can set invertedSignal to true, which causes
* RCSwitch to change how it interprets any HighLow struct FOO: It will
* then assume transmissions start with a low signal lasting
* FOO.high*pulseLength microseconds, followed by a high signal lasting
* FOO.low*pulseLength microseconds.
*/
bool invertedSignal;
};
void setProtocol(Protocol protocol);
void setProtocol(int nProtocol);
void setProtocol(int nProtocol, int nPulseLength);
private:
char* getCodeWordA(const char* sGroup, const char* sDevice, bool bStatus);
char* getCodeWordB(int nGroupNumber, int nSwitchNumber, bool bStatus);
char* getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus);
char* getCodeWordD(char group, int nDevice, bool bStatus);
void transmit(HighLow pulses);
#if not defined( RCSwitchDisableReceiving )
static void handleInterrupt();
static bool receiveProtocol(const int p, unsigned int changeCount);
int nReceiverInterrupt;
static int nStaticReceiverPin; // needed because nReceiverInterrupt (receiver pin) can not be read from handleInterrupt because it is static
#endif
int nTransmitterPin;
int nRepeatTransmit;
Protocol protocol;
#if not defined( RCSwitchDisableReceiving )
static int nReceiveTolerance;
volatile static unsigned long nReceivedValue;
volatile static unsigned int nReceivedBitlength;
volatile static unsigned int nReceivedDelay;
volatile static unsigned int nReceivedProtocol;
static bool nReceivedInverted;
static unsigned int nReceivedLevelInFirstTiming;
const static unsigned int nSeparationLimit;
/*
* timings[0] contains sync timing, followed by a number of bits
*/
static unsigned int firstperiodlevel;
static unsigned int timings[RCSWITCH_MAX_CHANGES];
#endif
};
#endif

View file

@ -0,0 +1,41 @@
# rc-switch
[![Build Status](https://travis-ci.org/sui77/rc-switch.svg?branch=master)](https://travis-ci.org/sui77/rc-switch)
Use your Arduino or Raspberry Pi to operate remote radio controlled devices
## Download
https://github.com/sui77/rc-switch/releases/latest
rc-switch is also listed in the arduino library manager.
## Wiki
https://github.com/sui77/rc-switch/wiki
## Info
### Send RC codes
Use your Arduino or Raspberry Pi to operate remote radio controlled devices.
This will most likely work with all popular low cost power outlet sockets. If
yours doesn't work, you might need to adjust the pulse length.
All you need is a Arduino or Raspberry Pi, a 315/433MHz AM transmitter and one
or more devices with one of the supported chipsets:
- SC5262 / SC5272
- HX2262 / HX2272
- PT2262 / PT2272
- EV1527 / RT1527 / FP1527 / HS1527
- Intertechno outlets
- HT6P20X
### Receive and decode RC codes
Find out what codes your remote is sending. Use your remote to control your
Arduino.
All you need is an Arduino, a 315/433MHz AM receiver (altough there is no
instruction yet, yes it is possible to hack an existing device) and a remote
hand set.
For the Raspberry Pi, clone the https://github.com/ninjablocks/433Utils project to
compile a sniffer tool and transmission commands.

View file

@ -0,0 +1,100 @@
/*
Example for analyzing and proposing unknown new protocols
https://github.com/Martin-Laclaustra/rc-switch/
Requires modified rc-switch branch "protocollessreceiver"
with ReceivedInverted() function exposed.
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
// Use mySwitch.enableReceive(D2); for ESP8266
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
int databuffer[64]; // get a copy of the received timings before they are overwritten
int numberoftimings = 2 * mySwitch.getReceivedBitlength() + 2;
if(numberoftimings > 64) numberoftimings = 64;
for (int i = 0; i < numberoftimings; i++) {
databuffer[i] = mySwitch.getReceivedRawdata()[i];
}
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
unsigned int databitsoffset = abs( (int)mySwitch.getReceivedLevelInFirstTiming() - (int)mySwitch.getReceivedInverted());
//Serial.println( mySwitch.getReceivedLevelInFirstTiming() );
//Serial.println( mySwitch.getReceivedInverted() );
//Serial.println( databitsoffset );
unsigned long dataduration = 0;
for (unsigned int i = 1 + databitsoffset; i < numberoftimings - 1 + databitsoffset; i++) {
dataduration += databuffer[i];
}
Serial.print("data bits of pulse train duration: ");
Serial.println( dataduration );
unsigned int averagebitduration = (int)(0.5 + ((double)dataduration)/mySwitch.getReceivedBitlength());
unsigned int protocolratio = (unsigned int)(0.5 + ((double)(averagebitduration - mySwitch.getReceivedDelay())) / (double)mySwitch.getReceivedDelay());
Serial.print("proposed protocol: { ");
Serial.print(mySwitch.getReceivedDelay());
Serial.print(", { ");
Serial.print( (databitsoffset==0) ?
(int) (0.5 + (double)databuffer[2*mySwitch.getReceivedBitlength()+1]/(double)mySwitch.getReceivedDelay())
:
(int) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay())
);
Serial.print(", ");
Serial.print( (databitsoffset==0) ?
(int) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay())
:
(int) (0.5 + (double)databuffer[1]/(double)mySwitch.getReceivedDelay())
);
Serial.print(" }, { ");
Serial.print("1");
Serial.print(", ");
Serial.print(protocolratio);
Serial.print(" }, { ");
Serial.print(protocolratio);
Serial.print(", ");
Serial.print("1");
Serial.print(" }, ");
Serial.print((mySwitch.getReceivedInverted()) ? "true" : "false" );
Serial.println(" }");
// raw signal
Serial.println("====");
Serial.print("first level ");
Serial.println((mySwitch.getReceivedLevelInFirstTiming() == 0) ? "down" : "up" );
for (int i = 0; i < 2*mySwitch.getReceivedBitlength()+2 - 1 + databitsoffset; i++) {
Serial.print(databuffer[i]);
Serial.print(" ");
if((i - databitsoffset) % 16 == 0) Serial.println("");
}
if ((2*mySwitch.getReceivedBitlength()+2 - 1 + databitsoffset - 1) % 16 != 0) Serial.println("");
if (databitsoffset != 1) Serial.println(databuffer[2*mySwitch.getReceivedBitlength()+1]);
// plot signal in spreadsheet
Serial.println("====");
}
mySwitch.resetAvailable();
}
}

View file

@ -0,0 +1,24 @@
/*
Example for receiving
https://github.com/sui77/rc-switch/
If you want to visualize a telegram copy the raw data and
paste it into http://test.sui.li/oszi/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}

View file

@ -0,0 +1,74 @@
static const char* bin2tristate(const char* bin);
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength);
void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
if (decimal == 0) {
Serial.print("Unknown encoding.");
} else {
const char* b = dec2binWzerofill(decimal, length);
Serial.print("Decimal: ");
Serial.print(decimal);
Serial.print(" (");
Serial.print( length );
Serial.print("Bit) Binary: ");
Serial.print( b );
Serial.print(" Tri-State: ");
Serial.print( bin2tristate( b) );
Serial.print(" PulseLength: ");
Serial.print(delay);
Serial.print(" microseconds");
Serial.print(" Protocol: ");
Serial.println(protocol);
}
Serial.print("Raw data: ");
for (unsigned int i=0; i<= length*2; i++) {
Serial.print(raw[i]);
Serial.print(",");
}
Serial.println();
Serial.println();
}
static const char* bin2tristate(const char* bin) {
static char returnValue[50];
int pos = 0;
int pos2 = 0;
while (bin[pos]!='\0' && bin[pos+1]!='\0') {
if (bin[pos]=='0' && bin[pos+1]=='0') {
returnValue[pos2] = '0';
} else if (bin[pos]=='1' && bin[pos+1]=='1') {
returnValue[pos2] = '1';
} else if (bin[pos]=='0' && bin[pos+1]=='1') {
returnValue[pos2] = 'F';
} else {
return "not applicable";
}
pos = pos+2;
pos2++;
}
returnValue[pos2] = '\0';
return returnValue;
}
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) {
static char bin[64];
unsigned int i=0;
while (Dec > 0) {
bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
Dec = Dec >> 1;
}
for (unsigned int j = 0; j< bitLength; j++) {
if (j >= bitLength - i) {
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
} else {
bin[j] = '0';
}
}
bin[bitLength] = '\0';
return bin;
}

View file

@ -0,0 +1,35 @@
/*
Simple example for receiving
https://github.com/sui77/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
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() );
}
mySwitch.resetAvailable();
}
}

View file

@ -0,0 +1,57 @@
/*
Example for different sending methods
https://github.com/sui77/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
// Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15);
}
void loop() {
/* See Example: TypeA_WithDIPSwitches */
mySwitch.switchOn("11111", "00010");
delay(1000);
mySwitch.switchOff("11111", "00010");
delay(1000);
/* Same switch as above, but using decimal code */
mySwitch.send(5393, 24);
delay(1000);
mySwitch.send(5396, 24);
delay(1000);
/* Same switch as above, but using binary code */
mySwitch.send("000000000001010100010001");
delay(1000);
mySwitch.send("000000000001010100010100");
delay(1000);
/* Same switch as above, but tri-state code */
mySwitch.sendTriState("00000FFF0F0F");
delay(1000);
mySwitch.sendTriState("00000FFF0FF0");
delay(1000);
delay(20000);
}

View file

@ -0,0 +1,40 @@
/*
Example for outlets which are configured with a 10 pole DIP switch.
https://github.com/sui77/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
}
void loop() {
// Switch on:
// The first parameter represents the setting of the first 5 DIP switches.
// In this example it's ON-ON-OFF-OFF-ON.
//
// The second parameter represents the setting of the last 5 DIP switches.
// In this example the last 5 DIP switches are OFF-ON-OFF-ON-OFF.
mySwitch.switchOn("11001", "01010");
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff("11001", "01010");
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,43 @@
/*
This is a minimal sketch without using the library at all but only works for
the 10 pole dip switch sockets. It saves a lot of memory and thus might be
very useful to use with ATTinys :)
https://github.com/sui77/rc-switch/
*/
int RCLpin = 7;
void setup() {
pinMode(RCLpin, OUTPUT);
}
void loop() {
RCLswitch(0b010001000001); // DIPs an Steckdose: 0100010000 An:01
delay(2000);
RCLswitch(0b010001000010); // DIPs an Steckdose: 0100010000 Aus:10
delay(2000);
}
void RCLswitch(uint16_t code) {
for (int nRepeat=0; nRepeat<6; nRepeat++) {
for (int i=4; i<16; i++) {
RCLtransmit(1,3);
if (((code << (i-4)) & 2048) > 0) {
RCLtransmit(1,3);
} else {
RCLtransmit(3,1);
}
}
RCLtransmit(1,31);
}
}
void RCLtransmit(int nHighPulses, int nLowPulses) {
digitalWrite(RCLpin, HIGH);
delayMicroseconds( 350 * nHighPulses);
digitalWrite(RCLpin, LOW);
delayMicroseconds( 350 * nLowPulses);
}

View file

@ -0,0 +1,40 @@
/*
Example for outlets which are configured with two rotary/sliding switches.
https://github.com/sui77/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
}
void loop() {
// Switch on:
// The first parameter represents the setting of the first rotary switch.
// In this example it's switched to "1" or "A" or "I".
//
// The second parameter represents the setting of the second rotary switch.
// In this example it's switched to "4" or "D" or "IV".
mySwitch.switchOn(1, 4);
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff(1, 4);
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,40 @@
/*
Example for Intertechno outlets
https://github.com/sui77/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
}
void loop() {
// Switch on:
// The first parameter represents the familycode (a, b, c, ... f)
// The second parameter represents the group number
// The third parameter represents the device number
//
// In this example it's family 'b', group #3, device #2
mySwitch.switchOn('b', 3, 2);
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff('b', 3, 2);
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,41 @@
/*
Example for REV outlets (e.g. 8342L)
https://github.com/sui77/rc-switch/
Need help? http://forum.ardumote.com
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// set pulse length.
mySwitch.setPulseLength(360);
}
void loop() {
// Switch on:
// The first parameter represents the channel (a, b, c, d)
// The second parameter represents the device number
//
// In this example it's family 'd', device #2
mySwitch.switchOn('d', 2);
// Wait a second
delay(1000);
// Switch off
mySwitch.switchOff('d', 2);
// Wait another second
delay(1000);
}

View file

@ -0,0 +1,154 @@
/*
A simple RCSwitch/Ethernet/Webserver demo
https://github.com/sui77/rc-switch/
*/
#include <SPI.h>
#include <Ethernet.h>
#include <RCSwitch.h>
// Ethernet configuration
uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC Address
uint8_t ip[] = { 192,168,0, 2 }; // IP Address
EthernetServer server(80); // Server Port 80
// RCSwitch configuration
RCSwitch mySwitch = RCSwitch();
int RCTransmissionPin = 7;
// More to do...
// You should also modify the processCommand() and
// httpResponseHome() functions to fit your needs.
/**
* Setup
*/
void setup() {
Ethernet.begin(mac, ip);
server.begin();
mySwitch.enableTransmit( RCTransmissionPin );
}
/**
* Loop
*/
void loop() {
char* command = httpServer();
}
/**
* Command dispatcher
*/
void processCommand(char* command) {
if (strcmp(command, "1-on") == 0) {
mySwitch.switchOn(1,1);
} else if (strcmp(command, "1-off") == 0) {
mySwitch.switchOff(1,1);
} else if (strcmp(command, "2-on") == 0) {
mySwitch.switchOn(1,2);
} else if (strcmp(command, "2-off") == 0) {
mySwitch.switchOff(1,2);
}
}
/**
* HTTP Response with homepage
*/
void httpResponseHome(EthernetClient c) {
c.println("HTTP/1.1 200 OK");
c.println("Content-Type: text/html");
c.println();
c.println("<html>");
c.println("<head>");
c.println( "<title>RCSwitch Webserver Demo</title>");
c.println( "<style>");
c.println( "body { font-family: Arial, sans-serif; font-size:12px; }");
c.println( "</style>");
c.println("</head>");
c.println("<body>");
c.println( "<h1>RCSwitch Webserver Demo</h1>");
c.println( "<ul>");
c.println( "<li><a href=\"./?1-on\">Switch #1 on</a></li>");
c.println( "<li><a href=\"./?1-off\">Switch #1 off</a></li>");
c.println( "</ul>");
c.println( "<ul>");
c.println( "<li><a href=\"./?2-on\">Switch #2 on</a></li>");
c.println( "<li><a href=\"./?2-off\">Switch #2 off</a></li>");
c.println( "</ul>");
c.println( "<hr>");
c.println( "<a href=\"https://github.com/sui77/rc-switch/\">https://github.com/sui77/rc-switch/</a>");
c.println("</body>");
c.println("</html>");
}
/**
* HTTP Redirect to homepage
*/
void httpResponseRedirect(EthernetClient c) {
c.println("HTTP/1.1 301 Found");
c.println("Location: /");
c.println();
}
/**
* HTTP Response 414 error
* Command must not be longer than 30 characters
**/
void httpResponse414(EthernetClient c) {
c.println("HTTP/1.1 414 Request URI too long");
c.println("Content-Type: text/plain");
c.println();
c.println("414 Request URI too long");
}
/**
* Process HTTP requests, parse first request header line and
* call processCommand with GET query string (everything after
* the ? question mark in the URL).
*/
char* httpServer() {
EthernetClient client = server.available();
if (client) {
char sReturnCommand[32];
int nCommandPos=-1;
sReturnCommand[0] = '\0';
while (client.connected()) {
if (client.available()) {
char c = client.read();
if ((c == '\n') || (c == ' ' && nCommandPos>-1)) {
sReturnCommand[nCommandPos] = '\0';
if (strcmp(sReturnCommand, "\0") == 0) {
httpResponseHome(client);
} else {
processCommand(sReturnCommand);
httpResponseRedirect(client);
}
break;
}
if (nCommandPos>-1) {
sReturnCommand[nCommandPos++] = c;
}
if (c == '?' && nCommandPos == -1) {
nCommandPos = 0;
}
}
if (nCommandPos > 30) {
httpResponse414(client);
sReturnCommand[0] = '\0';
break;
}
}
if (nCommandPos!=-1) {
sReturnCommand[nCommandPos] = '\0';
}
// give the web browser time to receive the data
delay(1);
client.stop();
return sReturnCommand;
}
return '\0';
}

View file

@ -0,0 +1,57 @@
#######################################
# Syntax Coloring Map For RCSwitch
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
RCSwitch KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
##########
#SENDS Begin
##########
switchOn KEYWORD2
switchOff KEYWORD2
sendTriState KEYWORD2
send KEYWORD2
##########
#SENDS End
##########
##########
#RECEIVE Begin
##########
enableReceive KEYWORD2
disableReceive KEYWORD2
available KEYWORD2
resetAvailable KEYWORD2
setReceiveTolerance KEYWORD2
getReceivedValue KEYWORD2
getReceivedBitlength KEYWORD2
getReceivedDelay KEYWORD2
getReceivedProtocol KEYWORD2
getReceivedRawdata KEYWORD2
##########
#RECEIVE End
##########
##########
#OTHERS Begin
##########
enableTransmit KEYWORD2
disableTransmit KEYWORD2
setPulseLength KEYWORD2
setProtocol KEYWORD2
setRepeatTransmit KEYWORD2
##########
#OTHERS End
##########
#######################################
# Constants (LITERAL1)
#######################################

View file

@ -0,0 +1,21 @@
{
"name": "RCSwitch",
"description": "Use your Arduino or Raspberry Pi to operate remote radio controlled devices",
"keywords": "rf, radio, wireless",
"authors":
{
"name": "Suat Ozgur"
},
"repository":
{
"type": "git",
"url": "https://github.com/sui77/rc-switch.git"
},
"version": "2.52",
"frameworks": [
"arduino",
"energia",
"wiringpi"
],
"platforms": "*"
}

View file

@ -0,0 +1,10 @@
name=rc-switch
version=2.6.2
author=sui77
maintainer=sui77,fingolfin <noreply@sui.li>
sentence=Operate 433/315Mhz devices.
paragraph=Use your Arduino or Raspberry Pi to operate remote radio controlled devices. This will most likely work with all popular low cost power outlet sockets.
category=Device Control
url=https://github.com/sui77/rc-switch
architectures=avr,esp8266
includes=RCSwitch.h