error in transmitting and receiving binary data

hi all :).. this is my code of c for transmiting data 0 and 1 and want to blink the LED on and off by recving that 0 and 0....but this code cannot work for me....i want to read the port of arduino uno and sent that binary to the reciver end to blink the led on and when the port goes to low the led getting offf....

//////// transmitter code////////
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define x 7

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);
int data[2];

void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}

void loop()
{
if(digitalRead(x) == HIGH)
{
radio.stopListening(); // must stop listening before you open a writing pipe
radio.openWritingPipe(pipe);
data[0] = 1;
//joystick[1] = analogRead(x);
radio.write( data, sizeof(data) );
delay(200);
}
else
{
radio.stopListening(); // must stop listening before you open a writing pipe
radio.openWritingPipe(pipe);
data[1]= 0;
radio.write( data, sizeof(data) );
delay(200);
}

}

/////////////// reciver code////////////
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);

int data[2];
int led =7;

void setup()
{
Serial.begin(9600);
pinMode (led, OUTPUT);
delay(1000);
//Serial.println(“Nrf24L01 Receiver Starting”);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}

void loop()
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read( data, sizeof(data) );

if (done== HIGH)
{
digitalWrite (led, HIGH);
delay(1000);
}

if (done== LOW)
{
digitalWrite (led, LOW);
delay(1000);
}
}
}
}

//else

//digitalWrite (led, LOW);
//delay(1000);
//Serial.println(“No radio available”);
//}

radio.startListening();;

Double semicolon?

Hi,

Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom..... :slight_smile:

[code][code]
//////// transmitter code////////
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define x 7

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);
int data[2];

void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}

void loop()
{
if(digitalRead(x) == HIGH)
{
radio.stopListening(); // must stop listening before you open a writing pipe  
radio.openWritingPipe(pipe);
data[0] = 1;
//joystick[1] = analogRead(x);
radio.write( data, sizeof(data) );
delay(200);
}
else
{
radio.stopListening(); // must stop listening before you open a writing pipe  
radio.openWritingPipe(pipe);
data[1]= 0;
radio.write( data, sizeof(data) );
delay(200);
}

}


///////////////  reciver code////////////
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);

int data[2];
int led =7;

void setup()
{
Serial.begin(9600);
pinMode (led, OUTPUT);
delay(1000);
//Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}

void loop()
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read( data, sizeof(data) );

if (done== HIGH)
{
digitalWrite (led, HIGH);
delay(1000);
}

if (done== LOW)
{
digitalWrite (led, LOW);
delay(1000);
}
}
}
}

//else

//digitalWrite (led, LOW);
//delay(1000);
//Serial.println("No radio available");
//}

Hi,
Please read post #1.....

Tom... :slight_smile:

Nothing wrong with a double semi-colon. Not useful, but no harm done.

hi :).double semicolon is not issue in the code..... its just due to mistake... the actual problem is in transmission and receiving...

Maybe nothing to do with it, but in the transmitter code I see no resetting of the opposite block of the data array 'data', so data[0] will always be 1, once set, and data[1] will always be 0, once set. I also can't see any reason you'd need an array here.

The receiver makes no use of arrayed data. 'done' seems to get set on the fact that something was sent, rather than the actual contents. Since 'done' is a bool, it cannot possibly be used to hold the contents of a multi-byte data packet.

In the void loop(); of the transmitter, you have:

radio.stopListening(); // must stop listening before you open a writing pipe  
radio.openWritingPipe(pipe);

It seems right that this should be in the void setup();

hi sirius631:pls help me.... i wants to take the operation of push button from this code...when press the button will transmit 1 to bliink the LED and when release the button turns the LED of.....