Go Down

Topic: NRF 24L01 RC car problem (Read 499 times) previous topic - next topic

ratm00

Hello all,

Arduino is something completely new for me. I have a project on my university to remotely control a car using 2 aruidno UNO-s and a nrf controlers. I can't understand how to send this code from one arduino to another. Do i have to put the same code on both arduinos or not? I have tried using GettingStarted from RF Libray, but I am stuck on part when i must send the code in radio.write(); i do not know what parametars to use.
Here is the thing that i have done soo far
Code: [Select]

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Servo.h>


Servo myservo; 
int pos = 90;   
int power2 = 3;
int motor_forward = 5;
int motor_back = 6;
int t = 1;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void)
{
   
  Serial.begin(57600);
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(motor_forward , OUTPUT);
  pinMode(motor_back, OUTPUT);     
  analogWrite(power2, 160); 
  myservo.attach(4);
  myservo.write(90);// attaches the servo on pin 9 to the servo object
 
}

void loop()
{

  if (t==1){
     digitalWrite(motor_forward, HIGH);
     digitalWrite(motor_back, LOW);
     delay(1000);
     digitalWrite(motor_forward, LOW);
     digitalWrite(motor_back, HIGH);
     delay(1000);
     t = 0;
  }
  else{
      for(pos = 0; pos < 180; pos += 1) 
         {                               
            myservo.write(constrain(pos,60,130));             
            delay(15);                       
         }
      for(pos = 180; pos>=1; pos-=1)     
         {                               
           myservo.write(constrain(pos,60,130));             
           delay(15);                     
         }
         t = 1;
  }
  radio.write(); 
}


Ty for help

crofter

The code you need to run on the 2 arduinos is different. The controller arduino will be sending data/commands and the car arduino will be receiving the commands and acting on them. Most of the code you have written will be for the receiving end of the link.
It is unfortunate that all the examples with rf24 are combined programs where the role is selected by the state of a pin.
If you look at led_remote for example you need to make 2 separate programs from it, one with all the role == role_remote parts deleted and the other with all the role == role_led parts deleted. You would then have the two separate programs needed for both end of the link. These could then be the basis of your two programs.

Go Up