nRF and Serial problem and function parameter problem

Hi,

We are developing home automation application using Arduino.

I am sending data from my computer to my UNO. then UNO transfer the data to another arduino(Nano) through nRF24L01 radio devices.(Small one. not PA+antenna version).

computer------->UNO+nRF24L01---------------->nRF24L01+Nano.

Serial node1 Air node2

Like this.

I am using maniacbuc RF library.

Tx code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//void radio_w(int x);
void function(int x);
RF24 radio(9, 10); // CNS, CE
const byte address[6] = "00001";
char bt;
const char text[14] = {'F', 'G', 'H', 'I', 'J', 'f', 'g', 'h', 'i', 'j', '5', '6', '7', '8'};
int AC_LOAD = 5;    // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF
int fan = 0;

void setup() {
  //  attachInterrupt(0, zero_crosss_int, RISING);
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.stopListening();
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(AC_LOAD, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(AC_LOAD, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
}

void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
  if (fan == 1) {
    int dimtime = (75 * dimming);  // For 60Hz =>65
    delayMicroseconds(dimtime);    // Wait till firing the TRIAC
    digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
    delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
    digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
  }
}


void loop() {
  if (Serial.available()) {
    delay(10);
    bt = Serial.read();
  }
  if (bt == 'F') {
    function(0);
  }
  if (bt == 'G') {
    function(1);
  }
  delay(10);
  radio.startListening();
  delay(10);
}

void function(int x) {
  delay(10);
  radio.stopListening();
  delay(10);
  radio.write(&text[x], sizeof(text));
  delay(10);
}

Rx code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CNS, CE
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    const char text[1];
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

The problem is if I pass different parameter into my function then the device doesn’t send the data to node 2.

example:

if (bt == 'F') {
    [b]function(0);[/b]
  }
  if (bt == 'G') {
    [b]function(1);[/b]
  }

Your opinion ?.

You claim to use an outdated and known slow and buggy library, your code seems to be for the recommended version.

Under the original maniacbug library you can not use stings as addresses.

const byte address[6] = "00001";

I would recommend Optimized High Speed NRF24L01+ Driver Class

You are sprinkling your code with (mostly?) senseless delays.

Your sender keeps calling stopListening without calling startListing ever.

You are sending 14 bytes and read back only one in the receiver.

You could start with Simple nRF24L01+ 2.4GHz transceiver demo.

Ok. thanks.

Under the original maniacbug library you can not use stings as addresses.

I am testing and trying many ways to fix this. that time I search example codes from internet. in one example one guy used this kind of address.

Your sender keeps calling stopListening without calling startListing ever.

If I didn't call that stopListening and startListening then I cant send the data. (try this code in real time then you can understand).

You are sending 14 bytes and read back only one in the receiver.

I just send only one byte one time at a time. As you can see the sending function is in if control statement

You should programm, not puzzle, especially not cross-library.

SureshKumar2610: If I didn't call that stopListening and startListening then I cant send the data. (try this code in real time then you can understand).

Try a good library and you will see it is not neccessary (but I'm repeating myself).

SureshKumar2610: I just send only one byte one time at a time. As you can see the sending function is in if control statement

Nope, you are sending 14 bytes.

const char text[14] = {'F', 'G', 'H', 'I', 'J', 'f', 'g', 'h', 'i', 'j', '5', '6', '7', '8'};
  radio.write(&text[x], sizeof(text));

I use an Arduino with an nRF24 in the way you wish to. It should be quite straightforward with the examples in my Tutorial that @Whandall linked to.

Also have a look at Serial Input Basics

...R

Ok. Thanks for the reply. I will follow and get back to you if I faced any problem.