Hi my goal is to use the controller to control two separate RF Nanos simultaneously, each in turn controlling their own separate ESC and BLDC. I managed to get it the control and remote to work with one board, but when I upload the same code to another board, nothing happens, the BLDC simply beeps at a high rate. I did research to find info and it stated that I needed to create new pipes for a second receiver but I'm lost. I followed this for the bones of the project
Initially that did not work, I read the the RF nano had the CE and CSN pins switched so I swapped that and it worked for the instructables as intended with the exception that the motor with the joystick in the middle position is spinning pretty fast instead of at a stop. Im not sure how to change this either, but I assume it has something to do with my ESC not being able to reverse until I reprogram it. I am waiting for the reprogramming card to arrive.
I made 3 changes to the transmitter code:
/* Transmitter code for the Skateboard Radio control with PWM output
Module // Arduino UNO,NANO
GND -> GND
Vcc -> 3.3V
CE -> D9
CSN -> D10
CLK -> D13
MOSI -> D11
MISO -> D12
Consider like share and subscribe : https://www.youtube.com/NematicsLab
*/
#include <SPI.h>
#include <nRF24L01.h> //https://github.com/nRF24/RF24
#include <RF24.h>
const uint64_t my_radio_pipe = 0x12345ABC;
// 1. ADDED A SECOND PIPE **************************************************
const uint64_t my_radio_pipe2 = 0x12345ABD;
// 2. SWAPPED (9, 10) TO (10, 9) **************************************************
RF24 radio(10, 9); //Set CE and CSN pins
struct Data_to_be_sent {
byte ch1;
byte ch2;
};
Data_to_be_sent sent_data;
void setup()
{
pinMode(2,INPUT_PULLUP);
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(my_radio_pipe);
// 3. ADDED THE SECOND PIPE HERE **************************************************
radio.openWritingPipe(my_radio_pipe2);
//Reset each channel value
sent_data.ch1 = 127;
sent_data.ch2 = 1;
}
/**************************************************/
void loop()
{
sent_data.ch1 = map( analogRead(A0), 0, 1024, 0, 255);
sent_data.ch2 = digitalRead(2);
radio.write(&sent_data, sizeof(Data_to_be_sent));
}
I also made 3 changes to the receiver code:
tr/* Receiver code for the Skateboard Radio control with PWM output
Module // Arduino UNO,NANO
GND -> GND
Vcc -> 3.3V
CE -> D9
CSN -> D10
CLK -> D13
MOSI -> D11
MISO -> D12
Consider like share and subscribe : https://www.youtube.com/NematicsLab
*/
#include <SPI.h>
#include <nRF24L01.h> //https://github.com/nRF24/RF24
#include <RF24.h>
#include <Servo.h>
int dela;
int Mode;
const uint64_t pipeIn = 0x12345ABC;
// 1. ADDED BELOW **************************************************
const uint64_t pipeIn2 = 0x12345ABD;
// 2. (9, 10) to (10, 9) **************************************************
RF24 radio(10, 9); //CSN and CE pins
struct Received_data {
byte ch1;
byte ch2;
};
Received_data received_data;
Servo channel_1;
int ch1_value = 0;
int ch2_value = 0;
void reset_the_Data()
{
received_data.ch1 = 128; //Throttle (channel 1) to 0
received_data.ch2 = 0;
}
/**************************************************/
void setup()
{
channel_1.attach(5);
dela=1552;
reset_the_Data();
Serial.begin(9600);
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,pipeIn);
// 3. ADDED. **************************************************
radio.openReadingPipe(2,pipeIn2);
radio.startListening();
}
unsigned long lastRecvTime = 0;
void receive_the_data()
{
while ( radio.available() ) {
radio.read(&received_data, sizeof(Received_data));
lastRecvTime = millis();
}
}
void loop()
{
//Receive the radio data
receive_the_data();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
reset_the_Data();
}
ch2_value =received_data.ch2;
if(ch2_value==0)
{
Mode=1;
}
if(ch2_value==1)
{
Mode = 0;
}
//Creathe the PWM signals
//Pro Mode
if(Mode == 1)
{
ch1_value = map(received_data.ch1,0,255,1100,2000);
if(dela<ch1_value && dela < 2000)
{
dela++;
channel_1.writeMicroseconds(dela);
Serial.println(dela);
delay(10);
}
if(dela>ch1_value)
{
dela--;
channel_1.writeMicroseconds(dela);
Serial.println(dela);
}
}
//Noob Mode
if(Mode==0)
{
ch1_value = map(received_data.ch1,0,255,1300,1820);
if(dela<ch1_value && dela < 1570){
dela++;
channel_1.writeMicroseconds(dela);
Serial.println(dela);
}
if(dela<ch1_value && dela < 1685){
dela++;
channel_1.writeMicroseconds(dela);
Serial.println(dela);
delay(20);
}
if(dela<ch1_value && dela < 1850){
dela++;
channel_1.writeMicroseconds(dela);
Serial.println(dela);
delay(12);
}
if(dela>ch1_value){
dela--;
channel_1.writeMicroseconds(dela);
Serial.println(dela);
}
}
}//Loop end