sending a data array over nrf24l01 with mirf ??? how?

So im trying to send a multiple byte array over the nrf24L01, however i cant seem to figure out how to do it, and i cant seem to find much documentation! ultimately i'd like to be able to send a 16byte array... I'll post the latest code i've been messing around with ... could someone point out what i need to change to be able to send a data array? Thanks.

Hmmm until i find out how to paste the code this will have to do ... its almost the same as the actual examples but with for loops to fill the array...

/**

  • A Mirf example to test the latency between two Ardunio.
  • Pins:
  • Hardware SPI:
  • MISO -> 12
  • MOSI -> 11
  • SCK -> 13
  • Configurable:
  • CE -> 8
  • CSN -> 7
  • Note: To see best case latency comment out all Serial.println
  • statements not displaying the result and load
  • 'ping_server_interupt' on the server.
    */

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
char thisChar[3];
char time[3];
int i;

void setup(){
Serial.begin(9600);
Serial.println("send any byte and I'll tell you everything I can about it");
Serial.println();
/*

  • Setup pins / SPI.
    */

/* To change CE / CSN Pins:
*

  • Mirf.csnPin = 9;
  • Mirf.cePin = 7;
    /
    /

    Mirf.cePin = 7;
    Mirf.csnPin = 8;
    */
    Mirf.spi = &MirfHardwareSpi;
    Mirf.init();

/*

  • Configure reciving address.
    */

Mirf.setRADDR((byte *)"clie1");

/*

  • Set the payload length to sizeof(unsigned long) the
  • return type of millis().
  • NB: payload on client and server must be the same.
    */

Mirf.payload = 3;

/*

  • Write channel and payload config then power up reciver.
    */

/*

  • To change channel:
  • Mirf.channel = 10;
  • NB: Make sure channel is legal in your area.
    */

Mirf.config(); // this was just added so that there was something default to send while testing
thisChar[0] = 1;
thisChar[1] = 0;
thisChar[2] = 1;

Serial.println("Beginning ... ");
}

void loop(){
if (Serial.available() >= 3) {
for (i = 0; i < 3; i = i + 1) {
thisChar = Serial.read();

  • }*
  • }*

//int time = thisChar;

_ Mirf.setTADDR((byte *)"serv1");_

  • for (i = 0; i < 3; i = i + 1) {*
    _ Mirf.send((byte ) thisChar);_
    _ //Mirf.send((byte )"12345");_
    _
    }
    _

* while(Mirf.isSending()){*
* }*
* Serial.println("Finished sending");*
* delay(10);*
* while(!Mirf.dataReady()){*
* //Serial.println("Waiting");*
_ /* if ( ( millis() - time ) > 1000 ) {
* Serial.println("Timeout on response from server!");*
* return;*
} /_
_
Serial.print("waiting");_
_
delay(250);_
_
}_
_
for (i = 0; i < 3; i = i + 1) {_
_Mirf.getData((byte ) time);
}_

* Serial.print("Ping: ");*

//for (i = 0; i < 3; i = i + 1) {
* Serial.println(time[0]);*
//}
* //Serial.println( time[0]);*

* delay(1000);*
}

I just stumbled across a post ... looks like there is a piece of the puzzle missing to be able to send an array ...

Mirf.payload = 13;
byte data[Mirf.payload];

// ... fill in your data into your array

// hand over to transmitter
Mirf.send((byte*)data);

// give the chip the time to transmit (and retransmit in case of errors)
while( Mirf.isSending() ) ;

Yup, that's right. You build your entire packet, and call send() once with the whole thing.

Also, next time please post your code surrounded by 'code' markers. See the '#' button in the toolbar. That and it's helpful to remove the commented-out code.

OK heres a sample for anyone else trying to find an example. This will send a 16byte array to a second unit which will then send it back to the first and then display the 16byte array in the monitor window. Hopefully this will save us beginners a bunch of work :-).

Transmitting unit

/**
 * A Mirf example to test the latency between two Ardunio.
 *
 * Pins:
 * Hardware SPI:
 * MISO -> 12
 * MOSI -> 11
 * SCK -> 13
 *
 * Configurable:
 * CE -> 8
 * CSN -> 7
 *
 * Note: To see best case latency comment out all Serial.println
 * statements not displaying the result and load 
 * 'ping_server_interupt' on the server.
 */

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

char data[16];
char rec[16];
byte time[16];
int i, a, f;


void setup(){
  Serial.begin(9600);
  Serial.println("Enter 16 characters");
  Serial.println();

  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();

  Mirf.setRADDR((byte *)"clie1");

  Mirf.payload = 16;

  Mirf.config();



  Serial.println("Beginning ... "); 
}

void loop(){

  if (a == 0){

    if (Serial.available() > 15) {
      a = 1;

      for (i = 0; i < 16; i = i + 1) {
        data[i] = Serial.read();
      }
      Serial.println(" ");
      Serial.print("you sent ");
      for (i = 0; i < 16; i = i + 1) {
        Serial.print(data[i]);
      }
      
      Serial.print(" DEC ");
    for (i = 0; i < 16; i = i + 1) {
      Serial.print(data[i], DEC);
    }

      Serial.print(" Hex ");
      for (i = 0; i < 16; i = i + 1) {
        Serial.print(data[i], HEX);
      }
      Serial.println(" ");
    }
  }


  if (a == 1){

    Mirf.setTADDR((byte *)"serv1");


    data[Mirf.payload];



    Mirf.send((byte *) &data);


    while(Mirf.isSending()){
    }

    Serial.println(" ");
   
    delay(10);

    while(!Mirf.dataReady()){
    }
    Serial.print("You Got  ");
    Mirf.getData((byte *) &rec);


    for (i = 0; i < 16; i = i + 1) {
      Serial.print(rec[i]);
    }
    Serial.print(" DEC ");
    for (i = 0; i < 16; i = i + 1) {
      Serial.print(rec[i], DEC);
    }
    Serial.print(" Hex ");
    for (i = 0; i < 16; i = i + 1) {
      Serial.print(rec[i], HEX);
    }
    Serial.println(" ");

    a = 0;
    
  } 

}

responding unit

/**
 * An Mirf example which copies back the data it recives.
 *
 * Pins:
 * Hardware SPI:
 * MISO -> 12
 * MOSI -> 11
 * SCK -> 13
 *
 * Configurable:
 * CE -> 8
 * CSN -> 7
 *
 */

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
boolean b = 0;
byte thisChar[16];
int i;

int data[16];

void setup(){
  
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  
  /*
   * Set the SPI Driver.
   */

  Mirf.spi = &MirfHardwareSpi;
  
  /*
   * Setup pins / SPI.
   */
   
  Mirf.init();
  
  /*
   * Configure reciving address.
   */
   
  Mirf.setRADDR((byte *)"serv1");
  
  /*
   * Set the payload length to sizeof(unsigned long) the
   * return type of millis().
   *
   * NB: payload on client and server must be the same.
   */
   
  Mirf.payload = 16;
   char data[Mirf.payload];
  /*
   * Write channel and payload config then power up reciver.
   */
   
  Mirf.config();
 
  
  Serial.println("Listening..."); 
}

void loop(){
  
  
  
  /*
   * A buffer to store the data.
   */
   
   data[Mirf.payload];
  
  /*
   * If a packet has been recived.
   *
   * isSending also restores listening mode when it 
   * transitions from true to false.
   */
   
  if(!Mirf.isSending() && Mirf.dataReady()){
    Serial.println("Got packet");
    
    /*
     * Get load the packet into the buffer.
     */
     
    
    Mirf.getData((byte *) data);
    
     for (i = 0; i < 16; i = i + 1) {
      Serial.print(data[i]);
    }
   
    
    /*
     * Set the send address.
     */
     
     
    Mirf.setTADDR((byte *)"clie1");
    
    /*
     * Send the data back to the client.
     */
    
    Mirf.send((byte *) data);
    
    
    /*
     * Wait untill sending has finished
     *
     * NB: isSending returns the chip to receving after returning true.
     */
      b = !b;
      digitalWrite(4, b);
    
    Serial.println("Reply sent.");
  }
}

These examples are just modified from the included examples.

responding unit:

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
boolean b = 0;
byte thisChar[16];
int i;

int data[16];

int data [16] should be char data[16], right?