Commit c51049de authored by TMRh20's avatar TMRh20

Replace old examples with the current ones for RPi

Accidentally copied old RPi examples on last commit (code merge)
parent 85038040
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include "../RF24.h" #include <RF24/RF24.h>
using namespace std; using namespace std;
...@@ -50,7 +50,7 @@ const uint64_t pipes[6] = ...@@ -50,7 +50,7 @@ const uint64_t pipes[6] =
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
int main(int argc, char** argv) int main(int argc, char** argv)
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include "../RF24.h" #include <RF24/RF24.h>
using namespace std; using namespace std;
...@@ -42,7 +42,7 @@ using namespace std; ...@@ -42,7 +42,7 @@ using namespace std;
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// //
......
...@@ -23,7 +23,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library ...@@ -23,7 +23,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "./RF24.h" #include <RF24/RF24.h>
using namespace std; using namespace std;
// //
...@@ -38,19 +38,22 @@ using namespace std; ...@@ -38,19 +38,22 @@ using namespace std;
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// NEW: Setup for RPi B+
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; const uint8_t pipes[][6] = {"1Node","2Node"};
//const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = true, role_pong_back = false;
bool role = role_pong_back;
// Print preamble: // Print preamble:
printf("RF24/examples/pingtest/\n"); printf("RF24/examples/pingtest/\n");
...@@ -60,7 +63,6 @@ int main(int argc, char** argv){ ...@@ -60,7 +63,6 @@ int main(int argc, char** argv){
// optionally, increase the delay between retries & # of retries // optionally, increase the delay between retries & # of retries
radio.setRetries(15,15); radio.setRetries(15,15);
// Dump the configuration of the rf unit for debugging // Dump the configuration of the rf unit for debugging
radio.printDetails(); radio.printDetails();
...@@ -94,7 +96,7 @@ int main(int argc, char** argv){ ...@@ -94,7 +96,7 @@ int main(int argc, char** argv){
radio.startListening(); radio.startListening();
} }
// forever loop // forever loop
while (1) while (1)
{ {
...@@ -120,8 +122,6 @@ int main(int argc, char** argv){ ...@@ -120,8 +122,6 @@ int main(int argc, char** argv){
unsigned long started_waiting_at = millis(); unsigned long started_waiting_at = millis();
bool timeout = false; bool timeout = false;
while ( ! radio.available() && ! timeout ) { while ( ! radio.available() && ! timeout ) {
// by bcatalin » Thu Feb 14, 2013 11:26 am
//delay(5); //add a small delay to let radio.available to check payload
if (millis() - started_waiting_at > 200 ) if (millis() - started_waiting_at > 200 )
timeout = true; timeout = true;
} }
...@@ -143,7 +143,8 @@ int main(int argc, char** argv){ ...@@ -143,7 +143,8 @@ int main(int argc, char** argv){
} }
// Try again 1s later // Try again 1s later
// delay(1000); // delay(1000);
sleep(1); sleep(1);
} }
...@@ -154,9 +155,10 @@ int main(int argc, char** argv){ ...@@ -154,9 +155,10 @@ int main(int argc, char** argv){
if ( role == role_pong_back ) if ( role == role_pong_back )
{ {
// if there is data ready // if there is data ready
//printf("Check available...\n"); //printf("Check available...\n");
//delay(3);
if ( radio.available() ) if ( radio.available() )
{ {
// Dump the payloads until we've gotten everything // Dump the payloads until we've gotten everything
...@@ -164,22 +166,25 @@ int main(int argc, char** argv){ ...@@ -164,22 +166,25 @@ int main(int argc, char** argv){
// Fetch the payload, and see if this was the last one. // Fetch the payload, and see if this was the last one.
radio.read( &got_time, sizeof(unsigned long) ); while(radio.available()){
radio.read( &got_time, sizeof(unsigned long) );
}
radio.stopListening(); radio.stopListening();
//delay(1);
// Seem to need a delay, or the RPi is too quick
radio.write( &got_time, sizeof(unsigned long) ); radio.write( &got_time, sizeof(unsigned long) );
//delay(1);
// Now, resume listening so we catch the next packets. // Now, resume listening so we catch the next packets.
radio.startListening(); radio.startListening();
//delay(1);
// Spew it // Spew it
printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time); printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time);
delay(925); //Delay after payload responded to, minimize RPi CPU time
} }
//delay(5);
} }
} // forever loop } // forever loop
return 0; return 0;
......
...@@ -17,7 +17,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library ...@@ -17,7 +17,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "./RF24.h" #include <RF24/RF24.h>
using namespace std; using namespace std;
...@@ -28,17 +28,20 @@ using namespace std; ...@@ -28,17 +28,20 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed // CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ); //RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS1, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz // NEW: Setup for RPi B+
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; const uint8_t addresses[][6] = {"1Node","2Node"};
bool role_ping_out = 1, role_pong_back = 0, role = 0; bool role_ping_out = 1, role_pong_back = 0, role = 0;
...@@ -48,14 +51,12 @@ uint8_t counter = 1; // ...@@ -48,14 +51,12 @@ uint8_t counter = 1; //
int main(int argc, char** argv){ int main(int argc, char** argv){
printf("RF24/examples/gettingstarted_call_response\n"); printf("RPi/RF24/examples/gettingstarted_call_response\n");
radio.begin(); radio.begin();
radio.setAutoAck(1); // Ensure autoACK is enabled radio.setAutoAck(1); // Ensure autoACK is enabled
radio.enableAckPayload(); // Allow optional ack payloads radio.enableAckPayload(); // Allow optional ack payloads
radio.setRetries(1,15); // Smallest time between retries, max no. of retries radio.setRetries(1,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.setPayloadSize(1); // Here we are sending 1-byte payloads to test the call-response speed
//radio.powerUp();
radio.printDetails(); // Dump the configuration of the rf unit for debugging radio.printDetails(); // Dump the configuration of the rf unit for debugging
...@@ -76,9 +77,8 @@ int main(int argc, char** argv){ ...@@ -76,9 +77,8 @@ int main(int argc, char** argv){
} }
} }
/***********************************/ /***********************************/
// This simple sketch opens two pipes for these two nodes to communicate // This opens two pipes for these two nodes to communicate
// back and forth. // back and forth.
if ( role == role_ping_out ) { if ( role == role_ping_out ) {
radio.openWritingPipe(addresses[0]); radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]); radio.openReadingPipe(1,addresses[1]);
...@@ -96,7 +96,7 @@ while (1){ ...@@ -96,7 +96,7 @@ while (1){
if (role == role_ping_out){ // Radio is in ping mode if (role == role_ping_out){ // Radio is in ping mode
uint8_t gotByte; // Initialize a variable for the incoming response uint8_t gotByte; // Initialize a variable for the incoming response
radio.stopListening(); // First, stop listening so we can talk. radio.stopListening(); // First, stop listening so we can talk.
printf("Now sending %d as payload. ",counter); // Use a simple byte counter as payload printf("Now sending %d as payload. ",counter); // Use a simple byte counter as payload
...@@ -116,18 +116,22 @@ while (1){ ...@@ -116,18 +116,22 @@ while (1){
}else{ printf("Sending failed.\n\r"); } // If no ack response, sending failed }else{ printf("Sending failed.\n\r"); } // If no ack response, sending failed
sleep(1); // Try again later sleep(1); // Try again later
//delay(250);
} }
/****************** Pong Back Role ***************************/ /****************** Pong Back Role ***************************/
if ( role == role_pong_back ) { if ( role == role_pong_back ) {
uint8_t pipeNo, gotByte; // Declare variables for the pipe and the byte received uint8_t pipeNo, gotByte; // Declare variables for the pipe and the byte received
while( radio.available(&pipeNo)){ // Read all available payloads if( radio.available(&pipeNo)){ // Read all available payloads
radio.flush_tx(); // Clear any unused ACK payloads
radio.read( &gotByte, 1 ); radio.read( &gotByte, 1 );
// Since this is a call-response. Respond directly with an ack payload. // Since this is a call-response. Respond directly with an ack payload.
// Ack payloads are much more efficient than switching to transmit mode to respond to a call // Ack payloads are much more efficient than switching to transmit mode to respond to a call
radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads. radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads.
printf("Sent response %d \n\r", gotByte); printf("Sent response %d \n\r", gotByte);
delay(900); //Delay after a response to minimize CPU usage on RPi
//Expects a payload every second
} }
} }
......
...@@ -28,6 +28,9 @@ using namespace std; ...@@ -28,6 +28,9 @@ using namespace std;
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// NEW: Setup for RPi B+
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
...@@ -35,8 +38,7 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -35,8 +38,7 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
const int min_payload_size = 4; const int min_payload_size = 4;
const int max_payload_size = 32; const int max_payload_size = 32;
...@@ -47,6 +49,8 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating ...@@ -47,6 +49,8 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble: // Print preamble:
printf("RF24/examples/pingpair_dyn/\n"); printf("RF24/examples/pingpair_dyn/\n");
......
...@@ -16,7 +16,7 @@ TMRh20 2014 ...@@ -16,7 +16,7 @@ TMRh20 2014
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "./RF24.h" #include <RF24/RF24.h>
using namespace std; using namespace std;
...@@ -32,6 +32,9 @@ using namespace std; ...@@ -32,6 +32,9 @@ using namespace std;
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// NEW: Setup for RPi B+
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
...@@ -40,13 +43,14 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -40,13 +43,14 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
uint8_t data[32]; uint8_t data[32];
unsigned long startTime, stopTime, counter, rxTimer=0; unsigned long startTime, stopTime, counter, rxTimer=0;
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble: // Print preamble:
...@@ -55,9 +59,9 @@ int main(int argc, char** argv){ ...@@ -55,9 +59,9 @@ int main(int argc, char** argv){
radio.begin(); // Setup and configure rf radio radio.begin(); // Setup and configure rf radio
radio.setChannel(1); radio.setChannel(1);
radio.setPALevel(RF24_PA_MAX); radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS); radio.setDataRate(RF24_1MBPS);
radio.setAutoAck(1); // Ensure autoACK is enabled radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
radio.setCRCLength(RF24_CRC_8); radio.setCRCLength(RF24_CRC_8);
radio.printDetails(); radio.printDetails();
/********* Role chooser ***********/ /********* Role chooser ***********/
...@@ -89,7 +93,7 @@ int main(int argc, char** argv){ ...@@ -89,7 +93,7 @@ int main(int argc, char** argv){
for(int i=0; i<32; i++){ for(int i=0; i<32; i++){
data[i] = rand() % 255; //Load the buffer with random data data[i] = rand() % 255; //Load the buffer with random data
} }
// forever loop // forever loop
...@@ -99,16 +103,24 @@ int main(int argc, char** argv){ ...@@ -99,16 +103,24 @@ int main(int argc, char** argv){
sleep(2); sleep(2);
printf("Initiating Basic Data Transfer\n\r"); printf("Initiating Basic Data Transfer\n\r");
long int cycles = 10000; //Change this to a higher or lower number. long int cycles = 10000; //Change this to a higher or lower number.
// unsigned long pauseTime = millis(); //Uncomment if autoAck == 1 ( NOACK )
startTime = millis(); startTime = millis();
for(int i=0; i<cycles; i++){ //Loop through a number of cycles for(int i=0; i<cycles; i++){ //Loop through a number of cycles
data[0] = i; //Change the first byte of the payload for identification data[0] = i; //Change the first byte of the payload for identification
if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers
counter++; //Keep count of failed payloads counter++; //Keep count of failed payloads
} }
}
//This is only required when NO ACK ( enableAutoAck(0) ) payloads are used
/* if(millis() - pauseTime > 3){ // Need to drop out of TX mode every 4ms if sending a steady stream of multicast data
pauseTime = millis();
radio.txStandBy(); // This gives the PLL time to sync back up
}
*/
}
stopTime = millis(); stopTime = millis();
if(!radio.txStandBy()){ counter+=3; } if(!radio.txStandBy()){ counter+=3; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment