Arduino cc1101 библиотека

Arduino cc1101 библиотека

CC1101 radio example

So, I’ve made a video with some radio modules you could use. In this case we will see the CC1101 radio module with SPI serial communication. See the connections below, download the example code and test if it works. You will need the ELECHOUSE_CC1101 library as well so download that from the links below. You need two modules, an LED and a potentiometer and we will send just one byte of data, 0 to 255 values. The range for this module could be up to 400m abut we need a lot of pins to use this.

PART 1 — The CC1101

Ok, guys let’s move to the CC 11 01 radio module. There are different modules with different frequencies. The frequencies can also be modified. The most popular and also the most used band is the 70 cm band. Again, the module is used via the SPI interface. You might find that the module can not be connected directly to the SPI pins because of the 3.3 Volts operating voltage. And basically this is true, however, during my test I’ve used this with my Arduino and I had no problems. It has a maximum operating speed of 500KB per second and according to the user manual, it could send data up to 500 meters but that depending on the environment, the antenna and baud rate. There are also some small power amplifiers that you could use to increase the transmission power by up to 5 watts. With power amplifiers, you can get over 15 kilometers according to some internet posts I’ve found.

For this module you will need the CC1101 library you will find below in the code link. Make the connenctions for the modules as in the schematic. For breadboard connection you will need a jumper like the one I’ve made with some female and male pins. Download the example code from below and upload those to the Arduinos. You have the transmitter and receiver examples and again, the transmission is working and I can control the LED using radio connection.

PART 2 — Schematic

The schematic is simple but with a lot of pins. We have 2 Arduino NANO and we will use 3.3V from the Arduino in this case. If this doesn’t work, connect an external 3.3V supply and share ground. Anyway, connect the SPI pins and add a potentiometer, and LED and a resistor. Upload the codes below to the transmitter and receiver and read the comments in the code for more. Test if it works and you could change the brightness of the LED using the radio connection.

3.1 Transmitter

Here we have the transmitter code. You will need the ELECHOUSE_CC1101 library for this module so download that from the code link below and install it to the Arduino IDE. Uplaod this code to the Arduino with the potentiometer. Read the comments in the code for more. Copy or download the code from below.

Источник

simonmonk/CC1101_arduino

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A clone of the ELECHOUSE_CC1101 http://www.elechouse.com library updated for Arduino 1.0 plus.

I made the following changes to the original library.

  • Changed imports of WProgram.h to Arduino.h in line with Arduino 1.0+
  • Changed the init method so that you have to set the carrier frequency

Connecting an Arduino to a CC1101

These instructions are for an Arduino Uno.

Arduino CC1101 Notes
GND GND
3.3V VCC
10 CSN/SS Must be level shifted to 3.3V
11 SI/MOSI Must be level shifted to 3.3V
12 SO/MISO
13 SCK Must be level shifted to 3.3V
2 GD0 Signals buffer ready to read

Installing the Library

To install the library into your IDE:

  • click on the Clone or Download button on this Github page and select Download ZIP.
  • Start the Arduino IDE and from the Sketch menu do Sketch->Include Library->Add ZIP Library and select the ZIP you just downloaded.

This is a very easy library to use. You may just wish to try out the examples, that send a text message from one Arduino to another using the Serial Monitor. But for completeness, here it is:

Put this in your setup function.

Put this in your setup function and call again, any time after you have processed a received message.

When a new message arives GD0 on the CC1101 (Arduino pin 2) will be set LOW. You can hook this up to an interrupt or just watch for it in your loop function.

The maximum data size is 64 bits.

ReceiveData requires a buffer of type byte[] and returns the number of bytes contained in the message.

The maximum data size is 64 bits.

SendData requires a buffer of type byte[] and the number of bytes contained in the message.

Источник

SpaceTeddy/CC1101

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

driver library for Ti CC1100 / CC1101.
Contains Lib for Arduino and Raspberry Pi.
Note: Raspi need wiringPi

a compatible and tested library for TI MSP430 is provided by abhra0897.
https://github.com/abhra0897/msp430_cc1101_energia_v2

If you are happy with the library and you want to spend me a beer, please feel free to use the following link. ;)

check cc1101_arduino.h and/or cc1101_raspi.h for Pin description

CC1101 Vdd = 3.3V CC1101 max. digital voltage level = 3.3V (not 5V tolerant)

General description of RF packet

pkt_len = count of bytes which shall transfered over air (rx_addr + tx_addr + payload data)
rx_addr = address of device, which shall receive the message (0x00 = broadcast to all devices)
tx_addr = transmitter or my address. the receiver should know who has sent a message.
payload = 1 to 60 bytes payload data.

TX Bytes example:
-> 0x06 0x03 0x01 0x00 0x01 0x02 0x03

use uint8_t CC1100::begin(volatile uint8_t &My_addr) always as first configuration step. For Arduino devices, this function returns the device address, which was already stored in the Arduino EEPROM.

you should set a unique device address for the transmitter and a unique device address for the receiver. This can be done with void CC1100::set_myaddr(uint8_t addr).

i.E. -> TX = 0x01 ; RX = 0x03

the following modulation modes can be set by void CC1100::set_mode(uint8_t mode). Transmitter and receiver must have the same Mode setting.

ISM frequency band

you can set a frequency operation band by void CC1100::set_ISM(uint8_t ism_freq) to make it compatible with your hardware.

CC1101 RF settings must be stored in the Arduino EEPROM to have maximum flexibility with different mode settings and reduced memory usage. Follow the following steps, how to store the compiled EEPROM file (*.eep) to your Arduino EEPROM. From my experience, you have to repeat this step only, if you have changed the Arduino Version, because the gcc compiler defines the location of the eeprom settings.

  • compile the tx_demo or rx_demo example sketch
  • remember the path of your compiled output data (Arduino *.hex file and *.eep file)
  • use the python eeprom_create.py to generate the eeprom array for the eeprom_write.ino This is needed because the compiler can choose the EEPROM position by its own.
  • usage: ./eeprom_create.py
  • you get an output file with like *.array
  • open that file and copy the array content into the eeprom_write.ino sketch at the correct position
  • compile the eeprom_write.ino sketch
  • upload into to your connected arduino hardware
  • open the Arduino Serial console, set the baudrate to 38400 and restart your arduino hardware
  • type the character w to the input field and press the sent button
  • wait till eeprom is written
  • sent r to verify that eeprom is written.
  • if your EEPROM data is written correct, you can compile and upload the RX_Demo or TX_Demo sketch to that hardware

How to compile Raspi Demo files

be sure first, that you have already wiringPi installed on your Raspberry Pi hardware.

Источник

pkarsy/CC1101_RF

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Arduino library for Texas Instruments CC1101 chip.

  • Works with the latest Arduino IDE and with Platformio IDE (2021-).
  • Works with any SPI bus provided by the platform or with SoftwareSPI. 2 CC1101 modules can be connected to the same ISP bus, only CSN and GDO0(optional) need to be on different MCU pins.
  • Tested to be working with Atmega328(3.3V variants), STM32f103(BluePill both SPI busses) and both arduino cores, esp8266(NodeMCU). It is not using any MCU specific code. It is expected to work after pin tweaking on almost any architecture arduino is ported.
  • The developer chooses directly the exact frequency. This is better than choosing the base frequency and selecting channels. The ISM bands (especially outside US) are very narrow and choosing the right frequency is crusial. It is the duty of the developer however to use the available bandwith efficiently and to comply with the national and international standards about radio transmission.
  • 4800 and 38000 baudrates.
  • Simple interface. Sending packets is a synchronous operation. No callback function (to signal the end of transmission). Most of the time also no need for interrupts/callbacks for packet receive (see below). Maximum packet size is 61 bytes(library limitation).
  • Support for WakeOnRadio. The RF chip (CC1101 in this case) go to sleep and wake up periodically to check for incoming message. The use of WakeOnRadio(WOR) together with MCU sleep can dramatically reduce power consumption, allowing RF projects to run for years using only battery power, and still be able to receive messages. See the wor folder in the examples.
  • Optional GDO0 pin connection. sendPacket and getPacket functions work without relying on the state of the GDO0 pin. However the use of this CC1101 pin is easy (all breakout CC1101 boards have a pin for GDO0) and is needed if we use microcontroller sleep mode or/and WakeOnRadio.
  • Even if one is using the GDO0 pin there is no need for interrupt handler. The reason is that the GDO0 is asserted when a packet is received and stays high until the packet is read. In the case of Sleep/WakeOnRadio an empty interrupt handler is only needed, without the need to alter any flags. This is a big plus. Interrupt driven logic can be tricky and error prone.
  • Based on elechouse library, with many additions.
  • Permissive MIT licence.

Using with Arduino IDE

cd to Arduino Libraries folder (

/Arduino/libraries on Linux)

Using with Platformio

No need to install anything. In platformio.ini just add :

The pins depend on platform and SPI bus. See the examples.

Most of the functionality explained in the examples but here is some code (platformio) :

or if GDO0 is connected, use getPacket only when needed :

Every example is a separate tiny platformio project and can be opened by platformio IDE. The CC1101_RF library will be imported automatically.

Some things to keep in mind :

  • Usually most of the time the module must be in RX. This however depends on the communication schema used.
  • When a packet is received the module goes to IDLE state and we must do a getPacket(buf) as soon as possible in order to be adle to receive more packets. So delay(msec) and generally blocking operations must be avoided in loop(). The communication is half duplex, so a protocol must be implemented, and every module should know when to transmit and when not. The chip’s CCA(Clear Channel Assessment) is enabled of course, but this alone does not guarantee reliable communication.
  • It is very tempting to use SyncWord in order to isolate nearby projects but this is a very bad practice. The role of syncword is for packet detection, NOT FOR PACKET FILTERING. Use setFrequency(freq) and/or setAddress(addr) for filtering and leave the SyncWord as is.
  • To reduce interference to nearby RF modules the functions setPower5dbm() and setPower0dbm() can be used. This also allows the communication in short distances (less than 1m) where the signal is very strong.

Fixing bugs, adding features

  • If you found a bug, and want to report it use the Github Issues

If however you prefer to code:

If you code with platformio, you need to adjust the serial ports inside platformio.ini

Even some seemingly innocent changes in register CC1101 settings can break the library. It is recommended to use a target with debugging support. This can be :

  • A blackmagic probe(or clone) with a STM32 BluePill + vscode + platformio IDE. BMP supports also JTAG so can be used with a lot more platforms than STM32. BMP also supports an auxiliary serial port which can be connected to the target.
  • A ST-link v2 (or clone) can also be used if the target is STM32.

there is a var CC1101_DEBUG which can be enabled by editing the CC1101_RF.cpp file or preferably in platformio.ini

even if you can find multiple unrelated things to fix/improve, please focus on one each time.

Follow some tutorial about contributing to a github project like this one, or any other you may prefer.

Look at the source code. The examples contain comments for the most useful functions.

Capabilities of the chip

CC1101 at 4800bps and 10dbm can penetrate easily 3-4 reinforced concrete floors, or a few hundred meters without obstacles using simple modules with pre-soldered spring antennas. This is more than enough for many projects. Of course LoRa devices can do better but there is no compelling reason to use them if the project does not need such capabilities. Given the lower price, the easier pin connections (at least for the modules found on ebay/aliexpress), and the capability of the same chip to use all sub-GHz ISM bands, means the CC1101 chip is quite useful, despite being more than 10 years old.

Choosing data rate and frequency

Most projects do not require high data rate. for those projects the default (4800bps) is OK.

The frequency selection usually needs more attention. The frequency must be inside one ISM band, if we talk about a project not requiring gevernment permission !

Let’s say we configure the module for 433.2Mhz. The CC1101 chip (all RF chips basically) use a crystal for precise carrier signal generation. If you are not very unlucky the crystall will have 30ppm error or less. The base frequency then, can be 433.187 — 433.213 MHz. Also the modulation of the signal (GFSK with

25KHz deviation in this lib) needs a bandwith. Using the «Carson Bandwith Rule» for 4800bps we have 4.8+2*25=55KHz lets say +/- 28KHz for 98% of the power. So our module can emit signals

  • from 433.187MHz-28KHz=433.159MHz (worst -30ppm sending «0»)
  • up to 433.213MHz + 28KHz = 433.241MHz (worst +30ppm sending «1») Both extremes are well inside the ISM band.

The story does not end here however, the receiver also has a crystal ! And this crystal can have the oposite ppm error than the transmitter. For example :

  • The transmitter sends 433.187MHz — 28KHz = 433.159 (worst -30ppm sending «0»)
  • The receiver listens at 433.213MHz (worst +30ppm).

Consequently the receiver needs a «window» of +/-(433.213-433.159) or +/-54Khz or 108KHz «BWchannel» as CC1101 documentation calls it. This is about the setting in this library (101KHz). Generally is not a good idea to use a larger than needed BWchannel setting, as the chip then collects a lot of noise, and signals from other ISM working devices. For 868 band the required «BWchannel» is somewhat higher but at the moment this lib does not change the setting. RFstudio (TI’s software) has some preconfigured settings with this BWchannel, and they know better. A function tweaking the BWchannel may be added if such a need(reception problems) arises.

The above calculations show that we have to isolate nearby projects with at least

150KHz gap. Probably even 200KHz as RFStudio suggest(channel spacing). For example:

  • one project with 433.2Mhz : radio.begin(433.2e6)
  • another nearby project and isolated (no need for communication) to the first at 433.35MHz : radio.begin(433.35e6)

Even then, expect some disturbance from unrelated nearby devices. For example some garage doors use 433.42MHz +/- unknown ppm

Another consideration is which ISM band to use: Should we choose 433 or 868MHz ? (And there are more) Both seem to be allowed in Europe. Some 868 sub-bands allow 25mW or even 500mW. This is actually not good for us, as CC1101 can transmit only 10mW and the module will compete with higher power modules. Others say that 868 is in fact better, and that 433 is more crowded. Note that the antennas do not perform the same on every frequency. And finally the rules for frequency and power/time allocation are somewhat complex. You have to do your tests to be sure, and read the rules for your country.

About

Arduino library for TI CC1101. Supports the latest Arduino IDE and Platformio. Tested with AVR atmega328, stm32f103, nodeMCU and probably works with a lot more.

Источник

Adblock
detector