Hello everybody
im making a plane using 2 servos for steering and one brusless motor.
i have 2 UNOs one as transmitter the other as reveiver and they are communicating via Rf24 modules.
when i check values sent from transmitter on serial monitor they are perfect but when i check them on receiver side there are two zeros sent between every value which probably won't let my esc work
Transmitter code
int value = 0; // set values you need to zero
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led 12
RF24 radio(7, 8); // CNS, CE
const byte addresses[][6] = {"00001", "00002"};
boolean buttonState = 0;
#define MAX_SIGNAL 2100
#define MIN_SIGNAL 700
void setup() {
pinMode(12, OUTPUT);
radio.begin();
radio.openWritingPipe(addresses[1]); // 00001
radio.openReadingPipe(1, addresses[0]); // 00002
radio.setPALevel(RF24_PA_MIN);
Serial.begin(115200);
}
void loop() {
delay(5);
radio.stopListening();
int potValue = analogRead(A0);
int angleValue = map(potValue, 0, 1023, 0, 180);
radio.write(&angleValue, sizeof(angleValue));
int potValue1 = analogRead(A1);
int angleValue1 = map(potValue1, 0, 1023, 0, 180);
radio.write(&angleValue1, sizeof(angleValue1));
int potValue2 = analogRead(A2);
int angleValue2 = map(potValue2, 0, 1023, MIN_SIGNAL, MAX_SIGNAL);
radio.write(&angleValue2, sizeof(angleValue2));
if(Serial.available())
value = Serial.parseInt(); // Parse an Integer from Serial
Serial.println(angleValue2);
}
Receiver code
int value = 0; // set values you need to zero
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define button 4
RF24 radio(7, 8); // CNS, CE
const byte addresses[][6] = {"00001", "00002"};
Servo myServo;
Servo myServo1;
Servo firstESC;
boolean buttonState = 0;
void setup() {
pinMode(button, INPUT);
myServo.attach(5);
myServo1.attach(6);
firstESC.attach(9);
radio.begin();
radio.openWritingPipe(addresses[0]); // 00002
radio.openReadingPipe(1, addresses[1]); // 00001
radio.setPALevel(RF24_PA_MIN);
Serial.begin(115200);
}
void loop() {
delay(5);
radio.startListening();
if ( radio.available()) {
while (radio.available()) {
int angleV = 0;
radio.read(&angleV, sizeof(angleV));
myServo.write(angleV);
int angleV1 = 0;
radio.read(&angleV1, sizeof(angleV1));
myServo1.write(angleV1);
int angleV2 = 0;
radio.read(&angleV2, sizeof(angleV2));
firstESC.writeMicroseconds(angleV2);
if(Serial.available())
value = Serial.parseInt();
Serial.println(angleV2);
}
}
}
one of my suggestion is that the receiver ignores all 0 values for the variable "angleV2" and replace them with the last value received but since im beginner in arduino i didnt know how to do it
Any help will be very appreciated sorry for the long post or mistakes this is my first post in a forum
thank you guys in advance
