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 @@
#include <cstdlib>
#include <iostream>
#include "../RF24.h"
#include <RF24/RF24.h>
using namespace std;
......@@ -50,7 +50,7 @@ const uint64_t pipes[6] =
//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
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)
......
......@@ -25,7 +25,7 @@
#include <cstdlib>
#include <iostream>
#include "../RF24.h"
#include <RF24/RF24.h>
using namespace std;
......@@ -42,7 +42,7 @@ using namespace std;
//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
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
#include <iostream>
#include <sstream>
#include <string>
#include "./RF24.h"
#include <RF24/RF24.h>
using namespace std;
//
......@@ -38,19 +38,22 @@ using namespace std;
// 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);
// 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
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.
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){
bool role_ping_out = true, role_pong_back = false;
bool role = role_pong_back;
// Print preamble:
printf("RF24/examples/pingtest/\n");
......@@ -60,7 +63,6 @@ int main(int argc, char** argv){
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
// Dump the configuration of the rf unit for debugging
radio.printDetails();
......@@ -120,8 +122,6 @@ int main(int argc, char** argv){
unsigned long started_waiting_at = millis();
bool timeout = false;
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 )
timeout = true;
}
......@@ -144,6 +144,7 @@ int main(int argc, char** argv){
// Try again 1s later
// delay(1000);
sleep(1);
}
......@@ -154,9 +155,10 @@ int main(int argc, char** argv){
if ( role == role_pong_back )
{
// if there is data ready
//printf("Check available...\n");
//delay(3);
if ( radio.available() )
{
// Dump the payloads until we've gotten everything
......@@ -164,22 +166,25 @@ int main(int argc, char** argv){
// Fetch the payload, and see if this was the last one.
while(radio.available()){
radio.read( &got_time, sizeof(unsigned long) );
}
radio.stopListening();
//delay(1);
// Seem to need a delay, or the RPi is too quick
radio.write( &got_time, sizeof(unsigned long) );
//delay(1);
// Now, resume listening so we catch the next packets.
radio.startListening();
//delay(1);
// Spew it
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
return 0;
......
......@@ -17,7 +17,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library
#include <iostream>
#include <sstream>
#include <string>
#include "./RF24.h"
#include <RF24/RF24.h>
using namespace std;
......@@ -28,17 +28,20 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed
// 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);
// 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);
// 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;
......@@ -48,14 +51,12 @@ uint8_t counter = 1; //
int main(int argc, char** argv){
printf("RF24/examples/gettingstarted_call_response\n");
printf("RPi/RF24/examples/gettingstarted_call_response\n");
radio.begin();
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.enableAckPayload(); // Allow optional ack payloads
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.powerUp();
radio.printDetails(); // Dump the configuration of the rf unit for debugging
......@@ -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.
if ( role == role_ping_out ) {
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
......@@ -116,18 +116,22 @@ while (1){
}else{ printf("Sending failed.\n\r"); } // If no ack response, sending failed
sleep(1); // Try again later
//delay(250);
}
/****************** Pong Back Role ***************************/
if ( role == role_pong_back ) {
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 );
// 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
radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads.
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;
// 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);
// 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
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.
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 max_payload_size = 32;
......@@ -47,6 +49,8 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating
int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble:
printf("RF24/examples/pingpair_dyn/\n");
......
......@@ -16,7 +16,7 @@ TMRh20 2014
#include <iostream>
#include <sstream>
#include <string>
#include "./RF24.h"
#include <RF24/RF24.h>
using namespace std;
......@@ -32,6 +32,9 @@ using namespace std;
// 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);
// 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
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.
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
uint8_t data[32];
unsigned long startTime, stopTime, counter, rxTimer=0;
int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble:
......@@ -55,7 +59,7 @@ int main(int argc, char** argv){
radio.begin(); // Setup and configure rf radio
radio.setChannel(1);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
radio.setDataRate(RF24_1MBPS);
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
radio.setCRCLength(RF24_CRC_8);
......@@ -101,6 +105,7 @@ int main(int argc, char** argv){
long int cycles = 10000; //Change this to a higher or lower number.
// unsigned long pauseTime = millis(); //Uncomment if autoAck == 1 ( NOACK )
startTime = millis();
for(int i=0; i<cycles; i++){ //Loop through a number of cycles
......@@ -108,6 +113,13 @@ int main(int argc, char** argv){
if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers
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();
......
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