Hi everyone, didn't know if you see my post that is why I mentioned you.
@groundFungus
@Robin2
@sherzaad
@KrisKasprzak
@6v6gt
I'm using NRF24 module as RX and TX. My sketch is to control 2 dc motors via analog output through a 2 axis joystick. Everything is normal, it means I can control the speed and the direction of motors, but the problem starts when I cut the TX power off.
When I cut the TX module power off, the RX module remains ON and it sustains the last received analog signals before turning off the TX module. Subsequently the motor is still turning until I reconnect the TX power supply again. This can be so dangerous for my project cause I lift heavy weights and when the TX module is off the Rx outputs should be zero(Low) rapidly.
help if possible.
Regards.
Shahryar
Tx code:
#include <RF24.h>
#include <nRF24L01.h>
#include <SPI.h>
RF24 radio(9, 8);
const byte rxAddr[6] = "00001";
int DATA[2];
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setRetries(15, 15);
radio.openWritingPipe(rxAddr);
}
void loop()
{
DATA[0] = analogRead(A0);
DATA[1] = analogRead(A1);
Serial.print("X:"); Serial.println(DATA[0]);
Serial.print("Y:"); Serial.println(DATA[1]);
radio.write(DATA, sizeof(DATA));
//delay(1);
}
Rx:
#include <RF24.h>
#include <nRF24L01.h>
#include <SPI.h>
RF24 radio(9, 8);
const byte rxAddr[6] = "00001";
int DATA[2];
void setup() {
Serial.begin(9600);
radio.begin();
radio.setRetries(15, 15);
radio.openReadingPipe(0, rxAddr);
radio.startListening();
}
void loop() {
if (radio.available()){
radio.read(DATA, sizeof(DATA));
if (DATA[0]>570 && 1023>=DATA[0]){
int i=map(DATA[0], 570, 1023, 0, 255);
analogWrite(5, i);
analogWrite(3, 0);
}
if (DATA[0]<450 && DATA[0]>=0){
int i=map(DATA[0], 450, 0, 0, 255);
analogWrite(5, 0);
analogWrite(3, i);
}
if (DATA[0]>450 && DATA[0]<570){
int i=map(DATA[0], 451, 569, 0, 0);
analogWrite(5, 0);
analogWrite(3, 0);
}
Serial.print("X:"); Serial.println(DATA[0]);
Serial.print("Y:"); Serial.println(DATA[1]);
}
}