Il 0% ha trovato utile questo documento (0 voti)
2 visualizzazioni

Arduino CC1101

Caricato da

suonodimarte
Copyright
© © All Rights Reserved
Formati disponibili
Scarica in formato PDF, TXT o leggi online su Scribd
Il 0% ha trovato utile questo documento (0 voti)
2 visualizzazioni

Arduino CC1101

Caricato da

suonodimarte
Copyright
© © All Rights Reserved
Formati disponibili
Scarica in formato PDF, TXT o leggi online su Scribd
Sei sulla pagina 1/ 8

Arduino e CC1101

Componenti:
- Arduino Uno
- CC1101 (Versione 433MHz SMA)

(https://it.aliexpress.com/item/1005002603656188.html?
spm=a2g0o.productlist.main.1.16d92475n5gcXU&algo_pvid=212b89da-fccd-47b5-bdef-
24dd5337a1bc&algo_exp_id=212b89da-fccd-47b5-bdef-24dd5337a1bc-0&pdp_ext_f=%7B
%22sku_id%22%3A%2212000021352867203%22%7D&pdp_npi=2%40dis%21EUR
%212.06%211.79%21%21%21%21%21%402100b0d116728307801401963d073f
%2112000021352867203%21sea&curPageLogUid=Npyq8tiO0wEn)

E’ stata utilizzata la seguente libreria:


https://github.com/LSatan/SmartRC-CC1101-Driver-Lib

Step 1 – Collegamenti

ATTENZIONE: Esistono varie versioni del CC1101, 10 pin e 8 pin

Versione 10 pin

Pinout versione 8 pin


ARDUINO CC1101
D6 GDO0
D2 GDO2
D13 SCK
3.3V VCC
D11 MOSI
D12 MISO
D10 CSN
GND GND

Step 2 – Librerie
Le librerie utilizzate sono 2:

1) https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
- E’ necessario scaricare la libreria da github e importare come file zip

2) RCSwitch

Installabile tramite il Gestore delle librerie di Arduino IDE.


Step 3 – Script

Vi sono 2 script principali: Ricevitore (Rx.ino) e Trasmettitore (Tx.ino)

I) Script ricevitore

#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>

int pin;

RCSwitch mySwitch = RCSwitch();

void setup() {
Serial.begin(9600);

pin = 0;

if (ELECHOUSE_cc1101.getCC1101()){
Serial.println("Connection OK");
}else{
Serial.println("Connection Error");
}

ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(433.92);

mySwitch.enableReceive(pin);

ELECHOUSE_cc1101.SetRx();
}

void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(),
mySwitch.getReceivedDelay(),
mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}
Script Rx.ino

Per funzionare correttamente lo script del ricevitore ha bisogno dello script output.ino, che deve
essere posizionato all’interno della stessa cartella di Rx.ino

I’) Script output

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;
}
Script output.ino

ATTENZIONE
Se per caso non dovesse funzionare, è necessario modificare il file
ELECHOUSE_CC1101_SRC_DRV.cpp, in Ubuntu si trova nel percorso
/home/nomeUtente/Arduino/libraries/SmartRC-CC1101-Driver-Lib-master/

Bisognerà modificare il metodo setSpi e cambiarlo da:


void ELECHOUSE_CC1101::setSpi(void){
if (spi == 0){
#if defined __AVR_ATmega168__ || defined __AVR_ATmega328P__
SCK_PIN = 13; MISO_PIN = 12; MOSI_PIN = 11; SS_PIN = 10;
#elif defined __AVR_ATmega1280__ || defined __AVR_ATmega2560__
SCK_PIN = 52; MISO_PIN = 50; MOSI_PIN = 51; SS_PIN = 53;
#elif ESP8266
SCK_PIN = 14; MISO_PIN = 12; MOSI_PIN = 13; SS_PIN = 15;
#elif ESP32
SCK_PIN = 18; MISO_PIN = 19; MOSI_PIN = 23; SS_PIN = 5;
#else
SCK_PIN = 13; MISO_PIN = 12; MOSI_PIN = 11; SS_PIN = 10;
#endif
}
}
a:
void ELECHOUSE_CC1101::setSpi(void){
SCK_PIN = 13; MISO_PIN = 12; MOSI_PIN = 11; SS_PIN = 10;
}
Esempio monitor seriale del BruteForce NICE 12bit 433

II) Script trasmettitore

#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <RCSwitch.h>

int pin;

RCSwitch mySwitch = RCSwitch();

void setup() {
Serial.begin(9600);
while(!Serial);

pin = 6;

if (ELECHOUSE_cc1101.getCC1101()){
Serial.println("Connection OK");
}else{
Serial.println("Connection Error");
}

ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(433.92);

mySwitch.enableTransmit(pin);

ELECHOUSE_cc1101.SetTx();

mySwitch.setProtocol(INSERIRE_PROTOCOLLO);
mySwitch.setPulseLength(INSERIRE_PULSELENGHT);
}

void loop() {

/* Binary code */
mySwitch.send("INSERIRE_BIT");

delay(20000);
}

Script Tx.ino

Bisognerà, infine, inserire in mySwitch.send("INSERIRE_BIT") la stringa binaria che vogliamo


trasmettere.

Inoltre, è consigliato inserire nel setup i seguenti 2 parametri opzionali ottenuti tramite lo script
ricevitore:

mySwitch.setProtocol(INSERIRE_PROTOCOLLO);
mySwitch.setPulseLength(INSERIRE_PULSELENGHT);

Per quando riguarda il send è possibile utilizzare vari metodi di trasmissione, sotto sono riportati tre
diversi esempi:
mySwitch.send(5393, 24); /* Decimal code */
mySwitch.send("000000000001010100010001"); /* Binary code */
mySwitch.sendTriState("00000FFF0F0F"); /* Tri-state code */

QUESTA GUIDA E' SOLO A SCOPO INFORMATIVO NON MI ASSUMO NESSUNA RESPONSABILITÀ SU CIO' CHE FARETE E SUI
DANNI CHE POTRESTE CAUSARE!!!

Potrebbero piacerti anche