Skip to content

Commit

Permalink
Merge pull request #141 from fab672000/master
Browse files Browse the repository at this point in the history
Reduced RAM usage, added a new example, fixed inconsistencies.
  • Loading branch information
Avamander committed Oct 20, 2015
2 parents a045c5a + aab3a52 commit 46ccceb
Show file tree
Hide file tree
Showing 10 changed files with 516 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <SPI.h>
#include "RF24.h"
//#include "printf.h"

/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
Expand All @@ -40,7 +39,7 @@ void setup(){
Serial.begin(115200);
Serial.println(F("RF24/examples/GettingStarted_CallResponse"));
Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
//printf_begin();

// Setup and configure radio

radio.begin();
Expand Down
4 changes: 2 additions & 2 deletions examples/GettingStarted_HandlingData/GettingStarted_HandlingData.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct dataStruct{
void setup() {

Serial.begin(115200);
Serial.println(F("RF24/examples/GettingStarted"));
Serial.println(F("RF24/examples/GettingStarted_HandlingData"));
Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));

radio.begin();
Expand Down Expand Up @@ -131,7 +131,7 @@ if (role == 1) {
radio.startListening(); // Now, resume listening so we catch the next packets.
Serial.print(F("Sent response "));
Serial.print(myData._micros);
Serial.print(" : ");
Serial.print(F(" : "));
Serial.println(myData.value);
}
}
Expand Down
16 changes: 7 additions & 9 deletions examples/Transfer/Transfer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ TMRh20 2014

#include <SPI.h>
#include "RF24.h"
#include "printf.h"

/************* USER Configuration *****************************/
// Hardware configuration
Expand All @@ -34,7 +33,6 @@ bool TX=1,RX=0,role=0;
void setup(void) {

Serial.begin(115200);
printf_begin();

radio.begin(); // Setup and configure rf radio
radio.setChannel(1);
Expand All @@ -50,8 +48,8 @@ void setup(void) {
radio.startListening(); // Start listening
radio.printDetails(); // Dump the configuration of the rf unit for debugging

printf("\n\rRF24/examples/Transfer Rates/\n\r");
printf("*** PRESS 'T' to begin transmitting to the other node\n\r");
Serial.println(F("\n\rRF24/examples/Transfer/"));
Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));

randomSeed(analogRead(0)); //Seed for random number generation

Expand All @@ -68,7 +66,7 @@ void loop(void){

delay(2000);

printf("Initiating Basic Data Transfer\n\r");
Serial.println(F("Initiating Basic Data Transfer"));


unsigned long cycles = 10000; //Change this to a higher or lower number.
Expand Down Expand Up @@ -115,10 +113,10 @@ if(role == RX){
if(millis() - rxTimer > 1000){
rxTimer = millis();
unsigned long numBytes = counter*32;
Serial.print("Rate: ");
Serial.print(F("Rate: "));
//Prevent dividing into 0, which will cause issues over a period of time
Serial.println(numBytes > 0 ? numBytes/1000.0:0);
Serial.print("Payload Count: ");
Serial.print(F("Payload Count: "));
Serial.println(counter);
counter = 0;
}
Expand All @@ -132,7 +130,7 @@ if(role == RX){
char c = toupper(Serial.read());
if ( c == 'T' && role == RX )
{
printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r");
Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.stopListening();
Expand All @@ -143,7 +141,7 @@ if(role == RX){
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.startListening();
printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r");
Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
role = RX; // Become the primary receiver (pong back)
}
}
Expand Down
20 changes: 10 additions & 10 deletions examples/pingpair_ack/pingpair_ack.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 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 optionlly as well.
* 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.
Expand Down Expand Up @@ -37,11 +37,11 @@ byte counter = 1;

void setup(){

Serial.begin(57600);
Serial.begin(115200);
printf_begin();
printf("\n\rRF24/examples/GettingStarted/\n\r");
printf("ROLE: %s\n\r",role_friendly_name[role]);
printf("*** PRESS 'T' to begin transmitting to the other node\n\r");
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

Expand All @@ -67,11 +67,11 @@ void loop(void) {
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 )){
printf("failed.\n\r");
Serial.println(F("failed."));
}else{

if(!radio.available()){
printf("Blank Payload Received\n\r");
Serial.println(F("Blank Payload Received."));
}else{
while(radio.available() ){
unsigned long tim = micros();
Expand Down Expand Up @@ -104,20 +104,20 @@ void loop(void) {
char c = toupper(Serial.read());
if ( c == 'T' && role == role_pong_back )
{
printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r");
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 )
{
printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r");
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();
}
}
}
}
2 changes: 0 additions & 2 deletions examples/pingpair_dyn/pingpair_dyn.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include <printf.h> // Printf is used for debug

//
// Hardware configuration
Expand Down Expand Up @@ -88,7 +87,6 @@ void setup(void)
//

Serial.begin(115200);
//printf_begin(); //Printf is used for debug

Serial.println(F("RF24/examples/pingpair_dyn/"));
Serial.print(F("ROLE: "));
Expand Down
22 changes: 12 additions & 10 deletions examples/pingpair_irq/pingpair_irq.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void setup(){

Serial.begin(115200);
printf_begin();
printf("\n\rRF24/examples/pingpair_irq/\n\r");
printf("ROLE: %s\n\r",role_friendly_name[role]);
Serial.print(F("\n\rRF24/examples/pingpair_irq\n\rROLE: "));
Serial.println(role_friendly_name[role]);

// Setup and configure rf radio
radio.begin();
Expand Down Expand Up @@ -92,7 +92,8 @@ void loop() {

if (role == role_sender) { // Sender role. Repeatedly send the current time
unsigned long time = millis(); // Take the time, and send it.
printf("Now sending %lu\n\r",time);
Serial.print(F("Now sending "));
Serial.println(time);
radio.startWrite( &time, sizeof(unsigned long) ,0);
delay(2000); // Try again soon
}
Expand All @@ -112,30 +113,31 @@ void check_radio(void) // Receiver role: Does not
radio.whatHappened(tx,fail,rx); // What happened?

if ( tx ) { // Have we successfully transmitted?
if ( role == role_sender ){ printf("Send:OK\n\r"); }
if ( role == role_receiver ){ printf("Ack Payload:Sent\n\r"); }
if ( role == role_sender ){ Serial.println(F("Send:OK")); }
if ( role == role_receiver ){ Serial.println(F("Ack Payload:Sent")); }
}

if ( fail ) { // Have we failed to transmit?
if ( role == role_sender ){ printf("Send:Failed\n\r"); }
if ( role == role_receiver ){ printf("Ack Payload:Failed\n\r"); }
if ( role == role_sender ){ Serial.println(F("Send:Failed")); }
if ( role == role_receiver ){ Serial.println(F("Ack Payload:Failed")); }
}

if ( rx || radio.available()){ // Did we receive a message?

if ( role == role_sender ) { // If we're the sender, we've received an ack payload
radio.read(&message_count,sizeof(message_count));
printf("Ack:%lu\n\r",message_count);
Serial.print(F("Ack: "));
Serial.println(message_count);
}


if ( role == role_receiver ) { // If we're the receiver, we've received a time message
static unsigned long got_time; // Get this payload and dump it
radio.read( &got_time, sizeof(got_time) );
printf("Got payload %lu\n\r",got_time);
Serial.print(F("Got payload "));
Serial.println(got_time);
radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); // Add an ack packet for the next time around. This is a simple
++message_count; // packet counter

}
}
}
Loading

0 comments on commit 46ccceb

Please sign in to comment.