WP_20160207_16_04_35_Pro_LI.jpg (1958734Bytes)
Hi,
I am building a Project which targets to:
Driving the Car with Steering Wheel connected to PC.
PC connected to Arduino which will transmit the Steering wheel commands to other Arduino via NRF24L01 modul.
On Car Side:
I will use two Arduino Cards,
- one for motorshield connection,
- one for NRF24L01 connection.
Arduino with NRF24L01 will be master, and Arduino with motorshild will be slave with I2C connection.
Currently i manage to send data and receive properly, the RC car that i will use has a DC steering control (with all left and all right, no precision position),
i bought one CHEAP servo to replace it. I connected the servo to RX part and control it via the steering wheel.
But it works with 1 sec delay. If i disable the servo, i can see the commands appearing on RX side like real time. but when i connect the servo, it slows down. can it be related to servo quality ?
I haven't attached the second Arduino yet for motorol control, just was checking servo control for now.
Any suggestion help will be very wellcome for delay problem.
My Code on RX part is as follows:
#include <VarSpeedServo.h>
#include <SPI.h>
#include <RF24.h>
#define led 3
#define RF_CS 9
#define RF_CSN 10
RF24 radio(RF_CS, RF_CSN);
const uint64_t pipes[2] = { 0xe7e7e7e7e7LL, 0xc2c2c2c2c2LL }; // paralel veri yolu adresleri
bool done = false;
VarSpeedServo myservo;
int pos = 0;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
radio.begin();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1, pipes[0]);
radio.startListening();
radio.printDetails();
pinMode(1, OUTPUT);
myservo.attach(7); //analog pin 0
}
void loop() {
if (radio.available()) {
int Komut;
int Value;
radio.read( &Komut, sizeof(int) );
Serial.print("Incoming Command: ");
Serial.println(Komut);
if (Komut < 4000) // Steering Wheel Command
{
int X = Komut - 2000; //Serial.println(X);
if (abs(X) > 30) // Avoid small steering wheel commands.
{
int stepX = map(X, -1000, 1000, 0, 180);
Serial.print("Servo Command send: ");
Serial.println(stepX);
myservo.write(stepX, 255, false);
// step, speed (1--255), wait for action to finish
}
}
Komut = 0;
}
}