Questo il codice per Arduino (nel mio caso Mini Pro a 3,3V) con alcune mie modifiche:
#include <SPI.h>
#include <RF24.h>
#include "nRF24L01.h"
#define BAUDE_RATE 57600
#define LEDPIN 13
byte ledState = LOW;
unsigned long previousMillis = 0;
RF24 radio(9,10); // CE pin and CSN pin
unsigned char ch;
void setup(void)
{ delay(1000);
Serial.begin(BAUDE_RATE);
//the usb dongle works by default at 1Mbit, so this can be any speed
radio.begin();
//wi-fi channel (frequency) and the address and the speed those are the default values, can be modified by user
// To modify them send the following text to the terminal on which the usb dongle is: AT+SET=xxyyabcdefghij
// xx is the channel
// yy is the RF_SETUP REGISTER on nRF24l01 (on dongle there is BK2423, but works almost the same)
// It sets the dB power level and the speed (default value 0x07 = 1Mhz, 0dB (maximum value));
// ijghefcdab is the port (note that is in the reverse byte order)
// all values are in hexadecimal
// Example: to change to the default values use: AT+SET=28073443101001
radio.setChannel(0x28);
radio.openReadingPipe(1,0x0110104334LL); //default value when the usb wifi dongle is plugged (can be changed by user)
radio.openWritingPipe(0x0110104334LL); //default value when the usb wifi dongle is plugged (can be changed by user)
radio.setDataRate(RF24_1MBPS);
//setPayload,enabledynamic,setcrc. These are hardcoded the same on usb wifi dongle. Cannot be changed by the user
radio.setPayloadSize(32);
radio.enableDynamicPayloads();
radio.setCRCLength(RF24_CRC_16);
radio.startListening();
radio.printDetails(); //print the configuration
pinMode(LEDPIN,OUTPUT);
}
void loop(void)
{ unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
ledState = (ledState==LOW ? HIGH : LOW);
digitalWrite(LEDPIN, ledState);
}
if ( radio.available() )
{ radio.read( &ch, 1 ); // const void* buf, uint8_t len
Serial.print((char)ch);
radio.stopListening();
//delay(5);
radio.write(&ch,1); // const void* buf, uint8_t len
radio.startListening(); //flush the rx buffer
}
}
Ho anche provato 2 dongle tra 2 PC. Con due dongle su due PC diversi, e con un terminal seriale si comunica subito tra i due PC.
Dimenticavo: tra Arduino e PC ho provato solo usando cavo USB da 6 mt verso il Mini Pro (collegato allo stesso PC), quindi la distanza era "minima", 6 metri e dietro ad un muro (intramezzo) e non ho provato distanze lunghe.
Io ho preso quella cinese con scritto sopra AI.
Dai cinesi scrivono solo questo (quindi poche info):
One AT order
e.g: AT+SET=40270102030405
40 is stand for 0X40, which means physical frequency
---- You can set 126 0X40MHZ on the basis of 2400MHZ
27 is stand for SETUP register,
which is use for setting transmit frequency and transmit-receive Baud rate.
01 02 03 04 05 is stand for 5 software physical address.
Il registro SETUP sarà RF_SETUP? Se si però perché ha il valore 0x27 visto che il primo bit è riservato e deve essere zero? Perchè dice che si può impostare la frequenza mentre è il registro RF_CH e non RF_SETUP negli nrf24?
In teoria il costruttore è AI-THINKER, se ne parla nel thread di ESP8266, ma io il sito cinese di www.AI-THINKER.com non riesco a visualizzarlo, qualcuno invece riesce "spacciandosi" per olandese.
Magari li si trovano info.
/wi-fi channel (frequency) and the address and the speed
// those are the default values, can be modified by user
//
// To modify them send the following text to the terminal on which the
usb dongle is: AT+SET=xxyyabcdefghij
// xx is the channel
// yy is the RF_SETUP REGISTER on nRF24l01 (on dongle there is BK2423,
but works almost the same)
// It sets the dB power level and the speed (default value 0x07
= 1Mhz, 0dB (maximum value));
// ijghefcdab - the port (note that is in the reverse byte order)
// all values are in hexadecimal
// Example: to change to the default values use: AT+SET=28073443101001
//
Il Crazyradio è sicuro più serio, l'unica grande pecca però è un case e la difficoltà di programmazione visto che usa un Soc. Mi sa che rimango con la mia soluzione (micro usb + nrf24l01+) visto che gli ho fatto pure un case, peccato che è venuto un pò più grosso di quello dei cinesi