nRF24L01+ and roles

Hello all, once again…

I have a couple of questions about the roles on nRF24L01+.
I’m using the RF24 lib, my “network” wont be a tree, but a star, where i have my main equipment, and the individual modules will communicate only with the main.
at the moment i have my main recieving and the nodes transmitting but what i really need is to have the nodes in receive mode and when they get a specific request it will automatically change his own role to send the answer to the main, example: Temperature

Main Module
Ask temp -------------------------------> receive request
receive ack (automatic) <------------------------------- send ack (automatic)
change to receive mode -------------------------------- change to send mode
receive answer <------------------------------- send answer
send ack (automatic) -------------------------------> receive ack (automatic)
change to send mode -------------------------------- change to receive mode

The RF24: pingpair.pde is long and a bit confusing to me to be honest, im looking for an extremelly easy, small code example that dont need human interation like printf("*** PRESS 'T' to begin transmitting to the other node\n\r");
Other question: is it really need to set pipes?
what about the

// sets the role of this unit in hardware.  Connect to GND to be the 'pong' receiver
// Leave open to be the 'ping' transmitter
const int role_pin = 7;

what does he mean by that?

Thanks in advance and sorry for the looong noob post

Perhaps i should post some code that might help, this is the modules part, and at the end of the loop part you can see the if, where i want the role thing.

//RX

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <printf.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//########################### DS18B20 MAIN #############################

// Data wire is plugged into pin 6 on the module
#define ONE_WIRE_BUS 6
 
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//########################### NRF24L01 MAIN #############################

// nRF24L01(+) radio attached using Getting Started board 
RF24 radio(8,7);
 
// Network uses that radio
RF24Network network(radio);
 
// Address of our node
const uint16_t this_node = 1;
 
// Address of the other node
const uint16_t other_node = 0;
 
// How often to send 'hello world to the other unit
const unsigned long interval = 2000; //ms
 
// When did we last send?
unsigned long last_sent;
 
// How many have we sent already
unsigned long packets_sent;
 
// Structure of our payload
struct payload_t
{
  float temperatura;
  unsigned long ms;
  unsigned int order;
  unsigned long counter;
  
};

void setup(void)
{
  Serial.begin(57600);
  Serial.println("RF24Network/examples/helloworld_rx/");
  sensors.begin();
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
}

//########################### NRF24L01 LOOP #############################

void loop(void)
{
  
  // Pump the network regularly
  network.update();
 
  // Is there anything ready for us?
  while ( network.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload));
    Serial.print("Received packet #");
    Serial.println(payload.counter);
    Serial.print(" Milisegundos ");
    Serial.println(payload.order);
    Serial.print(" Temperatura remota ");
    Serial.println(payload.temperatura);
    Serial.print(" Order ");
    Serial.println(payload.ms);
    if (payload.order == 1)
    {
      //Change mode and send temp

      temp();
  }

}

//########################### DS18B20 VOID #############################

  void temp()
{
 
sensors.requestTemperatures(); // Send the command to get temperatures

Serial.print(" Arduino Temperature: ");
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
delay (1000);
}

The first question to be answered is what does the role pin do... If you had taken the time to read ALL the documentation you'd know... From the pingpair sketch... // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter const int role_pin = 7;

Docedison: The first question to be answered is what does the role pin do... If you had taken the time to read ALL the documentation you'd know... From the pingpair sketch... // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter const int role_pin = 7;

Thank you for the reply,

I've read it, though since its phisically connected to the ground, i can change the status? isnt ground always low? im preety new to this stuff, and believe that i read a lot about this... i even printed the classes http://maniacbug.github.io/RF24Network/annotated.html except the sync

did you manage to get it working? i would like to use this one https://www.sparkfun.com/products/152 to communicate data to a garmin watch. I got everything concerning the ant protocol and messages i should send, but it seems i am unable to properly communicate with the chip. Do you recommend using the NRF lib as you did?

what does nrf24 radio(8,7) stand for? i mean what do 8 and 7 refer to? Rx pin, tx pin? SDA & clock it is totaly unclear

The two passed in values are for the CE, and CSN pins.

Here is the documentation I used ( successfully ): http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/

1 quick question... if im gonna have 1 main module, that asks for temp and send 0 or 1 for the remote modules take action and then reply the event to the main, should i use radio or network. do i need to use pipes?

im not sure if the question is clear if its not ill try to be more specific

Pipes are part of the communication process. I think you need to read the documentation and ask questions until you understand all of the library you are trying to use. If you don't I doubt that your success will be what you planned. As to your question above yes you can ground it to reverse roles... I believe that was covered on Maniacbug's blog and 24L01 page.. I can probably go find it should you be challemged in some manner.

After a couple of days testing, i decided to try the RF24Network because i will have more than 30 nodes and only 1 “central” and because i think it might be easier for the central node to send a message and wait for a reply from the destination more than just open and close pipes all the time…

The project consists in the main sending a “question” like temp or or an “order” like activate relay, and then receive the answer of the temp or the order succeeded or not. Am i thinking right by choosing the RF24Network instead on the RF24?
My code isnt working, not sure why, but since i’m at my work place i cannot check it, i do have the code though. just in case someone have the time and will of reading it ill drop it here…

Transmitter:

/*
 Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */

/**
 * Simplest possible example of using RF24Network 
 *
 * TRANSMITTER NODE
 * Every 2 seconds, send a payload to the receiver node.
 */

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

// nRF24L01(+) radio attached using Getting Started board 
RF24 radio(8,7);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 1;

// Address of the other node
const uint16_t other_node = 0;

// Variables declaration
  int relay;
  unsigned long temperatura;
  int order;
  int certo;

// Structure of our payload
struct payload_t
{
  int relay;
  unsigned long temperatura;
  int order;
  int certo;
};

bool enviado = false;

void setup(void)
{
  Serial.begin(57600);
  Serial.println("RF24Network/examples/helloworld_tx/");
 
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
  
}

void loop(void)
{
  
  int incomingByte = 0;
  // send data depending on value in serial monitor:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
    if (incomingByte == 49);
    {
  enviar();
    }
  
  if (enviado == true)
  {
  receber();
  }
  
}

void enviar(void)
{
 // Pump the network regularly
  network.update();

  // send a message!

    Serial.print("Sending...");
    payload_t payload = { relay, temperatura, order, certo };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header,&payload,sizeof(payload));
    if (ok)
    {
      Serial.println("ok.");
      enviado = true;
    }
    else
      Serial.println("failed.");
}  
void receber(void)
{
  // Pump the network regularly
  network.update();

  // Is there anything ready for us?
  while ( network.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload));
    Serial.print("Relay State: ");
    Serial.println(payload.relay);
    Serial.print("Temperatura: ");
    Serial.println(payload.temperatura);
    enviado = false;
  }
  if (enviado == true)
  receber();
}

Receiver:

/*
 Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */

/**
 * Simplest possible example of using RF24Network,
 *
 * RECEIVER NODE
 * Listens for messages from the transmitter and prints them out.
 */

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

// nRF24L01(+) radio attached using Getting Started board 
RF24 radio(8,7);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 0;

// Address of the other node
const uint16_t other_node = 1;

// Variables declaration
  int relay;
  unsigned long temperatura;
  int order;
  int certo;

// Structure of our payload
struct payload_t
{
  int relay;
  unsigned long temperatura;
  int order;
  int certo;
};

bool recebido = false;

void setup(void)
{
  Serial.begin(57600);
  Serial.println("RF24Network/examples/helloworld_rx/");
 
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
}

void loop(void)
{
  if (recebido = true)
    enviar();
  else
    receber();
}

void receber(void)
{
  
  certo = 0;
  // Pump the network regularly
  network.update();

  // Is there anything ready for us?
  while ( network.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload));
    Serial.print("Relay State: ");
    Serial.println(payload.relay);
    Serial.print("Temperatura: ");
    Serial.println(payload.temperatura);
    Serial.print("Order: ");
    Serial.println(payload.order);
    Serial.print("Certo: ");
    Serial.println(payload.certo);
    certo = payload.certo;
  }
  if (certo = 1)
  {
    recebido = true;
    enviar();
  }
  else
    receber();
}

void enviar(void)
{
 // Pump the network regularly
  network.update();

  // send a message!

    Serial.print("Sending...");
    payload_t payload = { relay, temperatura, order, certo };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header,&payload,sizeof(payload));
    if (ok)
    {
      Serial.println("ok.");
      recebido = false;
    }
    else
      Serial.println("failed.");
}  


// vim:ai:cin:sts=2 sw=2 ft=cpp

Translation:
recebido = received
enviado = sent

Did you try this first? http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/... it seeks to work for those that bother to follow instructions.

yes, i did and i could make it work, but for 30 nodes it will become complicated i think. i could make the network work too, just by copy/paste and changing the pins, but when i changed the code for my needs it stopped working... not sure if its the payload... ill need to work more on the code, i just posted it cause perhaps the experienced people could see some real basic that i couldn't so far...

PS: i only have 1 arduino and one atmega328p on a breadboard...

to drive/listen to 30 nodes?... It's done one at a time and the data is repeated/resent if not acked when you detect a free channel condition. I would recommend that each node be polled and you could change frequency for several or many different frequencies/purposes... Some loose thoughts.

Doc

Docedison: to drive/listen to 30 nodes?... It's done one at a time and the data is repeated/resent if not acked when you detect a free channel condition. I would recommend that each node be polled and you could change frequency for several or many different frequencies/purposes... Some loose thoughts.

Doc

Wouldn't be easier to use the network header? cause the 30 nodes will always be listening, until the base request something from 1 of them, always 1 at a time and not multiple nodes at the same time...

to drive/listen to 30 nodes?... It's done one at a time and the data is repeated/resent if not acked when you detect a free channel condition. I would recommend that each node be polled and you could change frequency for several or many different frequencies/purposes... Perhaps some might have different priorities? [u]Just[/i] some loose thoughts.[/u] Doc[/quote]

oh gotcha :)

ty

yw