├── README.md ├── SmartRC-CC1101-Driver-Lib-master.zip ├── arduino.inf ├── cc1101-radio-chat-v2.ino ├── cc1101-radio-chat.ino └── cc1101-radio-chat.png /README.md: -------------------------------------------------------------------------------- 1 | # cc1101-arduino-radio-communicator 2 | This is simple half duplex radio communication device built with CC1101 module and Arduino Pro Micro (3.3V / 8MHz) using SmartRC library 3 | You simply connect your Arduino Pro Micro (Arduino Leonardo clone from Sparkfun) to USB port of your PC and launch Putty terminal to communicate over USB Serial port ( /dev/ttyACM0 port in Linux, COMxx in Windows). Also you may connect this device to Android OTG USB port in your smartphone and use USB Serial Terminal application ( set option CDC driver). 4 | 5 | 6 | The code uses SmartRC library (modified Electrohouse library by Little_S@tan) which allows to customize ALL transmission parameters in human readable format without using SmartRF studio from TI (CC1101 parameter customization tool). To use it please download following ZIP library from following github link https://github.com/LSatan/SmartRC-CC1101-Driver-Lib and attach it to the script in Arduino IDE. 7 | 8 | 9 | Arduino Pro Micro board ( ATMEGA32U4 chip ) must support 3.3Volt VCC and 3.3V TTL logic because this is required by CC1101 board, otherwise you will fry CC1101 chip. Please follow this guide to setup your Arduino environment for Arduino Pro Micro board : https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/all 10 | 11 | If you are having issues with uploading the code from Arduino IDE to the board, after pressing "Upload" in Arduino you have to immediatelly short GND+RST pins two times in few seconds. Then bootloader in Arduino Pro Micro will start (common issue) and upload will begin. 12 | 13 | 14 | 15 | Connections to be made : 16 | 17 | ARDUINO PRO MICRO 3.3V / 8MHz <-> CC1101 BOARD 18 | 19 | DIGITAL PIN 3 ( PD0 / INT0 ) <-> CC1101 GDO0 20 | DIGITAL PIN 9 ( PB5 ) <-> CC1101 GDO2 21 | DIGITAL PIN 10 ( PB6 ) <-> CC1101 CSN / CS / SS 22 | DIGITAL PIN 16 ( PB2 / MOSI ) <-> CC1101 MOSI 23 | DIGITAL PIN 14 ( PB3 / MISO ) <-> CC1101 MISO 24 | DIGITAL PIN 15 ( PB1 / SCK ) <-> CC1101 SCLK / CLK 25 | VCC 3.3V <-> CC1101 VCC 26 | GND <-> CC1101 GND 27 | 28 | 29 | The video showing how this device works is available here : https://youtu.be/aRe3WXXtzLU 30 | -------------------------------------------------------------------------------- /SmartRC-CC1101-Driver-Lib-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcore1976/cc1101-arduino-radio-communicator/b70f304171b07450f5d169766e2e9f826e26199c/SmartRC-CC1101-Driver-Lib-master.zip -------------------------------------------------------------------------------- /arduino.inf: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright 2015 Arduino LLC (http://www.arduino.cc/) 3 | ; 4 | ; Developed by Zach Eveland, Blacklabel Development, Inc. 5 | ; 6 | ; Arduino is free software; you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation; either version 2 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program; if not, write to the Free Software 18 | ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | ; 20 | ; As a special exception, you may use this file as part of a free software 21 | ; library without restriction. Specifically, if other files instantiate 22 | ; templates or use macros or inline functions from this file, or you compile 23 | ; this file and link it with other files to produce an executable, this 24 | ; file does not by itself cause the resulting executable to be covered by 25 | ; the GNU General Public License. This exception does not however 26 | ; invalidate any other reasons why the executable file might be covered by 27 | ; the GNU General Public License. 28 | ; 29 | 30 | [Strings] 31 | DriverPackageDisplayName="Arduino USB Driver" 32 | ManufacturerName="Arduino LLC (www.arduino.cc)" 33 | ServiceName="USB RS-232 Emulation Driver" 34 | bossa.name="Bossa Program Port" 35 | due.programming_port.name="Arduino Due Programming Port" 36 | due.sketch.name="Arduino Due" 37 | esplora.bootloader.name="Arduino Esplora bootloader" 38 | esplora.sketch.name="Arduino Esplora" 39 | leonardo.bootloader.name="Arduino Leonardo bootloader" 40 | leonardo.sketch.name="Arduino Leonardo" 41 | lilypadUSB.bootloader.name="Arduino LilyPad USB bootloader" 42 | lilypadUSB.sketch.name="Arduino LilyPad USB" 43 | mega2560.name="Arduino Mega 2560" 44 | mega2560rev3.name="Arduino Mega 2560" 45 | megaADK.name="Arduino Mega ADK" 46 | megaADKrev3.name="Arduino Mega ADK" 47 | micro.bootloader.name="Arduino Micro bootloader" 48 | micro.sketch.name="Arduino Micro" 49 | mkr1000.sketch.name="Arduino MKR1000" 50 | mkr1000.bootloader.name="Arduino MKR1000 bootloader" 51 | robotControl.bootloader.name="Arduino Robot Control bootloader" 52 | robotControl.sketch.name="Arduino Robot" 53 | robotMotor.bootloader.name="Arduino Robot Motor bootloader" 54 | robotMotor.sketch.name="Arduino Robot" 55 | uno.name="Arduino Uno" 56 | unoR3.name="Arduino Uno" 57 | usbserial.name="Arduino USB Serial Light Adapter" 58 | yun.bootloader.name="Arduino Yun bootloader" 59 | yun.sketch.name="Arduino Yun" 60 | zero.edbg.name="Atmel Corp. EDBG CMSIS-DAP" 61 | zero.sketch.name="Arduino Zero" 62 | zero.bootloader.name="Arduino Zero bootloader" 63 | sme_fox.sketch.name="SmartEverything Fox" 64 | sme_fox.bootloader.name="SmartEverything Fox bootloader" 65 | 66 | [DefaultInstall] 67 | CopyINF=arduino.inf 68 | 69 | [Version] 70 | Class=Ports 71 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 72 | Signature="$Windows NT$" 73 | Provider=%ManufacturerName% 74 | DriverPackageDisplayName=%DriverPackageDisplayName% 75 | CatalogFile=arduino.cat 76 | DriverVer=11/24/2015,1.2.3.0 77 | 78 | [Manufacturer] 79 | %ManufacturerName%=DeviceList, NTamd64, NTia64 80 | 81 | [DestinationDirs] 82 | FakeModemCopyFileSection=12 83 | DefaultDestDir=12 84 | 85 | [DeviceList] 86 | %bossa.name%=DriverInstall, USB\VID_03EB&PID_6124 87 | %due.programming_port.name%=DriverInstall, USB\VID_2341&PID_003D 88 | %due.sketch.name%=DriverInstall, USB\VID_2341&PID_003E&MI_00 89 | %esplora.bootloader.name%=DriverInstall, USB\VID_2341&PID_003C 90 | %esplora.sketch.name%=DriverInstall, USB\VID_2341&PID_803C&MI_00 91 | %leonardo.bootloader.name%=DriverInstall, USB\VID_2341&PID_0036 92 | %leonardo.sketch.name%=DriverInstall, USB\VID_2341&PID_8036&MI_00 93 | %lilypadUSB.bootloader.name%=DriverInstall, USB\VID_1B4F&PID_9207 94 | %lilypadUSB.sketch.name%=DriverInstall, USB\VID_1B4F&PID_9208&MI_00 95 | %mega2560rev3.name%=DriverInstall, USB\VID_2341&PID_0042 96 | %mega2560.name%=DriverInstall, USB\VID_2341&PID_0010 97 | %megaADK.name%=DriverInstall, USB\VID_2341&PID_003F 98 | %megaADKrev3.name%=DriverInstall, USB\VID_2341&PID_0044 99 | %micro.bootloader.name%=DriverInstall, USB\VID_2341&PID_0037 100 | %micro.sketch.name%=DriverInstall, USB\VID_2341&PID_8037&MI_00 101 | %mkr1000.sketch.name%=DriverInstall, USB\VID_2341&PID_804E&MI_00 102 | %mkr1000.bootloader.name%=DriverInstall, USB\VID_2341&PID_004E 103 | %robotControl.bootloader.name%=DriverInstall, USB\VID_2341&PID_0038 104 | %robotControl.sketch.name%=DriverInstall, USB\VID_2341&PID_8038&MI_00 105 | %robotMotor.bootloader.name%=DriverInstall, USB\VID_2341&PID_0039 106 | %robotMotor.sketch.name%=DriverInstall, USB\VID_2341&PID_8039&MI_00 107 | %uno.name%=DriverInstall, USB\VID_2341&PID_0001 108 | %unoR3.name%=DriverInstall, USB\VID_2341&PID_0043 109 | %usbserial.name%=DriverInstall, USB\VID_2341&PID_003B 110 | %yun.bootloader.name%=DriverInstall, USB\VID_2341&PID_0041 111 | %yun.sketch.name%=DriverInstall, USB\VID_2341&PID_8041&MI_00 112 | %zero.edbg.name%=DriverInstall, USB\VID_03EB&PID_2157&MI_01 113 | %zero.sketch.name%=DriverInstall, USB\VID_2341&PID_804D&MI_00 114 | %zero.bootloader.name%=DriverInstall, USB\VID_2341&PID_004D 115 | %sme_fox.sketch.name%=DriverInstall, USB\VID_2341&PID_E002&MI_00 116 | %sme_fox.bootloader.name%=DriverInstall, USB\VID_2341&PID_E001 117 | 118 | [DeviceList.NTamd64] 119 | %bossa.name%=DriverInstall, USB\VID_03EB&PID_6124 120 | %due.programming_port.name%=DriverInstall, USB\VID_2341&PID_003D 121 | %due.sketch.name%=DriverInstall, USB\VID_2341&PID_003E&MI_00 122 | %esplora.bootloader.name%=DriverInstall, USB\VID_2341&PID_003C 123 | %esplora.sketch.name%=DriverInstall, USB\VID_2341&PID_803C&MI_00 124 | %leonardo.bootloader.name%=DriverInstall, USB\VID_2341&PID_0036 125 | %leonardo.sketch.name%=DriverInstall, USB\VID_2341&PID_8036&MI_00 126 | %lilypadUSB.bootloader.name%=DriverInstall, USB\VID_1B4F&PID_9207 127 | %lilypadUSB.sketch.name%=DriverInstall, USB\VID_1B4F&PID_9208&MI_00 128 | %mega2560rev3.name%=DriverInstall, USB\VID_2341&PID_0042 129 | %mega2560.name%=DriverInstall, USB\VID_2341&PID_0010 130 | %megaADK.name%=DriverInstall, USB\VID_2341&PID_003F 131 | %megaADKrev3.name%=DriverInstall, USB\VID_2341&PID_0044 132 | %micro.bootloader.name%=DriverInstall, USB\VID_2341&PID_0037 133 | %micro.sketch.name%=DriverInstall, USB\VID_2341&PID_8037&MI_00 134 | %mkr1000.sketch.name%=DriverInstall, USB\VID_2341&PID_804E&MI_00 135 | %mkr1000.bootloader.name%=DriverInstall, USB\VID_2341&PID_004E 136 | %uno.name%=DriverInstall, USB\VID_2341&PID_0001 137 | %unoR3.name%=DriverInstall, USB\VID_2341&PID_0043 138 | %usbserial.name%=DriverInstall, USB\VID_2341&PID_003B 139 | %robotControl.bootloader.name%=DriverInstall, USB\VID_2341&PID_0038 140 | %robotControl.sketch.name%=DriverInstall, USB\VID_2341&PID_8038&MI_00 141 | %robotMotor.bootloader.name%=DriverInstall, USB\VID_2341&PID_0039 142 | %robotMotor.sketch.name%=DriverInstall, USB\VID_2341&PID_8039&MI_00 143 | %yun.bootloader.name%=DriverInstall, USB\VID_2341&PID_0041 144 | %yun.sketch.name%=DriverInstall, USB\VID_2341&PID_8041&MI_00 145 | %zero.edbg.name%=DriverInstall, USB\VID_03EB&PID_2157&MI_01 146 | %zero.sketch.name%=DriverInstall, USB\VID_2341&PID_804D&MI_00 147 | %zero.bootloader.name%=DriverInstall, USB\VID_2341&PID_004D 148 | %sme_fox.sketch.name%=DriverInstall, USB\VID_2341&PID_E002&MI_00 149 | %sme_fox.bootloader.name%=DriverInstall, USB\VID_2341&PID_E001 150 | 151 | [DeviceList.NTia64] 152 | %bossa.name%=DriverInstall, USB\VID_03EB&PID_6124 153 | %due.programming_port.name%=DriverInstall, USB\VID_2341&PID_003D 154 | %due.sketch.name%=DriverInstall, USB\VID_2341&PID_003E&MI_00 155 | %esplora.bootloader.name%=DriverInstall, USB\VID_2341&PID_003C 156 | %esplora.sketch.name%=DriverInstall, USB\VID_2341&PID_803C&MI_00 157 | %leonardo.bootloader.name%=DriverInstall, USB\VID_2341&PID_0036 158 | %leonardo.sketch.name%=DriverInstall, USB\VID_2341&PID_8036&MI_00 159 | %lilypadUSB.bootloader.name%=DriverInstall, USB\VID_1B4F&PID_9207 160 | %lilypadUSB.sketch.name%=DriverInstall, USB\VID_1B4F&PID_9208&MI_00 161 | %mega2560rev3.name%=DriverInstall, USB\VID_2341&PID_0042 162 | %mega2560.name%=DriverInstall, USB\VID_2341&PID_0010 163 | %megaADK.name%=DriverInstall, USB\VID_2341&PID_003F 164 | %megaADKrev3.name%=DriverInstall, USB\VID_2341&PID_0044 165 | %micro.bootloader.name%=DriverInstall, USB\VID_2341&PID_0037 166 | %micro.sketch.name%=DriverInstall, USB\VID_2341&PID_8037&MI_00 167 | %mkr1000.sketch.name%=DriverInstall, USB\VID_2341&PID_804E&MI_00 168 | %mkr1000.bootloader.name%=DriverInstall, USB\VID_2341&PID_004E 169 | %uno.name%=DriverInstall, USB\VID_2341&PID_0001 170 | %unoR3.name%=DriverInstall, USB\VID_2341&PID_0043 171 | %usbserial.name%=DriverInstall, USB\VID_2341&PID_003B 172 | %robotControl.bootloader.name%=DriverInstall, USB\VID_2341&PID_0038 173 | %robotControl.sketch.name%=DriverInstall, USB\VID_2341&PID_8038&MI_00 174 | %robotMotor.bootloader.name%=DriverInstall, USB\VID_2341&PID_0039 175 | %robotMotor.sketch.name%=DriverInstall, USB\VID_2341&PID_8039&MI_00 176 | %yun.bootloader.name%=DriverInstall, USB\VID_2341&PID_0041 177 | %yun.sketch.name%=DriverInstall, USB\VID_2341&PID_8041&MI_00 178 | %zero.edbg.name%=DriverInstall, USB\VID_03EB&PID_2157&MI_01 179 | %zero.sketch.name%=DriverInstall, USB\VID_2341&PID_804D&MI_00 180 | %zero.bootloader.name%=DriverInstall, USB\VID_2341&PID_004D 181 | %sme_fox.sketch.name%=DriverInstall, USB\VID_2341&PID_E002&MI_00 182 | %sme_fox.bootloader.name%=DriverInstall, USB\VID_2341&PID_E001 183 | 184 | [DriverInstall] 185 | include=mdmcpq.inf,usb.inf 186 | CopyFiles = FakeModemCopyFileSection 187 | AddReg=DriverAddReg 188 | 189 | [DriverAddReg] 190 | HKR,,DevLoader,,*ntkern 191 | HKR,,NTMPDriver,,usbser.sys 192 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 193 | 194 | [DriverInstall.Services] 195 | include=mdmcpq.inf 196 | AddService=usbser, 0x00000002, DriverService 197 | 198 | [DriverService] 199 | DisplayName=%ServiceName% 200 | ServiceType=1 201 | StartType=3 202 | ErrorControl=1 203 | ServiceBinary=%12%\usbser.sys 204 | LoadOrderGroup=Base 205 | 206 | -------------------------------------------------------------------------------- /cc1101-radio-chat-v2.ino: -------------------------------------------------------------------------------- 1 | // 2 | // CC1101 radio chat device 3 | // allows for bidirectioal half duplex communication 4 | // on selected radio channel, modulation, .. 5 | // 6 | // (C) Adam Loboda '2021 7 | // 8 | // based on great SmartRC library by Little_S@tan 9 | // Please download ZIP from 10 | // https://github.com/LSatan/SmartRC-CC1101-Driver-Lib 11 | // and attach it as ZIP library for Arduino 12 | // 13 | // This code will ONLY work with Arduino Pro Micro 3.3V 8MHz 14 | // this version contains BASE64 like encoding of the message 15 | // and XOR encryption with static preshared password 16 | // 17 | 18 | 19 | 20 | #include 21 | 22 | 23 | #define CCBUFFERSIZE 64 24 | 25 | // buffer for receiving CC1101 26 | byte ccreceivingbuffer[CCBUFFERSIZE] = {0}; 27 | 28 | // buffer for sending CC1101 29 | byte ccsendingbuffer[CCBUFFERSIZE] = {0}; 30 | 31 | // buffer for decoding hex to ascii (BASE64 like encoding) 32 | byte textbuffer[CCBUFFERSIZE * 2] = {0}; 33 | 34 | 35 | // The RX LED has a defined Arduino Pro Micro pin 36 | int RXLED = 17; 37 | 38 | 39 | void setup() { 40 | 41 | // initialize USB Serial Port CDC 42 | Serial.begin(9600); 43 | 44 | while (!Serial) { 45 | ; // wait until USB CDC port connects... Needed for Leonardo only 46 | } 47 | Serial.println("CC1101 Radio chat started..."); 48 | Serial.println(); // print CRLF 49 | 50 | // Arduino Pro Micro - RXLED diode will be used for debug blinking 51 | pinMode(RXLED, OUTPUT); // Set RX LED as an output 52 | 53 | // Following section enables SmartRC CC1101 library 54 | // to work with Arduino Pro Micro 55 | // if using different board, please remove it 56 | // defining PINs set for Arduino Pro Micro setup 57 | byte sck = 15; 58 | byte miso = 14; 59 | byte mosi = 16; 60 | byte ss = 10; 61 | int gdo0 = 3; 62 | // initializing library with custom pins selected 63 | ELECHOUSE_cc1101.setSpiPin(sck, miso, mosi, ss); 64 | 65 | // Main part to tune CC1101 with proper frequency, modulation and encoding 66 | ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101! 67 | ELECHOUSE_cc1101.setGDO0(gdo0); // set lib internal gdo pin (gdo0). Gdo2 not use for this example. 68 | ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode. 69 | ELECHOUSE_cc1101.setModulation(1); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK. 70 | 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. 71 | ELECHOUSE_cc1101.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz. 72 | ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0. 73 | 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. 74 | ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz. 75 | ELECHOUSE_cc1101.setDRate(1.2); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud! 76 | 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! 77 | 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. 78 | ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low) 79 | 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. 80 | ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF). 81 | ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on. 82 | 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. 83 | ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved 84 | 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. 85 | ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX. 86 | 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. 87 | 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). 88 | ELECHOUSE_cc1101.setManchester(1); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable. 89 | 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. 90 | ELECHOUSE_cc1101.setPRE(3); // Sets the minimum number of preamble bytes to be transmitted. Values: 0 : 2, 1 : 3, 2 : 4, 3 : 6, 4 : 8, 5 : 12, 6 : 16, 7 : 24 91 | 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. 92 | 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. 93 | 94 | } 95 | 96 | 97 | void loop() { 98 | 99 | // PASSWORD FOR COMMUNICATION ENCRYPTION 100 | char presharedkey[] = "P@55w0rD" ; 101 | 102 | // bytes for encoding received single character to HEX ascii value 103 | char lowhexdigit; 104 | char highhexdigit; 105 | 106 | // index for serial port characters 107 | int i = 0; 108 | 109 | // index for message XOR Encryption 110 | int k = 0; 111 | 112 | //Checks whether something has been received. 113 | if (ELECHOUSE_cc1101.CheckReceiveFlag()) 114 | { 115 | // blink LED RX - only for Arduino Pro Microsss 116 | digitalWrite(RXLED, LOW); // set the RX LED ON 117 | 118 | //CRC Check. If "setCrc(false)" crc returns always OK! 119 | if (ELECHOUSE_cc1101.CheckCRC()) 120 | { 121 | //Get received Data and calculate length 122 | int len = ELECHOUSE_cc1101.ReceiveData(ccreceivingbuffer); 123 | // put NULL at the end of char buffer 124 | ccreceivingbuffer[len] = '\0'; 125 | 126 | 127 | // Now DECRYPT the message via XOR function with preshared key 128 | // for whole string in CC receive buffer 129 | for (i = 0; i < len; i++) 130 | { 131 | for (k = 0; k 9) highhexdigit = highhexdigit - 7; // correction for capital Hex digits 143 | lowhexdigit = (ccreceivingbuffer[i+1] - 48 ); // take second hex digit and substract '0' ASCII 144 | if (lowhexdigit > 9) lowhexdigit = lowhexdigit - 7; // correction for capital Hex digits 145 | textbuffer[i/2] = (highhexdigit * 16) + lowhexdigit; // convert two hex digits to single ASCII 146 | }; 147 | textbuffer[(len/2)] = '\0'; 148 | 149 | 150 | // Serial.print((char *) ccreceivingbuffer); 151 | Serial.print((char *) textbuffer); 152 | }; // end of CRC check IF 153 | 154 | // blink LED RX - only for Arduino Pro Micro 155 | digitalWrite(RXLED, HIGH); // set the RX LED OFF 156 | 157 | }; // end of Check receive flag if 158 | 159 | 160 | // checking if anything received over Serial port has to be send over radio 161 | // if some chars available, copy it into CC sending buffer 162 | 163 | // check if there are available chars in serial port buffer 164 | if (Serial.available()) 165 | { 166 | // blink LED RX - only for Arduino Pro Micro 167 | digitalWrite(RXLED, LOW); // set the RX LED ON 168 | 169 | // clear serial port buffer index 170 | i = 0; 171 | 172 | // something was received over serial port put it into radio sending buffer 173 | while (Serial.available() and (i<(CCBUFFERSIZE-1)) ) 174 | { 175 | // read single character from Serial port 176 | ccsendingbuffer[i] = Serial.read(); 177 | 178 | // also put it as ECHO back to serial port 179 | Serial.write(ccsendingbuffer[i]); 180 | 181 | // if CR was received add also LF character and display it on Serial port 182 | if (ccsendingbuffer[i] == 0x0d ) 183 | { 184 | Serial.write( 0x0a ); 185 | i++; 186 | ccsendingbuffer[i] = 0x0a; 187 | 188 | }; // end of IF 189 | // 190 | // increase CC1101 TX buffer position 191 | i++; 192 | }; 193 | 194 | // put NULL at the end of CC transmission buffer 195 | ccsendingbuffer[i] = '\0'; 196 | 197 | // convert ASCII chars in CC sending buffer to BASE64 like encoding 198 | for (i = 0; i < strlen(ccsendingbuffer) ; i++ ) 199 | { 200 | lowhexdigit = (ccsendingbuffer[i] % 16) + 48; // calculate second hex digit for single ASCII character 201 | if (lowhexdigit > (48+9)) lowhexdigit = lowhexdigit + 7; // adjust for capital hex digit 202 | highhexdigit = (ccsendingbuffer[i] / 16) + 48; // calculate first hex digit for single ASCII character 203 | if (highhexdigit > (48+9)) highhexdigit = highhexdigit + 7; // adjust for capital hex digit 204 | textbuffer[(i*2)] = highhexdigit; // put first hex digit to output buffer 205 | textbuffer[(i*2)+1] = lowhexdigit; // put first hex digit to output buffer 206 | }; 207 | textbuffer[ strlen(ccsendingbuffer) * 2] = '\0'; // put NULL at the end to finish string 208 | 209 | // Now ENCRYPT the message via XOR function with preshared key 210 | for (i = 0; i < (strlen(ccsendingbuffer) * 2) ; i++) 211 | { 212 | for (k = 0; k < strlen(presharedkey); k++) 213 | { 214 | textbuffer[i] = textbuffer[i] ^ presharedkey[k]; 215 | }; 216 | }; // end of i loop 217 | 218 | // send these data to radio over CC1101 219 | // ELECHOUSE_cc1101.SendData(textbuffer, (strlen(ccsendingbuffer) * 2)); 220 | ELECHOUSE_cc1101.SendData(textbuffer, (strlen(ccsendingbuffer) * 2)); 221 | 222 | // blink LED RX - only for Arduino Pro Micro 223 | digitalWrite(RXLED, HIGH); // set the RX LED OFF 224 | 225 | }; 226 | 227 | } // end of main LOOP 228 | -------------------------------------------------------------------------------- /cc1101-radio-chat.ino: -------------------------------------------------------------------------------- 1 | // 2 | // CC1101 radio chat device 3 | // allows for bidirectioal half duplex communication 4 | // on selected radio channel, modulation, .. 5 | // 6 | // (C) Adam Loboda '2021 7 | // 8 | // based on great SmartRC library by Little_S@tan 9 | // Please download ZIP from 10 | // https://github.com/LSatan/SmartRC-CC1101-Driver-Lib 11 | // and attach it as ZIP library for Arduino 12 | // 13 | // This code will ONLY work with Arduino Pro Micro 3.3V 8MHz 14 | // 15 | 16 | 17 | 18 | #include 19 | 20 | 21 | #define CCBUFFERSIZE 64 22 | 23 | // buffer for receiving CC1101 24 | byte ccreceivingbuffer[CCBUFFERSIZE] = {0}; 25 | 26 | // buffer for sending CC1101 27 | byte ccsendingbuffer[CCBUFFERSIZE] = {0}; 28 | 29 | // The RX LED has a defined Arduino Pro Micro pin 30 | int RXLED = 17; 31 | 32 | 33 | void setup() { 34 | 35 | // initialize USB Serial Port CDC 36 | Serial.begin(9600); 37 | 38 | while (!Serial) { 39 | ; // wait until USB CDC port connects... Needed for Leonardo only 40 | } 41 | Serial.println("CC1101 Radio chat started..."); 42 | Serial.println(); // print CRLF 43 | 44 | // Arduino Pro Micro - RXLED diode will be used for debug blinking 45 | pinMode(RXLED, OUTPUT); // Set RX LED as an output 46 | 47 | // Following section enables SmartRC CC1101 library 48 | // to work with Arduino Pro Micro 49 | // if using different board, please remove it 50 | // defining PINs set for Arduino Pro Micro setup 51 | byte sck = 15; 52 | byte miso = 14; 53 | byte mosi = 16; 54 | byte ss = 10; 55 | int gdo0 = 3; 56 | // initializing library with custom pins selected 57 | ELECHOUSE_cc1101.setSpiPin(sck, miso, mosi, ss); 58 | 59 | // Main part to tune CC1101 with proper frequency, modulation and encoding 60 | ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101! 61 | ELECHOUSE_cc1101.setGDO0(gdo0); // set lib internal gdo pin (gdo0). Gdo2 not use for this example. 62 | ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode. 63 | ELECHOUSE_cc1101.setModulation(1); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK. 64 | 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. 65 | ELECHOUSE_cc1101.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz. 66 | ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0. 67 | 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. 68 | ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz. 69 | ELECHOUSE_cc1101.setDRate(1.2); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud! 70 | 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! 71 | 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. 72 | ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low) 73 | 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. 74 | ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF). 75 | ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on. 76 | 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. 77 | ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved 78 | 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. 79 | ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX. 80 | 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. 81 | 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). 82 | ELECHOUSE_cc1101.setManchester(1); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable. 83 | 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. 84 | ELECHOUSE_cc1101.setPRE(3); // Sets the minimum number of preamble bytes to be transmitted. Values: 0 : 2, 1 : 3, 2 : 4, 3 : 6, 4 : 8, 5 : 12, 6 : 16, 7 : 24 85 | 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. 86 | 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. 87 | 88 | } 89 | 90 | 91 | void loop() { 92 | 93 | // index for serial port characters 94 | int i = 0; 95 | 96 | //Checks whether something has been received. 97 | if (ELECHOUSE_cc1101.CheckReceiveFlag()) 98 | { 99 | // blink LED RX - only for Arduino Pro Micro 100 | digitalWrite(RXLED, LOW); // set the RX LED ON 101 | 102 | //CRC Check. If "setCrc(false)" crc returns always OK! 103 | if (ELECHOUSE_cc1101.CheckCRC()) 104 | { 105 | //Get received Data and calculate length 106 | int len = ELECHOUSE_cc1101.ReceiveData(ccreceivingbuffer); 107 | // put NULL at the end of char buffer 108 | ccreceivingbuffer[len] = '\0'; 109 | 110 | //Print received in char format. 111 | Serial.print((char *) ccreceivingbuffer); 112 | }; // end of CRC check IF 113 | 114 | // blink LED RX - only for Arduino Pro Micro 115 | digitalWrite(RXLED, HIGH); // set the RX LED OFF 116 | 117 | }; // end of Check receive flag if 118 | 119 | 120 | // chcecking if anything received over Serial port has to be send over radio 121 | // if some chars available, copy it into CC sending buffer 122 | 123 | // check if there are available chars in serial port buffer 124 | if (Serial.available()) 125 | { 126 | // blink LED RX - only for Arduino Pro Micro 127 | digitalWrite(RXLED, LOW); // set the RX LED ON 128 | 129 | // clear serial port buffer index 130 | i = 0; 131 | 132 | // something was received over serial port put it into radio sending buffer 133 | while (Serial.available() and (i<(CCBUFFERSIZE-1)) ) 134 | { 135 | // read single character from Serial port 136 | ccsendingbuffer[i] = Serial.read(); 137 | 138 | // also put it as ECHO back to serial port 139 | Serial.write(ccsendingbuffer[i]); 140 | 141 | // if CR was received add also LF character and display it on Serial port 142 | if (ccsendingbuffer[i] == 0x0d ) 143 | { 144 | Serial.write( 0x0a ); 145 | i++; 146 | ccsendingbuffer[i] = 0x0a; 147 | } 148 | // 149 | 150 | // increase CC1101 TX buffer position 151 | i++; 152 | }; 153 | 154 | // put NULL at the end of CC transmission buffer 155 | ccsendingbuffer[i] = '\0'; 156 | 157 | // send these data to radio over CC1101 158 | ELECHOUSE_cc1101.SendData(ccsendingbuffer); 159 | 160 | // blink LED RX - only for Arduino Pro Micro 161 | digitalWrite(RXLED, HIGH); // set the RX LED OFF 162 | 163 | }; 164 | 165 | } // end of main LOOP 166 | -------------------------------------------------------------------------------- /cc1101-radio-chat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcore1976/cc1101-arduino-radio-communicator/b70f304171b07450f5d169766e2e9f826e26199c/cc1101-radio-chat.png --------------------------------------------------------------------------------