Hi, I am very new to forum so excuse me if I don't give enough information and / or give it on the wrong way. I am working on a hobby project which is trying to make a remote control car using the nrf24l01 modules.
When I first attempted to start this project I was experimenting with the modules and couldn't get them to work for a while. Finally I discovered a faulty wire and got them to work, which led me to progress with the creation of the car its self.
I have worked on the car significantly and during testing the connection between the car and remote suddenly stopped working. For an hour or so I could get them to work by fiddling around with the wires but I have now hit a point where I can't get them to work ever.
I have been looking through the countless forms about this module and applying the solutions what worked for other people, but I can't seam to get it to work again.
One thing that I noticed that may are may not have an effect is that the 3.3v power supply pin on the Arduino uno (which is what I am using for the car and controller) is putting out close to 4 volts. I am not sure whether or not that would have an effect on the overall connection.
Below is the code for the remote (transmitting end):
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1;
int joystickX;
int joystickY;
const int rSWpin = 2;
const int rXpin = 0;
const int rYpin = 1;
const int lSWpin = 4;
const int lXpin = 2;
const int lYpin = 3;
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.setAutoAck(true);
radio.setRetries(0, 15);
radio.openWritingPipe(address);
radio.stopListening();
pinMode(rSWpin, INPUT);
digitalWrite(rSWpin, HIGH);
pinMode(lSWpin, INPUT);
digitalWrite(lSWpin, HIGH);
}
void loop() {
joystickX = analogRead(rXpin);
joystickY = analogRead(lYpin);
currentMillis = millis();
if(currentMillis - prevMillis >= txIntervalMillis)
{
send();
prevMillis = millis;
}
if(!radio.write(&joystickX,sizeof(joystickX)))
{
Serial.println(F("communication failed."));
}
}
void send()
{
radio.write(&joystickX, sizeof(joystickX));
radio.write(&joystickY, sizeof(joystickY));
Serial.print("Joystick X: ");
Serial.println(joystickX);
Serial.print("Joystick Y: ");
Serial.println(joystickY);
}
And here is the code for the car (receiving end):
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
int joystickX = 0;
int joystickY = 0;
const int forwardPin = 2;
const int backwardPin = 4;
const int lSpeedOut = 5;
const int rSpeedOut = 3;
int lSpeed;
int lSpeedF;
int rSpeed;
int rSpeedF;
float lrOffset;
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1, address);
radio.startListening();
pinMode(forwardPin, OUTPUT);
pinMode(lSpeedOut, OUTPUT);
pinMode(rSpeedOut, OUTPUT);
pinMode(backwardPin, OUTPUT);
}
void loop()
{
if (radio.available())
{
radio.read(&joystickX, sizeof(joystickX));
radio.read(&joystickY, sizeof(joystickY));
/*Serial.print("Joystick X: ");
Serial.println(joystickX);
Serial.print("Joystick Y: ");
Serial.println(joystickY);*/
if(joystickY < 511)
{
MoveBackward();
}
else if(joystickY == 511)
{
DontMove();
}
else if(joystickY > 511)
{
MoveForward();
}
if(joystickX < 511)
{
lrOffset = joystickX / 511.5;
lSpeedF = lSpeed * lrOffset;
rSpeedF = rSpeed;
}
else if(joystickX == 511)
{
lrOffset = 1;
lSpeedF = lSpeed;
rSpeedF = rSpeed;
}
else if(joystickX > 511)
{
lrOffset = 1 - (joystickX / 511.5) + 1;
lSpeedF = lSpeed;
rSpeedF = rSpeed * lrOffset;
}
Serial.print("LR Offest: ");
Serial.println(lrOffset);
lSpeed = map(joystickY, 0, 1023, -255, 255);
rSpeed = map(joystickY, 0, 1023, -255, 255);
}
}
void MoveForward()
{
if(radio.available())
{
digitalWrite(forwardPin, HIGH);
digitalWrite(backwardPin, LOW);
analogWrite(lSpeedOut, lSpeedF);
analogWrite(rSpeedOut, rSpeedF);
}
}
void MoveBackward()
{
if(radio.available())
{
digitalWrite(forwardPin, LOW);
digitalWrite(backwardPin, HIGH);
analogWrite(lSpeedOut, -lSpeedF);
analogWrite(rSpeedOut, -rSpeedF);
}
}
void DontMove()
{
if(radio.available())
{
digitalWrite(forwardPin, HIGH);
digitalWrite(backwardPin, HIGH);
}
}
Any help would be greatly appreciated as I am trying to get this project done before I start school again.
Thankyou for helping.