Problem with RF communication

Hi folks

This project is to create a master RF program which has the capacity to communicate two-way with up to six slave units. The master and (here one) slave start with a handshake sequence which establishes communication which allowing a few seconds grace if the slave unit does not boot first. This works just fine. From there, in the loop(), the idea is to enable two-way communication between master and slave. Currently I am a stalled on a couple of features in the master-to-slave communication. The code is:

MasterBackChat

/*
-- filename  : masterBackChat.ino
--
-- purpose   : 
--
-- mainline  : 
--
-- version   : 
--
-- date      : December 12, 2016
 */

 /*
  * declarative section
  */

  /*
   * header files
   */
  #include <SPI.h>
  #include <RF24.h>

/*
 * pin definitions
 */
  #define CE_Pin  7
  #define CSN_Pin 8

  /*
   * radio creation
   */
   const byte masterAddress[5] = { 'L','o','r','d',' ' };
   const byte slaveAddress0[5] = { 'S','e','r','f','0' };
   
   RF24 radio(CE_Pin, CSN_Pin);

   /*
    * variable definitions
    */
    unsigned long currentTime;
    unsigned long previousTime = millis();
    unsigned long signalInterval = 1000;  // wait 1 sec between signals

    bool newData = false;

    char testData[10] = "testData ";
    char testNumber   = '0';
    int  ackData[2]   = { -1, -1 };

    char firstCommand[10]   = "A12345678";
    char secondCommand[10]  = "B12345678";

    /*
     * forward declaration of subroutines
     */
    
    //  sets a new number at the end of testData
    //  to demonstrate that each test is with new data
    void updateMessage();


    // displays the acknowledgement data whenever it is new data
    // ignores the call if it is old data
    void showData();


    // transmits the test data and listens for acknowledgement
    //  if TX acknowledges, prints ackData
    //  else prints error message
    void send(const byte slave[5]);


    // carries out a *handshake* process with the nominated
    // slave unit.  transmits 10 test messages and receives
    // acknowledgement utilizing the *enableAckPayload*
    // functionality in the radio* header
    bool handshake(const byte slave[5]);
    

    // transmits a command to the designated slave and listens 
    // for acknowledgement
    //  if TX acknowledges, prints ackData
    //  else prints error message
    void sendCommand( const byte slave[5],
                      char currentCommand[]);
    
    
    //  displays the current command and the acknowledgement data
    void showData( char currentCommand[], 
                   int  acknowlegdementData[] );    

                          
/*
 * setup
 */
   void setup()
   {
    Serial.begin ( 9600 );
    Serial.println ( "BackChat Master is starting" );

    radio.begin();
    radio.setChannel( 115 );
    radio.setDataRate( RF24_250KBPS );
    radio.setPALevel( RF24_PA_MAX );
    radio.enableAckPayload();
    radio.setRetries( 3, 5 );
    radio.openReadingPipe( 0, masterAddress );
    // default status for master is Listening
    radio.startListening();

    updateMessage();

    if ( handshake( slaveAddress0  ) )
    {
      Serial.println ( "Handshake successful" );
      Serial.println(); 
    }
   }  //  end setup()

/*
 * working loop
 */
 
   void loop()
   {
      currentTime = millis();
      if (currentTime - previousTime >= signalInterval) 
      {
        sendCommand(slaveAddress0, firstCommand);
      }
      showData( firstCommand, ackData );   

      delay( 2000 );

      currentTime = millis();
      if (currentTime - previousTime >= signalInterval) 
      {
        sendCommand(slaveAddress0, secondCommand);
      }
      showData( secondCommand, ackData );         

      delay( 2000 );
      
//       firstCommand[0] += 1;

//        currentTime = millis();
//        if (currentTime - previousTime >= signalInterval) 
//        {
//          send( slaveAddress0 );
//        }
//        showData();
   }  // end loop()
  
/*
 * implementations of subroutines
 */

    //  sets a new number at the end of testData
    //  to demonstrate that each test is with new data
   void updateMessage() 
   {
      testNumber += 1;
      if (testNumber > '9') 
      {
        testNumber = '0';
      }
      testData[8] = testNumber;
   }  //  end updateMessage()

   // ====================

   // displays the acknowledgement data whenever it is new data
   // ignores the call if it is old data
   void showData() 
  {
    if (newData == true) 
    {
        Serial.print("  Acknowledge data ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        Serial.println();
        newData = false;
    }
  }  //  end showData()

  //  ====================


  // transmits the test data and listens for acknowledgement
  //  if TX acknowledges, prints ackData
  //  else prints error message
  void send(const byte slave[5]) 
  {
     // local variable
     bool rslt;

     radio.stopListening();
     radio.openWritingPipe( slave );

     rslt = radio.write( &testData, sizeof(testData) );
     // Always use sizeof() as it gives the size as the number of bytes.
     // For example if dataToSend was an int sizeof() would correctly return 2

     radio.startListening();
     
     if (rslt) 
     {
       Serial.print("Data Sent ");
       Serial.println(testData);  
           
       if ( radio.isAckPayloadAvailable() ) 
       {
         radio.read(&ackData, sizeof(ackData));
         newData = true;
       }else{
         Serial.println("  Acknowledge but no data ");
       }  // end if ( radio.isAckPayloadAvailable() )
          
        updateMessage();
    }else{
      Serial.println("  Tx failed");
    }  // end if (rslt)
  
    previousTime = millis();
  }  // end send()


  //  ====================


    // carries out a *handshake* process with the nominated
    // slave unit.  transmits 9 test messages and receives
    // acknowledgement utilizing the *enableAckPayload*
    // functionality in the *radio* header
    bool handshake(const byte slave[5])
    {
      while (testNumber != '0')
      {
        currentTime = millis();
        if (currentTime - previousTime >= signalInterval) 
        {
          send( slave );
        }
        showData();
      }
      return true;
    }  //  end handshake()


    //  ====================

   

    // transmits a command to the designated slave and listens 
    // for acknowledgement
    //  if TX acknowledges, prints ackData
    //  else prints error message
    void sendCommand( const byte slave[],
                      char currentCommand[])
    {
       // local variable
       bool rslt;

       // make sure you are writing to the designated slave
       radio.stopListening();
       radio.openWritingPipe( slave );
  
       rslt = radio.write( &currentCommand, sizeof( currentCommand ) );
       // Always use sizeof() as it gives the size as the number of bytes.
       // For example if dataToSend was an int sizeof() would correctly return 2

       //  reinstate default radio status
       radio.startListening();

       if (rslt) 
       {

Serial.print ( "Command sent was " );
Serial.println ( currentCommand );

         if ( radio.isAckPayloadAvailable() ) 
         {
            radio.read(&ackData, sizeof(ackData));
            newData = true;
         }else{
            Serial.println("  Acknowledge but no data ");
         }  // end if ( radio.isAckPayloadAvailable() )
                      
          updateMessage();
      }else{
        Serial.println("  Tx failed");
      }  // end if (rslt)
    
      previousTime = millis();          
    }  //  end sendCommand (slave, currentCommand)


/*    
 *  ====================
 */


     //  displays the current command and the acknowledgement data
    void showData( char currentCommand[], 
                   int  acknowledgementData[] )
    {
      if (newData == true) 
      {
        Serial.print ( "Command in memory is >" );
        Serial.print ( currentCommand );
        Serial.println( "<" );
        
        Serial.print("  Acknowledgement data ");
        Serial.print(acknowledgementData[0]);
        Serial.print(", ");
        Serial.println(acknowledgementData[1]);
        Serial.println();
        newData = false;
      }      
    }

slaveBackChat in next post

slaveBackChat is

/*
-- filename  : slaveBackChat.ino
--
-- purpose   : 
--
-- mainline  : 
--
-- version   : 
--
-- date      : December 12, 2016
 */

 /*
  * declarative section
  */

  /*
   * header files
   */
  #include <SPI.h>
  #include <RF24.h>

/*
 * pin definitions
 */
  #define CE_Pin  7
  #define CSN_Pin 8

  /*
   * radio creation
   */
   const byte masterAddress[5] = { 'L','o','r','d',' ' };
   const byte slaveAddress0[5] = { 'S','e','r','f','0' };
   
   RF24 radio(CE_Pin, CSN_Pin);

   /*
    * variable definitions
    */
//    unsigned long currentTime;
//    unsigned long previousTime;
//    unsigned long signalInterval = 3000;  // wait 3 sec between signals

    bool newData = false;

    char testDataIn[10];
    int  ackData[2]   = { 109, -4000 };

    char currentCommand[10] = "ninechars";

/*
 * forward declarations of subroutines
 */

  // reads in transmitted data
  void getData();  


  // displays the data received and the data sent in response
  void showData();  


  // changes the data send in reply so that
  //  it is different each time
  void updateReplyData();


   // carries out a *handshake* process with the 
   // master unit.  receives 9 test messages and transmits
   // acknowledgement utilizing the *enableAckPayload*
   // functionality in the radio* header
   bool handshake();


   // reads commands from tthe master unit.
   // records the command for action by the slave unit.
   void getCommand( char currentCommand[] );


   // displays the command received and the data sent in response
   void showCommand( char currentCommand[] );
   
   /*
 * setup
 */
   void setup()
   {
    Serial.begin ( 9600 );
    Serial.println ( "BackChat Slave 0 is starting" );

    radio.begin();
    radio.setChannel( 115 );
    radio.setDataRate( RF24_250KBPS );
    radio.setPALevel( RF24_PA_MAX );
    radio.enableAckPayload();
    radio.setRetries( 3, 5 );
    radio.openReadingPipe( 0, slaveAddress0 );
    // default status for slave is Listening
    radio.startListening();

    if ( handshake() )
    {
      Serial.println( "Handshake successful" );
      Serial.println();
    }
   }  //  end setup() 

//==========

  void loop()
  {
    getCommand( currentCommand );
    showCommand( currentCommand );

//     getData();
//     showData();
  }  //  end loop()

//============

  // reads in transmitted test data
  void getData() 
  {
    if ( radio.available() ) 
    {      
        radio.read( &testDataIn, sizeof(testDataIn) );
        updateReplyData();
        newData = true;
    }
  };//  end getData()
  

//================

  // displays the data received and the data sent in response
  void showData() 
  {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(testDataIn);
        Serial.print(" ackPayload sent ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        Serial.println();
        newData = false;
    }
  }  //  end showData()

//================

  // changes the data send in reply so that
  //  it is different each time
  void updateReplyData() 
  {
    ackData[0] -= 1;
    ackData[1] -= 1;
    if (ackData[0] < 100) {
        ackData[0] = 109;
    }
    if (ackData[1] < -4009) {
        ackData[1] = -4000;
    }
    radio.writeAckPayload(0, &ackData, sizeof(ackData)); // load the payload for the next time
  }  //  end updateReplyData


  //  ====================


    // carries out a *handshake* process with the nominated
    // master unit.  receives 9 test messages and receives
    // acknowledgement utilizing the *enableAckPayload*
    // functionality in the radio* header
    bool handshake()
    {
      do
      {
        getData();
        showData();
      } while (testDataIn[8] != '9');

      return true;
    }  //  end handshake()


/*
 *   ===================
 */

    // reads and responds to commands from tthe master unit.
    // records the command for action by the slave unit.
    // 
    void getCommand( char currentCommand[] )
    {
      if ( radio.available(0) ) 
      {
        radio.read( &currentCommand, sizeof( currentCommand ) );
        updateReplyData();

Serial.print( "Command received by getCommand() was >" );
Serial.print( currentCommand );
Serial.println( "<" );
        
        newData = true;
      }        
   }  //  end getCommand()  


/*
 *  ====================
 */

 
  // displays the command received and the data sent in response
  void showCommand( char currentCommand[] ) 
  {
    if (newData == true) {
        Serial.print("Command stored in currentCommand[0] is >");
        Serial.print( currentCommand );        
        Serial.println( "<" );
        
        Serial.print(" ackPayload sent ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        Serial.println();
        newData = false;
    }
  }  //  end showData()

Running these produces these debug printouts

masterBackChat

BackChat Master is starting
Data Sent testData1
  Acknowledge data 108, -4001

Data Sent testData2
  Acknowledge data 107, -4002

Data Sent testData3
  Acknowledge data 106, -4003

Data Sent testData4
  Acknowledge data 105, -4004

Data Sent testData5
  Acknowledge data 104, -4005

Data Sent testData6
  Acknowledge data 103, -4006

Data Sent testData7
  Acknowledge data 102, -4007

Data Sent testData8
  Acknowledge data 101, -4008

Data Sent testData9
  Acknowledge data 100, -4009

Handshake successful

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 109, -4000

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 108, -4001

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 107, -4002

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 106, -4003

slave BackChat

BackChat Slave 0 is starting
Data received testData1
 ackPayload sent 108, -4001

Data received testData2
 ackPayload sent 107, -4002

Data received testData3
 ackPayload sent 106, -4003

Data received testData4
 ackPayload sent 105, -4004

Data received testData5
 ackPayload sent 104, -4005

Data received testData6
 ackPayload sent 103, -4006

Data received testData7
 ackPayload sent 102, -4007

Data received testData8
 ackPayload sent 101, -4008

Data received testData9
 ackPayload sent 100, -4009

Handshake successful

Command received by getCommand() was >rs<
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 109, -4000

Command received by getCommand() was ><
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 108, -4001

Command received by getCommand() was >rs<
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 107, -4002

Command received by getCommand() was ><
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 106, -4003

My troubles in next post

  1. The printouts show that the handshake sequence works correctly.

  2. in masterBackChat

Why is the call to sendCommand at line 129 ignored?

The printout shows immediately after the line Handshake successful that the second call to sendCommand (line 138) is executed instead.

  1. in slaveBackChat

The data received by getCommand differs alternately (as does the transmission from masterBackChat but it is not the right data.

also

the data received by getCommand is not written to the declared variable currentCommand (line 49).

I have been working on this for two days and this is the best result I have achieved. Obviously I am missing something (probably right under my nose :roll_eyes: ). I'd really appreciate someone spotting what is wrong and letting me know.

Thanks

This morning I am using the same code I posted last night - see above - and the hardware is untouched (literally), but the ackData is not getting through. Here are today’s debug printouts:

masterBackChat

BackChat Master is starting
Data Sent testData1
  Acknowledge but no data 

Data Sent testData2
  Acknowledge but no data 

Data Sent testData3
  Acknowledge but no data 

Data Sent testData4
  Acknowledge but no data 

Data Sent testData5
  Acknowledge but no data 

Data Sent testData6
  Acknowledge but no data 

Data Sent testData7
  Acknowledge but no data 

Data Sent testData8
  Acknowledge but no data 

Data Sent testData9
  Acknowledge but no data 

Handshake successful

Command sent was B12345678
  Acknowledge but no data 

Command sent was A12345678
  Acknowledge but no data 

Command sent was B12345678
  Acknowledge but no data 

Command sent was A12345678
  Acknowledge but no data

slaveBackChat

BackChat Slave 0 is starting
Data received testData1
 ackPayload sent 108, -4001

Data received testData2
 ackPayload sent 107, -4002

Data received testData3
 ackPayload sent 106, -4003

Data received testData4
 ackPayload sent 105, -4004

Data received testData5
 ackPayload sent 104, -4005

Data received testData6
 ackPayload sent 103, -4006

Data received testData7
 ackPayload sent 102, -4007

Data received testData8
 ackPayload sent 101, -4008

Data received testData9
 ackPayload sent 100, -4009

Handshake successful

Command received by getCommand() was >rs<
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 109, -4000

Command received by getCommand() was ><
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 108, -4001

Command received by getCommand() was >rs<
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 107, -4002

Command received by getCommand() was ><
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 106, -4003

What would cause the same code and the same hardware to suddenly stop working?

Hi,
At no point have you told us what modules you are using.

Which RF modules are you using?

Tom.... :slight_smile:

Sorry, … I always forget something.

I am working with Arduino UNOs, nRF24L01s with Red Wings Power Supplies to stabilize the nRF24L01 3.3 V supply.

Red Wings Power Supply Info.pdf (92.3 KB)

Hi,
Have you got 0.1uF and 10uF caps on the supply pins at the nRF24L01's

Tom.. :slight_smile:

TomGeorge:
Hi,
Have you got 0.1uF and 10uF caps on the supply pins at the nRF24L01’s

Tom… :slight_smile:

Sorry about the quality of this circuit diagram - there is a story attached to that, as they say :slight_smile:

Anyway, it is legible and it shows the only capacitor I have in the circuit.

You won’t believe this!

I have to believe this because I am looking at it!

I start Arduino IDE this morning. Code in molested. Hardware untouched. writeAckPayload works!

BackChat Master is starting
Data Sent testData1
  Acknowledge data 108, -4001

Data Sent testData2
  Acknowledge data 107, -4002

Data Sent testData3
  Acknowledge data 106, -4003

Data Sent testData4
  Acknowledge data 105, -4004

Data Sent testData5
  Acknowledge data 104, -4005

Data Sent testData6
  Acknowledge data 103, -4006

Data Sent testData7
  Acknowledge data 102, -4007

Data Sent testData8
  Acknowledge data 101, -4008

Data Sent testData9
  Acknowledge data 100, -4009

Handshake successful

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 109, -4000

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 108, -4001

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 107, -4002

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 106, -4003
BackChat Slave 0 is starting
Data received testData1
 ackPayload sent 108, -4001

Data received testData2
 ackPayload sent 107, -4002

Data received testData3
 ackPayload sent 106, -4003

Data received testData4
 ackPayload sent 105, -4004

Data received testData5
 ackPayload sent 104, -4005

Data received testData6
 ackPayload sent 103, -4006

Data received testData7
 ackPayload sent 102, -4007

Data received testData8
 ackPayload sent 101, -4008

Data received testData9
 ackPayload sent 100, -4009

Handshake successful

Command received by getCommand() was >rs<
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 109, -4000

Command received by getCommand() was ><
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 108, -4001

Command received by getCommand() was >rs<
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 107, -4002

Command received by getCommand() was ><
Command stored in currentCommand[0] is >ninechars<
 ackPayload sent 106, -4003

Where are the ghosts in this machine?

Hi,

Do you have it built on protoboard?
If so, probably a bad connection.

Tom... :slight_smile:

TomGeorge:
Do you have it built on protoboard?
If so, probably a bad connection.

I agree. Trouble is that I can remember kids at school (in the Age of Aquarius) who had the same trouble with the same breadboards. Isn't it a shame that someone hasn't patented a Positive Connection Breadboard by now? Some innovative entrepreneur is missing out on millions. :sunglasses:

Some success to report, but this only raises more questions. In the current development phase of my project I get these debug printouts:

masterBackChat

BackChat Master is starting
Data Sent testData1
  Acknowledge data 108, -4001

Data Sent testData2
  Acknowledge data 107, -4002

Data Sent testData3
  Acknowledge data 106, -4003

Data Sent testData4
  Acknowledge data 105, -4004

Data Sent testData5
  Acknowledge data 104, -4005

Data Sent testData6
  Acknowledge data 103, -4006

Data Sent testData7
  Acknowledge data 102, -4007

Data Sent testData8
  Acknowledge data 101, -4008

Data Sent testData9
  Acknowledge data 100, -4009

Handshake successful

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 109, -4000

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 108, -4001

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 107, -4002

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 106, -4003

slaveBackChat

BackChat Slave 0 is starting
Data received testData1
 ackPayload sent 108, -4001

Data received testData2
 ackPayload sent 107, -4002

Data received testData3
 ackPayload sent 106, -4003

Data received testData4
 ackPayload sent 105, -4004

Data received testData5
 ackPayload sent 104, -4005

Data received testData6
 ackPayload sent 103, -4006

Data received testData7
 ackPayload sent 102, -4007

Data received testData8
 ackPayload sent 101, -4008

Data received testData9
 ackPayload sent 100, -4009

Handshake successful

Command received by getCommand() was >B12345678<
Command stored in currentCommand[0] is >B<
 ackPayload sent 109, -4000

Command received by getCommand() was >A12345678<
Command stored in currentCommand[0] is >A<
 ackPayload sent 108, -4001

Command received by getCommand() was >B12345678<
Command stored in currentCommand[0] is >B<
 ackPayload sent 107, -4002

Command received by getCommand() was >A12345678<
Command stored in currentCommand[0] is >A<
 ackPayload sent 106, -4003

These results, which are what I have been striving for, were obtained by a bit of programming hanky-panky.

See next post

In slaveBackChat I had this routinh for receiving production commands

    // reads and responds to commands from the master unit.
    // records the command for action by the slave unit.
    //
    void getCommand()  // char currentCommand[] )
    {
      if ( radio.available(0) )
      {
        radio.read( &currentCommand, sizeof( currentCommand ) );
        updateReplyData();

Serial.print( "Command received by getCommand() was >" );
Serial.print( currentCommand );
Serial.println( "<" );
       
        newData = true;
      }       
   }  //  end getCommand()

I got it to work by commenting out the char pointer parameter.

Now, it works, so I’m not complaining. but I would like to know why it would not work with the parameter but will with a global variable.

See next post.

In masterBackChat the original function to transmit production commands was

    // transmits a command to the designated slave and listens
    // for acknowledgement
    //  if TX acknowledges, prints ackData
    //  else prints error message
    void sendCommand( const byte slave[], 
                      char currentCommand[])
    {
       // local variable
       bool rslt;

       // make sure you are writing to the designated slave
       radio.stopListening();
       radio.openWritingPipe( slave );
 
       rslt = radio.write( &currentCommand, sizeof( currentCommand ) );
       // Always use sizeof() as it gives the size as the number of bytes.
       // For example if dataToSend was an int sizeof() would correctly return 2

       //  reinstate default radio status
       radio.startListening();

       if (rslt)
       {

Serial.print ( "Command sent was " );
Serial.println ( currentCommand );

         if ( radio.isAckPayloadAvailable() )
         {
            radio.read(&ackData, sizeof(ackData));
            newData = true;
         }else{
            Serial.println("  Acknowledge but no data ");
            Serial.println();
         }  // end if ( radio.isAckPayloadAvailable() )
                     
          updateMessage();
      }else{
        Serial.println("  Tx failed");
        Serial.println();
      }  // end if (rslt)
   
      previousTime = millis();         
    }  //  end sendCommand (slave, currentCommand)

In this case I commented out the command parameter and dumped the concept of reusable code writing two functions in the form

    // transmits a command to the designated slave and listens
    // for acknowledgement
    //  if TX acknowledges, prints ackData
    //  else prints error message
    void sendFirstCommand( const byte slave[])  //,
                      //char currentCommand[])
    {
       // local variable
       bool rslt;

       // make sure you are writing to the designated slave
       radio.stopListening();
       radio.openWritingPipe( slave );
 
       rslt = radio.write( &firstCommand, sizeof( firstCommand ) );
       // Always use sizeof() as it gives the size as the number of bytes.
       // For example if dataToSend was an int sizeof() would correctly return 2

       //  reinstate default radio status
       radio.startListening();

       if (rslt)
       {

Serial.print ( "Command sent was " );
Serial.println ( firstCommand );

         if ( radio.isAckPayloadAvailable() )
         {
            radio.read(&ackData, sizeof(ackData));
            newData = true;
         }else{
            Serial.println("  Acknowledge but no data ");
         }  // end if ( radio.isAckPayloadAvailable() )
                     
          updateMessage();
      }else{
        Serial.println("  Tx failed");
      }  // end if (rslt)
   
      previousTime = millis();         
    }  //  end sendFirsrCommand()

Once again I had an issue with a pointer parameter. Fortunately it works with the slave parameter which means I could send the first command to one of half a dozen slaves (which is the object of the exercise).

The question remains, "Why did the pointer parameter cause problems?"

There are two other unresolved issues:

  1. Why, in masterBackChat::loop(), is the first command call overlooked?
  2. Why is ackData working today when it didn't yesterday, and did the day before? Does it have some rule about not working on Sundays? :fearful:

Any assistance in resolving these issues will be greatly appreciated.

The question remains, "Why did the pointer parameter cause problems?"

You'll need to get an answer for that from http://snippets-r-us.com.

vagulus:
The question remains, "Why did the pointer parameter cause problems?"

Sorry about that. The question really is

Why did having two parameters cause problems?

Incidentally, the full code for masterBackChat is in the original post.

WRT: problem of second command being transmitted and the first ignored

Cured this.

BackChat Master is starting
===========================

Data Sent testData1
  Acknowledge data 108, -4001

Data Sent testData2
  Acknowledge data 107, -4002

Data Sent testData3
  Acknowledge data 106, -4003

Data Sent testData4
  Acknowledge data 105, -4004

Data Sent testData5
  Acknowledge data 104, -4005

Data Sent testData6
  Acknowledge data 103, -4006

Data Sent testData7
  Acknowledge data 102, -4007

Data Sent testData8
  Acknowledge data 101, -4008

Data Sent testData9
  Acknowledge data 100, -4009

Handshake successful

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 109, -4000

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 108, -4001

Command sent was A12345678
Command in memory is >A12345678<
  Acknowledgement data 107, -4002

Command sent was B12345678
Command in memory is >B12345678<
  Acknowledgement data 106, -4003

The problem was inh the execution ofhandshake() previousTime gets updated and these is insufficient time between that update and the call to sendFirstCommand().

 if ( handshake( slaveAddress0  ) )
    {
      Serial.println ( "Handshake successful" );
      Serial.println();
    }  // end if ( handshake

    delay( 1000 );  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   }  //  end setup()

/*
 * working loop
 */
 
   void loop()
   {
      currentTime = millis();
      if (currentTime - previousTime >= signalInterval)
      {
        sendFirstCommand(slaveAddress0); 
      }
      showData( firstCommand, ackData );

Inserting the delay statement ensures that currentTime - previousTime >= signalInterval.

Some added information concerning and existing problem.

vagulus:
2. Why is ackData working today when it didn't yesterday, and did the day before? Does it have some rule about not working on Sundays?

slaveBackChat is usuallu on COM5 and masterBackChat is usually on COM6.

Sometimes I make a change to the code (last instance I temporarily changed the reading pipe in slaveBackChat from 0 to 1) and ackData isn't received by masterBackChat. I have found that if I swap the COM ports, ackData behaves correctly again.

How weird is that? :o

masterBackChat and slaveBackChat now work as I wanted. That is not to say that I am happy with the programs which I have attached because they are too big to include on the page as code. There are a range of questions raised by this programming experience, and these will be raised over time in problem-specific postings.

In their current stage of evolution, these programs have one master unit and one slave unit. To run these programs, start slaveBackChat first. They begin with a handshake sequence which does allow a few seconds for slaveBackChat to be late, but it is best to start the slave first.

After the handshake a local task is run on command in the slave unit. While that is running a local task is run simultaneously on the master unit. When the master unit completes that task it commands another task on the slave unit. Then the sequence is repeated.

During development I used Arduino UNOs, and nRF24L01+ PCBs powered through Red Wings power supply boards.

My thanks again to the people who offered assistance during the development of these programs.

Merry Christmas, Happy Hanukkah, Salaam etc. to all.

masterBackChat.ino (11.9 KB)

slaveBackChat.ino (8 KB)