smartrc-cc1101-driver-lib

repository·master·Indexed 20 days ago

https://github.com/lsatan/smartrc-cc1101-driver-lib

A high-precision, object-oriented driver library for the SmartRC CC1101 transceiver designed for Arduino, ESP8266, and ESP32 platforms. It features minimal RAM usage, support for custom SPI pin mapping on ESP32 variants, and a multi-module architecture introduced in V3.0.0. The library includes tools for calibrating hardware frequency offsets using the setClb function.

Tokens
1K
Snippets
4
Records
5
Agent score
20%

What's inside smartrc-cc1101-driver-lib

  1. How multi-module setups work in V3.0.0

    master

    In V3.0.0, the library moved to a fully object-oriented architecture. Instead of using global configuration functions like setModul(), addSpiPin(), or addGDO(), you should simply instantiate multiple SmartRC_CC1101 objects. This allows you to manage multiple CC1101 modules (e.g., for a Dual-Band Gateway) independently.

    SmartRC_CC1101 radio1;
    SmartRC_CC1101 radio2;
  2. Configure custom SPI pins

    master

    If you need to use pins other than the defaults, use the setSpiPin() function.

    Important: You must call setSpiPin() before calling radio.Init().

    Platform Behavior:

    • ESP32, ESP32-S2 & ESP32-S3: You can map the SPI bus to almost any available GPIO using this function. This is mandatory for ESP32-S2 and ESP32-S3 variants as their default hardware SPI pins differ from the classic ESP32.
    • Arduino / AVR & ARM Boards: Hardware SPI lines (SCK, MISO, MOSI) are hardwired and cannot be changed. On these platforms, you can only change the SS / CS (Chip Select) pin. Passing different pins for SCK/MISO/MOSI on these boards will be ignored or fall back to hardware defaults.
    // Example for setting custom SPI pins
    radio.setSpiPin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
    radio.Init();
  3. Calibrate CC1101 hardware frequency offset

    master

    Inexpensive CC1101 modules often have crystal oscillator deviations (±20 ppm to ±30 ppm), causing frequency shifts. To fix this, use the Band Calibration Tool found in the examples/ folder.

    Using an SDR (Software Defined Radio) and the Serial Monitor, the tool measures frequency limits and generates ready-to-use C++ code using myRadio.setClb(...) to permanently tune your specific hardware module.

  4. Quick Start with SmartRC CC1101

    master

    To get started with the CC1101 driver, include the SPI.h and SmartRC_CC1101.h libraries, instantiate a SmartRC_CC1101 object, and initialize it using radio.Init(). You can then set the frequency with setMHZ() and enter receive mode with SetRx(). Use getCC1101() to verify the hardware is connected and CheckReceiveFlag() in your loop to detect incoming data.

    #include <SPI.h>
    #include "SmartRC_CC1101.h"
    
    // Create an instance
    SmartRC_CC1101 radio;
    
    void setup() {
        Serial.begin(115200);
        radio.Init();
        radio.setMHZ(433.92);
        radio.SetRx();
        
        if(radio.getCC1101()) {
            Serial.println("Hardware found and ready!");
        }
    }
    
    void loop() {
        if (radio.CheckReceiveFlag()) {
            byte buffer[64];
            byte len = radio.ReceiveData(buffer);
            // Process data...
        }
    }
  5. Hardware Wiring Reference

    master

    Standard wiring connections for the CC1101 module on common platforms. Note that VCC must be 3.3V ONLY.

    | **CC1101 Pin** | **Arduino Uno/Nano** | **ESP32 (Default)** | **Description** |
    | ----- | ----- | ----- | ----- |
    | **VCC** | 3.3V | 3.3V | Power Supply (3.3V ONLY!) |
    | **GND** | GND | GND | Ground |
    | **SCK** | Pin 13 | GPIO 18 | SPI Clock |
    | **MISO** | Pin 12 | GPIO 19 | SPI Data Out |
    | **MOSI** | Pin 11 | GPIO 23 | SPI Data In |
    | **CSN / SS** | Pin 10 | GPIO 5 | Chip Select |
    | **GDO0** | Pin 2 | GPIO 2 | Interrupt/Data Out |