Hi!
I am trying to conrol 4 motors with a joystick remote. I have one NRF connected to a Arduino Uno with a joystick that should send the analog input to the reciver witch is a Arduino Nano with a NRF24 as reciver. The problem is that the reciver doesnt recive the value.
Here is my wiring on my transmitter:
NRF24 - Arduino Uno
CSN - D8
CE - D9
MOSI - D11
MISO - D12
SCK - D13
My reciver:
CSN - D8
CE - D9
MOSI - D11
MISO - D12
SCK - D13
My code for the transmitter:
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
// Create Radio and define pins
RF24 radio(8, 9);
// Create Radio channels
byte addresses[][6] = {"00001", "00002"};
void setup() {
Serial.begin(9600);
// Start radio communication
radio.begin();
radio.openWritingPipe(addresses[1]); // 00002
radio.openReadingPipe(1, addresses[0]); // 00001
radio.setPALevel(RF24_PA_MIN);
}
void loop() {
delay(100);
radio.stopListening();
int potValue = analogRead(A0);
int angleValue = map(potValue, 0, 1023, 0, 180);
radio.write(&angleValue, sizeof(angleValue));
Serial.println(angleValue);
}
My code for the reciver:
#include <Servo.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
// Booleans
bool gpsMode = false;
// Create GPS
TinyGPSPlus gps;
// Create Radio and define pins
RF24 radio(8, 9);
// Create Radio channels
byte addresses[][6] = {"00001", "00002"};
// Create SoftwareSerial to read TX pin. RX pin is unnecessary
SoftwareSerial ss(4, -1);
// Create Motors
Servo motor1;
Servo motor2;
Servo motor3;
Servo motor4;
void setup() {
// Declare motor pins and min/max throttle
motor1.attach(5, 1000, 2000);
motor2.attach(6, 1000, 2000);
motor3.attach(7, 1000, 2000);
motor4.attach(8, 1000, 2000);
// Calibrate motors
motor1.writeMicroseconds(1000);
motor2.writeMicroseconds(1000);
motor3.writeMicroseconds(1000);
motor4.writeMicroseconds(1000);
// Start logging
Serial.begin(9600);
ss.begin(9600);
// Start radio communication
radio.begin();
radio.openWritingPipe(addresses[0]); // 00001
radio.openReadingPipe(1, addresses[1]); // 00002
radio.setPALevel(RF24_PA_MIN);
}
void loop() {
delay(100);
// Start radio
radio.startListening();
if (radio.available()) {
while (radio.available()) {
// Throttle Controll
int angleV = 0;
radio.read(&angleV, sizeof(angleV));
Serial.println(angleV);
motor1.writeMicroseconds(angleV);
motor2.writeMicroseconds(angleV);
motor3.writeMicroseconds(angleV);
motor4.writeMicroseconds(angleV);
// GPS Mode
if (gpsMode) {
while (ss.available() > 0) {
if (gps.encode(ss.read())) {
if (gps.location.isUpdated()) {
Serial.print(gps.location.lat(), 6);
Serial.print(", ");
Serial.println(gps.location.lng(), 6);
}
}
}
}
delay(100);
}
}
delay(100);
/*
radio.stopListening();
char postValue[32] = "Return Values";
radio.write(&postValue, sizeof(postValue));
*/
}
Thanks beforehand!!!
Best regards Max