I have two RF24s connected to two separate Arduino Nanos, and another RF24 connected to an Uno. Basically what I'm trying to do is make a stopwatch where if you push a button on any of the three boards, it tells the stopwatch to stop or start, and the Uno has an LCD that displays the time interval. I have the RF24 connected to the Uno set to read, and the RF24s connected to the Nanos set to write to signal when a button has been pressed on either of them. I have gotten this to work fine when using just one of the Nanos, but when I try to use both of them, the receiver only seems to be reading from a single pipe. I've attached my code here, can anyone see what it is that I'm doing wrong?
Transmitter code for the Nanos:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio (9, 10);
const byte address[6] = "00001";
const int switchpin = 4;
boolean switchstate = LOW;
boolean old_switchstate = LOW;
int state = 0;
void setup() {
pinMode (4, INPUT);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
switchstate = digitalRead(switchpin);
if (switchstate!= old_switchstate){
if (switchstate == HIGH){
state = 1;
radio.write(&state, sizeof(state));
}
else{
state = 0;
radio.write(&state, sizeof(state));
}
old_switchstate = switchstate;
}
}
The only difference in the code between the two transmitters is that the second transmitter has an address of "00002"
Reciever code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 6, 5, 4, 3, 2);
const int switchpin = 7;
const int ledpin = 1;
boolean switchstate = LOW;
boolean old_switchstate = LOW;
boolean ledon = LOW;
boolean old_ledstate = LOW;
unsigned long oldtime = 0;
float interval = 0;
RF24 radio(9, 10);
const byte address1 [6] = "00001";
const byte address2 [6] = "00002";
int state = 0;
void setup() {
SPI.begin;
radio.begin ();
radio.openReadingPipe (0, address1);
radio.openReadingPipe (1, address2);
radio.setPALevel (RF24_PA_MIN);
radio.startListening ();
pinMode(switchpin, INPUT);
pinMode(ledpin, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(1, 0);
lcd.print("Push button");
lcd.setCursor(3, 1);
lcd.print("to start");
}
void loop() {
unsigned long currenttime = millis();
if (radio.available()){
radio.read(&state, sizeof(state));
if (state == 1){
ledon = !ledon;
}
}
switchstate = digitalRead(switchpin);
if (switchstate != old_switchstate) {
old_switchstate = switchstate;
if (switchstate == HIGH){
ledon = !ledon;
}
}
if (ledon != old_ledstate){
if (ledon == HIGH){
digitalWrite(ledpin, HIGH);
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("GO!");
oldtime = currenttime;
}
else {
digitalWrite(ledpin, LOW);
interval = (currenttime - oldtime)/1000.0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time:");
lcd.setCursor(0, 1);
lcd.print(interval, 2);
}
old_ledstate = ledon;
}
}