买了10个SI24R01,想做点好玩的用,但是怕用的时候才发现模块有问题,于是到处找测试方法,看了看论坛的帖子,挨个试了一次都测试不通,于是通过Google找到了一个可以在Arduino UNO,Leonardo,Pro Micro,Nano测试的方法。
Arduino编译器版本1.6.7
源地址:https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
库文件下载地址:https://github.com/TMRh20/RF24
1 – GND
2 – VCC 3.3V !!! NOT 5V
3 – CE to Arduino pin 9 (Pro Micro 9)
4 – CSN to Arduino pin 10 (Pro Micro 10)
5 – SCK to Arduino pin 13 (Pro Micro 15)
6 – MOSI to Arduino pin 11 (Pro Micro 16)
7 – MISO to Arduino pin 12 (Pro Micro 14)
一个XY摇杆或者两个10K电阻
GND to Arduino GND
VCC to Arduino +5V
X Pot to Arduino A0 (或者10K电阻接地)
Y Pot to Arduino A1 (或者10K电阻接地)
发送端程序:
- YourDuinoStarter Example: nRF24L01 Transmit Joystick values
- WHAT IT DOES: Reads Analog values on A0, A1 and transmits
them over a nRF24L01 Radio Link to another transceiver. - SEE the comments after “//” on each line below
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
- WHAT IT DOES: Reads Analog values on A0, A1 and transmits
1 – GND
2 – VCC 3.3V !!! NOT 5V
3 – CE to Arduino pin 9
4 – CSN to Arduino pin 10
5 – SCK to Arduino pin 13
6 – MOSI to Arduino pin 11
7 – MISO to Arduino pin 12
8 – UNUSED
- Analog Joystick or two 10K potentiometers:
GND to Arduino GND
VCC to Arduino +5V
X Pot to Arduino A0
Y Pot to Arduino A1
- V1.00 11/26/13
Based on examples at http://www.bajdi.com/
Questions: [email protected] */ /-----( Import needed libraries )-----/ include include include /-----( Declare Constants and Pin Numbers )-----/ define CE_PIN 9 define CSN_PIN 10 define JOYSTICK_X A0 define JOYSTICK_Y A1 // NOTE: the "LL" at the end of the constant is "LongLong" type const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe /-----( Declare objects )-----/ RF24 radio(CE_PIN, CSN_PIN); // Create a Radio /-----( Declare Variables )-----/ int joystick[2]; // 2 element array holding Joystick readings void setup() / SETUP: RUNS ONCE **/ { Serial.begin(9600); radio.begin(); radio.openWritingPipe(pipe); }//--(end setup )--- void loop() / LOOP: RUNS CONSTANTLY **/ { joystick[0] = analogRead(JOYSTICK_X); joystick[1] = analogRead(JOYSTICK_Y); radio.write( joystick, sizeof(joystick) ); }//--(end main loop )--- /-----( Declare User-written Functions )-----/ //NONE //( THE END )** 接收端程序: /* YourDuinoStarter Example: nRF24L01 Receive Joystick values
-
WHAT IT DOES: Receives data from another transceiver with 2 Analog values from a Joystick or 2 Potentiometers
Displays received values on Serial Monitor
-
SEE the comments after "//" on each line below
-
CONNECTIONS: nRF24L01 Modules See: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
1 - GND 2 - VCC 3.3V !!! NOT 5V 3 - CE to Arduino pin 9 4 - CSN to Arduino pin 10 5 - SCK to Arduino pin 13 6 - MOSI to Arduino pin 11 7 - MISO to Arduino pin 12 8 - UNUSED
-
V1.00 11/26/13 Based on examples at http://www.bajdi.com/
Questions: [email protected] */ /-----( Import needed libraries )-----/ include include include /-----( Declare Constants and Pin Numbers )-----/ define CE_PIN 9 define CSN_PIN 10 // NOTE: the "LL" at the end of the constant is "LongLong" type const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe /-----( Declare objects )-----/ RF24 radio(CE_PIN, CSN_PIN); // Create a Radio /-----( Declare Variables )-----/ int joystick[2]; // 2 element array holding Joystick readings void setup() / SETUP: RUNS ONCE **/ { Serial.begin(9600); delay(1000); Serial.println("Nrf24L01 Receiver Starting"); radio.begin(); radio.openReadingPipe(1,pipe); radio.startListening();; }//--(end setup )--- void loop() / LOOP: RUNS CONSTANTLY **/ { if ( radio.available() ) {// Read the data payload until we've received everything bool done = false; while (!done) { // Fetch the data payload done = radio.read( joystick, sizeof(joystick) ); Serial.print("X = "); Serial.print(joystick[0]); Serial.print(" Y = "); Serial.println(joystick[1]); }
} else {Serial.println("No radio available");
} }//--(end main loop )--- /-----( Declare User-written Functions )-----/ //NONE //( THE END )**