Is it possible to use one nRF24L01 transmit to two nRF24L01 receivers?
I tried it using a single unit but the second receiver didn't work reliably. I loved it by making two transmitters on different addresses. Ultimately I want to send to 6 receivers from one transmitter.
Thanks for ANY GUIDANCE.
Here is the transmit code
#include <frequencyToNote.h>
#include <MIDIUSB.h>
#include <MIDIUSB_Defs.h>
#include <pitchToFrequency.h>
#include <pitchToNote.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*
* MIDI Packet:
* Byte 1 high nibble (most significant 4 bytes): MIDI message
* Byte 1 low nibble (least significant 4 bytes): Channel number
* Byte 2: Note number or control change
* Bytes 3: Velocity or value
*/
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00666";
//const byte addresses[][6] = {"00666", "00667"};
#define MIDI_CHANNEL_1_OFF 0b10000000
#define MIDI_CHANNEL_1_ON 0b10010000
#define MIDI_SERVO_MESSAGE 0b10110000 // 0xB0 is "control change message", 0x00 is channel 1 (servo channel)
midiEventPacket_t MIDIdata, MIDIack;
void setup() {
// put your setup code here, to run once:
pinMode(5, OUTPUT); //yellow LED - turns on at Transmit
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
}
void loop() {
if (radio.available()) {
MidiUSB.flush();
}
MIDIdata = MidiUSB.read();
if (MIDIdata.header > 0) {
// A MIDI message is available
// Send the message on to all receivers on this address and let them figure it out
radio.write(&MIDIdata, sizeof(MIDIdata)); // Send the MIDI packet
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(5, LOW); // turn the LED off by making the voltage LOW
}
}
AND Here is the receiver code:
/*
* Arduino Wireless Communication Tutorial
* Example 1 - Receiver Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <MIDIUSB_Defs.h>
#include <Servo.h>
#define MIDI_SERVO_MESSAGE 0b10110000 // 0xB0 is "control change message", 0x00 is channel 1 (servo channel)
#define MIDI_LED_MESSAGE 0b10110001 // 0xB0 is "control change message", 0x01 is channel 2 (LED channel)
Servo dowser; // create servo object to control a servo
Servo balldrop; // create servo object to control a servo
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00666";
midiEventPacket_t MIDIdata;
void setup() {
pinMode(5, OUTPUT); //Dowser LED Green
pinMode(3, OUTPUT); //Dowser LED Red
pinMode(6, OUTPUT); //Ball Drop LED
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.startListening();
dowser.attach(9); // attaches the servo on pin 9 to the servo object
dowser.write(90);
balldrop.attach(4); // attaches the servo on pin 9 to the servo object
balldrop.write(90);
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(6, LOW);
}
void loop() {
if (radio.available()) {
radio.read(&MIDIdata, sizeof(MIDIdata));
if (MIDIdata.byte1 == MIDI_SERVO_MESSAGE) {
// This is a control change message for the first channel (channel 1 in QLab)
if (MIDIdata.byte2 == 1) {
// This is a control change message on the first channel for the first device
// We map the MIDI value/velocity range (0 to 127) to the servo's range (0 to 180 degrees)
dowser.write(map(MIDIdata.byte3, 0, 127, 0, 180));
digitalWrite(3, LOW); // turn the Red LED on Pin 3 OFF
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for a second
digitalWrite(5, LOW); // turn the LED off by making the voltage LOW
} else if (MIDIdata.byte2 == 2) {
dowser.write(map(MIDIdata.byte3, 0, 127, 0, 180));
digitalWrite(3, HIGH); // turn the Red LED on Pin 3 ON (HIGH is the voltage level)
} else if (MIDIdata.byte2 == 3) {
// This is a control change message on the first channel for the third device
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level)
balldrop.write(map(MIDIdata.byte3, 0, 127, 0, 180));
delay(5000); // wait for a second
digitalWrite(6, LOW); // turn the LED off by making the voltage LOW
}
} else if (MIDIdata.byte1 == MIDI_LED_MESSAGE) {
if (MIDIdata.byte2 == 1) {
if (MIDIdata.byte3 == 1) {
// start LED sequence
} else if (MIDIdata.byte3 == 0) {
// stop LED sequence
}
}
}
// Send acknowledgement back to the PC so we know the message was received
//sendAck(MIDIdata);
}
}
