i am trying to connect ardruino uno to arduino mega 2560 using nrf24i0
arduino uno has 2 push button
arduino mega has two led attaced to it.
parts list
arduino uno transmitter
arduino mega 2560 receiver
2 led lights
2 push buttons
2 nrf24l01
I am trying to turn on and off, two led lights attached to arduino mega 2560, while pressing two push buttons attached to arduino uno r3.
pin connection for
arduino uno and arduino mega
CE 7 9
CSN 8 53
SCK 13 52
MO 11 51
MI 12 50
irq – __
code for transmitting arduino uno
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
int msg[1];
RF24 radio(7,8);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7; // asign push button pin 7
int SW2 = 10; // asign push button pin 10
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);}
void loop(void){
if (digitalRead(SW1) == HIGH); // read button is pressed
msg[0] = 111; // nothing is pressed
radio.write(msg, 1);
if (digitalRead(SW2) == HIGH){ // read button2 is pressed
msg[0] = 222; // nothing is pressed
radio.write(msg, 2);}} // transmitt button two is pressed
code for receiving arduino mega 2560
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
int msg[1];
RF24 radio(9,53);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 13; // led pin 13
int LED2 = 5;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);}
void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
if (msg[0] == 222){delay(10);digitalWrite(LED2, HIGH);}
else {digitalWrite(LED1, LOW);}
delay(10);}}
else{Serial.println("No radio available");}}
I am getting errors on receiver , I can’t figure out what is wrong with this code. can someone please fix it or show me how to do it
here is the error code
arduino mega 2560
anotherreceiver1:32: error: void value not ignored as it ought to be
done = radio.read(msg, 1);
^
exit status 1
void value not ignored as it ought to be[code]
[/code]