ผมงงเด้ งงเด้ ครับ
อย่างเช่นบน Board ผมต่อ CE=9, CSN=10
แต่เขียนโค๊ด RF24 radio(7,8);
ขึ้นว่าส่งได้เฉยเลย
แต่ถ้า Board ผมต่อ CE=9, CSN=10
แต่เขียนโค๊ด RF24 radio(9, 10);
ขึ้นว่าส่งไม่ได้
งงครับ
ผมใช้ arduino pro mini 3.3v คร่อม gnd and vcc ด้วย 10uF และ 0.1uF เข้า nrf24l01
/*
// March 2014 - TMRh20 - Updated along with High Speed RF24 Library fork
// Parts derived from examples by J. Coliz <maniacbug@ymail.com>
*/
/**
* Example for efficient call-response using ack-payloads
*
* This example continues to make use of all the normal functionality of the radios including
* the auto-ack and auto-retry features, but allows ack-payloads to be written optionally as well.
* This allows very fast call-response communication, with the responding radio never having to
* switch out of Primary Receiver mode to send back a payload, but having the option to if wanting
* to initiate communication instead of respond to a commmunication.
*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
// Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8
RF24 radio(7,8);
// Topology
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate.
// Role management: Set up role. This sketch uses the same software for all the nodes
// in this system. Doing so greatly simplifies testing.
typedef enum { role_ping_out = 1, role_pong_back } role_e; // The various roles supported by this sketch
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; // The debug-friendly names of those roles
role_e role = role_pong_back; // The role of the current running sketch
// A single byte to keep track of the data being sent back and forth
byte counter = 1;
void setup(){
Serial.begin(115200);
printf_begin();
Serial.print(F("\n\rRF24/examples/pingpair_ack/\n\rROLE: "));
Serial.println(role_friendly_name[role]);
Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
// Setup and configure rf radio
radio.begin();
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.enableAckPayload(); // Allow optional ack payloads
radio.setRetries(0,15); // Smallest time between retries, max no. of retries
radio.setPayloadSize(1); // Here we are sending 1-byte payloads to test the call-response speed
radio.openWritingPipe(pipes[1]); // Both radios listen on the same pipes by default, and switch when writing
radio.openReadingPipe(1,pipes[0]);
radio.startListening(); // Start listening
radio.printDetails(); // Dump the configuration of the rf unit for debugging
}
void loop(void) {
if (role == role_ping_out){
radio.stopListening(); // First, stop listening so we can talk.
printf("Now sending %d as payload. ",counter);
byte gotByte;
unsigned long time = micros(); // Take the time, and send it. This will block until complete
//Called when STANDBY-I mode is engaged (User is finished sending)
if (!radio.write( &counter, 1 )){
Serial.println(F("failed."));
}else{
if(!radio.available()){
Serial.println(F("Blank Payload Received."));
}else{
while(radio.available() ){
unsigned long tim = micros();
radio.read( &gotByte, 1 );
printf("Got response %d, round-trip delay: %lu microseconds\n\r",gotByte,tim-time);
counter++;
}
}
}
// Try again later
delay(1000);
}
// Pong back role. Receive each packet, dump it out, and send it back
if ( role == role_pong_back ) {
byte pipeNo;
byte gotByte; // Dump the payloads until we've gotten everything
while( radio.available(&pipeNo)){
radio.read( &gotByte, 1 );
radio.writeAckPayload(pipeNo,&gotByte, 1 );
}
}
// Change roles
if ( Serial.available() )
{
char c = toupper(Serial.read());
if ( c == 'T' && role == role_pong_back )
{
Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
role = role_ping_out; // Become the primary transmitter (ping out)
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
}
else if ( c == 'R' && role == role_ping_out )
{
Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
role = role_pong_back; // Become the primary receiver (pong back)
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.startListening();
}
}
}
Now sending 57 as payload. Got response 255, round-trip delay: 4864 microseconds
Got response 255, round-trip delay: 6672 microseconds
Got response 255, round-trip delay: 9176 microseconds
Now sending 60 as payload. Got response 255, round-trip delay: 4792 microseconds
Got response 255, round-trip delay: 6600 microseconds
Got response 255, round-trip delay: 9104 microseconds
Now sending 63 as payload. Got response 255, round-trip delay: 4696 microseconds
Got response 255, round-trip delay: 6504 microseconds
Got response 255, round-trip delay: 9008 microseconds
Now sending 66 as payload. Got response 255, round-trip delay: 4584 microseconds
Got response 255, round-trip delay: 6384 microseconds
Got response 255, round-trip delay: 8896 microseconds
Now sending 69 as payload. Got response 255, round-trip delay: 4480 microseconds
Got response 255, round-trip delay: 6288 microseconds
Got response 255, round-trip delay: 8792 microseconds
Now sending 72 as payload. Got response 255, round-trip delay: 4400 microseconds
Got response 255, round-trip delay: 6208 microseconds
Got response 255, round-trip delay: 8712 microseconds
Now sending 75 as payload. Got response 255, round-trip delay: 4368 microseconds
Got response 255, round-trip delay: 6160 microseconds
Got response 255, round-trip delay: 8680 microseconds
จากข้อมูล ขา CE กับ CNS ใช้ขาไหนก็ได้ครับ
http://www.deviceplus.com/how-tos/arduino-guide/nrf24l01-rf-module-tutorial/
The CE and the CSN pins can be connected to any output GPIO pin on the Arduino. In software, they are specified appropriately when the SPI communication is initialized.
อาจจะมีผิดบางที่ ต้องลองดีบั๊กดู หรือลองใช้ไลบารีตัวอื่น
มีไลบารี่ คลิป และโคดตัวอย่าง nrf24L01 ในหน้าบทความ ลองดูในหน้าบทความประกอบครับ
โวลต์ที่ทนได้ มากกว่าแหล่งจ่ายไฟที่จ่ายก็ใช้ได้ เช่น ถ้าใช้ไฟ 3.3V ตัวเก็บประจุทนแรงดันมากกว่า 3.3V ก็ใช้ได้ครับ