3

I did a search on the meaning of RX and TX and it seems TX means sending data and RX means receiving data. So when my transmitter is turned off, my receiver looks like this and it works with a battery:

enter image description here

and when I turn on the transmitter my receiver looks like this:

enter image description here

So Tx is blinking and I'm confused, because Rx is not blinking and I think I receive nothing.

receiver code:

#include <RF24.h> 
#include <SPI.h> 

int speedpin1=5;
int dir11=3;
int dir12=7;

int speedpin2=A4;
int dir21=8;
int dir22=A3;

int speedpin3=A2;
int dir31=A1;
int dir32=A0;

int speedpin4=2;
int dir41=4;
int dir42=6;

int mspeed;


const byte CE = 9;
const byte CS = 10;

int data[1];

RF24 Radio(CE,CS);
const byte address[6]="00001";


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);  
pinMode(speedpin1,OUTPUT);
pinMode(dir11,OUTPUT);
pinMode(dir12,OUTPUT);

pinMode(speedpin2,OUTPUT);
pinMode(dir21,OUTPUT);
pinMode(dir22,OUTPUT);

pinMode(speedpin3,OUTPUT);
pinMode(dir31,OUTPUT);
pinMode(dir32,OUTPUT);
 
pinMode(speedpin4,OUTPUT);
pinMode(dir41,OUTPUT);
pinMode(dir42,OUTPUT);

Radio.begin();
Radio.openReadingPipe(1,address);
Radio.startListening();
}

void loop() {
  // put your main code here, to run repeatedly:
if(Radio.available()){
  Radio.read(data,sizeof(data));
  if (data[0]>131){
    
    digitalWrite(dir41,LOW);
    digitalWrite(dir42,HIGH);
    
    analogWrite(dir31,0);
    analogWrite(dir32,255);
     
    digitalWrite(dir21,HIGH);
    analogWrite(dir22,0);
      
    digitalWrite(dir11,HIGH);
    digitalWrite(dir12,LOW);
    
    mspeed=255;
 
    analogWrite(speedpin1,mspeed);
    analogWrite(speedpin2,mspeed);
    analogWrite(speedpin3,mspeed);
    analogWrite(speedpin4,mspeed);    
    Serial.println(mspeed);
    
  
  } 
  if (data[0]<131){

    digitalWrite(dir41,HIGH);
    digitalWrite(dir42,LOW);    

    analogWrite(dir31,255);
    analogWrite(dir32,0);

    digitalWrite(dir21,LOW);
    analogWrite(dir22,255);    
      
    digitalWrite(dir11,LOW);
    digitalWrite(dir12,HIGH);
    
    mspeed=255;
    
    analogWrite(speedpin1,mspeed);
    analogWrite(speedpin2,mspeed);
    analogWrite(speedpin3,mspeed);
    analogWrite(speedpin4,mspeed);
    Serial.println(mspeed);
   
     
  }
  if (data[0]==131){
     
 
    mspeed=0;
    analogWrite(speedpin1,mspeed);
    analogWrite(speedpin2,mspeed);
    analogWrite(speedpin3,mspeed);
    analogWrite(speedpin4,mspeed);
    Serial.println(mspeed);
    
     
  } 
  
 

}

transmitter code:

#include <RF24.h> 
#include <SPI.h> 
const byte CE = 9;
const byte CS = 10;
int jpin=A0;
int datax;
int data[1];

RF24 Radio(CE,CS);
const byte address[6]="00001";
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
Radio.begin();
Radio.setRetries(5,10);
Radio.openWritingPipe(address);
}

void loop() {
  // put your main code here, to run repeatedly:
datax=analogRead(jpin);
datax=map(datax, 0, 1023, 0, 255);
data[0]=datax;
Serial.print("data x: ");
Serial.println(data[0]);
Radio.write(data,sizeof(data));
 
 


}

I'm using nRF2401 and in my transmitter and my receiver the Rx is not blinking and Tx is blinking; why does Rx not blinking?

I also don't know that why does Tx in my receiver not blinking when I move the joystick in my transmitter.

I can control my motors only a few times with a Joystick and after that the Tx in my receiver does not blink and then my motors are keep working or they stop and I can't control them.


Edit

enter image description here

7
  • don't pay attention to lights ... examine the transmitted data and examine the received data ... if the data is the same, then your devices are operational
    – jsotola
    Commented Aug 29, 2022 at 15:24
  • why did you delete your previous question and added this one? ... the two are almost the same ... if you want to make changes then edit your question instead
    – jsotola
    Commented Aug 29, 2022 at 15:34
  • you are making things difficult for yourself ... add debugging code, so that you know what is being transmitted, what is being received, and how the received data is being decoded
    – jsotola
    Commented Aug 29, 2022 at 15:39
  • 1
    How do you connect your nRF2401 and Arduino Nano? A circuit diagram would help to confirm whether the connection is correct or not as the first step of debugging.
    – hcheung
    Commented Aug 30, 2022 at 7:55
  • @hcheung I added the information you asked for to my question.
    – dagh
    Commented Aug 30, 2022 at 9:55

1 Answer 1

1

We've got multiple questions here, so:

Why is TX/RX blinking weirdly?

The RX and TX LEDs on the Arduino Nano are connected to the RX0 and TX1 pins: they show activity on the Serial-over-USB port that connects your Arduino to the PC.

So, every time you receive data, you do a Serial.print(), transmitting text to the PC (where you can see that text in the Serial monitor). And that is what's showing up in the RX/TX LEDs: the text you send over the serial line to the PC. If you want to get RX blinking in this setup, just enter some text in the Serial monitor's input box and send it. The TX LED should blink shortly, then (maybe too short to be noticeable).

Reusing those LEDs to show activity on the wireless transceiver by writing to the RX0/TX1 pins would mean that you'll lose the Serial monitor, i.e. Serial.print() would no longer be possible. Not recommended.

Your best option would be to introduce your own LEDs as an activity monitor. Just add an LED in series with an 1K resistor to pins D11 and D12 each (which are the MOSI and MISO lines of the SPI interface, i.e. the equivalent of RX and TX of a serial interface).

In other words, add these components:

  D11 --> -LED+ --> 1K resistor --> 5V
  D12 --> -LED+ --> 1K resistor --> 5V

Why does my transmission stop?

That's harder to see, but: I think you're using the RF24 library interface wrong.

According to the code example "Transmitter Lv2" on this page, Radio.read() and Radio.write() expect a reference to the data array, so you'd need to use Radio.read(&data, sizeof(data)) and Radio.write(&data, sizeof(data)) (note the ampersands).

It also may be that your transmitter is transmitting faster than your receiver can accept data, so you could try and add a delay(5) in the loop() of your transmitter.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.