Hello
Question: How do I send individualized instructions to separate nRF24L01's receivers with a single transmitting nRF24L01?
I have a functioning project that needs some rework with the addition of a third nRF24L01, a receiver, and am not finding the proper resource for coding-in this second receiver to my transmitter sketch. Briefly, a handheld transmitter (TX) governs the direction and rate of rotation of a pair of continuous rotation servos (RX). RX is comprised of servos run by an Uno R3. RX is located opposite a single continuous rotation servo with Uno R3 (Head), some 30 feet away. Head is manually toggled, requiring a bit of a scramble at times. I would like to double, even treble, this distance (ropewalk), but need remote control of Head (even at present, with the shorter distance).
I desire to mount a second switch/potentiometer pair to my transmitter box to allow individualized control over two receiving radios.
Here's my code...
Transmitter,
//kaulaTX.ino
//Arduino Micro, nRF24L01, 9V batt, half-breadboard, stuffed into snap-top container,
//controls mounted to/protrude through lid.
//associated sketches: kaulaHead.ino & kaulaRX.ino
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW = 2; //SPST mini-toggle, ON/OFF toggle for RX servos
int POT = A0; //10k small pot, mapped value to control direction and speed of RX servos
int val = 0;
//need second SW/POT combo to control Head
void setup(void){
pinMode(SW, INPUT_PULLUP);
pinMode(POT, INPUT);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop(void){
if (digitalRead(SW) == LOW)
{
unsigned long val = analogRead(POT);
val = map(val, 0, 1023, 0, 179);
radio.write( &val, sizeof(unsigned long) );
}
else
{
unsigned long val = 90;
radio.write( &val, sizeof(unsigned long) );
}
}
Receiver,
//kaulaRX.ino
//associated sketches: kaulaTX.ino & kaulaHead.ino
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Servo.h>
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
Servo servoL;
Servo servoR;
void setup(){
servoL.attach(6);
servoR.attach(5);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop(){
if (radio.available())
{
unsigned long got_val;
bool done = false;
while (!done)
{
done = radio.read( &got_val, sizeof(unsigned long) );
servoL.write(got_val);
servoR.write(got_val);
// delay(10);
}
}
}
and Head.
//kaulaHead.ino
//associated sketches: kaulaTX.ino & kaulaRX.ino
#include <Servo.h>
Servo headServo;
int POT = A0; //small 10k pot
int SW = 2; //SPST standard toggle mounted onboard
int val = 0;
void setup()
{
headServo.attach(9);
pinMode(SW, INPUT_PULLUP);
pinMode(POT, INPUT);
}
void loop()
{
if (digitalRead(SW) == LOW)
{
unsigned long val = analogRead(POT);
val = map(val, 0, 1023, 0, 179);
headServo.write(val);
}
else
{
headServo.write(86) ;
}
}
A thorough review was made of J Coliz and Mike M resources (libraries and examples), this forum, and of course, the big G. From these resources I cobbled together the above code. My experience with programming Arduino is only months recent, so I reach out to the community for some gentle guidance in adding a second RX'er to my project.
Thanks, Mark
BTW -- My first post.