So I should print radio.read() function to check if communication is okey?
yes. here:
// 8 Channel Receiver | 8 Kanal Alıcı
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
int ch_width_1 = 0;
int ch_width_2 = 0;
int ch_width_3 = 0;
int ch_width_4 = 0;
int ch_width_5 = 0;
int ch_width_6 = 0;
int ch_width_7 = 0;
int ch_width_8 = 0;
Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
Servo ch5;
Servo ch6;
Servo ch7;
Servo ch8;
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
byte aux3;
byte aux4;
} data;
unsigned long lastRecvTime = 0;
const byte pipeIn[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(9, 10);
void ResetData() {
data.throttle = 0;
data.roll = 127;
data.pitch = 127;
data.yaw = 127;
data.aux1 = 0; // Define the inicial value of each data input. | Veri girişlerinin başlangıç değerleri
data.aux2 = 0;
data.aux3 = 0;
data.aux4 = 0;
}
void setup() {
// Set the pins for each PWM signal | Her bir PWM sinyal için pinler belirleniyor.
Serial.begin(9600);
ch1.attach(0);
ch2.attach(2);
ch3.attach(3);
ch4.attach(4);
ch5.attach(5);
ch6.attach(6);
ch7.attach(7);
ch8.attach(8);
ResetData(); // Configure the NRF24 module | NRF24 Modül konfigürasyonu
radio.begin();
radio.openReadingPipe(1, pipeIn);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS); // The lowest data rate value for more stable communication | Daha kararlı iletişim için en düşük veri hızı.
radio.setPALevel(RF24_PA_MAX); // Output power is set for maximum | Çıkış gücü maksimum için ayarlanıyor.
radio.startListening(); // Start the radio comunication for receiver | Alıcı için sinyal iletişimini başlatır.
}
void recvData() {
radio.read(&data, sizeof(Signal));
Serial.println("something is arrived");
lastRecvTime = millis();
}
void loop() {
if ( radio.available() )recvData();
if ( millis() - lastRecvTime > 1000)ResetData();
ch_width_1 = map(data.roll, 0, 255, 1000, 2000);
ch_width_2 = map(data.pitch, 0, 255, 1000, 2000);
ch_width_3 = map(data.throttle, 0, 255, 1000, 2000);
ch_width_4 = map(data.yaw, 0, 255, 1000, 2000);
ch_width_5 = map(data.aux1, 0, 255, 1000, 2000);
ch_width_6 = map(data.aux2, 0, 255, 1000, 2000);
ch_width_7 = map(data.aux3, 0, 1, 1000, 2000);
ch_width_8 = map(data.aux4, 0, 1, 1000, 2000);
// Write the PWM signal | PWM sinyaller çıkışlara gönderiliyor
ch1.writeMicroseconds(ch_width_1);
ch2.writeMicroseconds(ch_width_2);
ch3.writeMicroseconds(ch_width_3);
ch4.writeMicroseconds(ch_width_4);
ch5.writeMicroseconds(ch_width_5);
ch6.writeMicroseconds(ch_width_6);
ch7.writeMicroseconds(ch_width_7);
ch8.writeMicroseconds(ch_width_8);
}
if number increasing then payload comes good thru
gives an error
Compilation error: invalid operands of types 'uint16_t {aka unsigned int}' and 'void' to binary 'operator+'
Compilation error: void value not ignored as it ought to be
i don't understand, in github stay written .read() gives boolean back, but my compiler say it is void.
bool RF24::read ( void * buf, uint8_t len ) Read the payload.
Return the last payload received
The size of data read is the fixed payload size, see getPayloadSize()
Note:
I specifically chose 'void*' as a data type to make it easier for beginners to use. No casting needed.Parameters:
buf Pointer to a buffer where the data should be written len Maximum number of bytes to read into the buffer Returns:
True if the payload was delivered successfully false if not
i see, it is from 2012.
so now you can't quick check if data is arrived good, data must be read and then examined.
UPD post #22 adopted
I think you look at the wrong Github page.
https://nrf24.github.io/RF24/classRF24.html#a8e2eacacfba96426c192066f04054c5b
Why?
Ive changed the code as below and this code prints 240. So the main code has an if statement that has resetdata function in it that resets data if a certain time past. Reseted data.pitch has to be 127 but this code print 240. Does that mean the data is received. Btw I didnt connect a joystick to transmitter.
void recvData() {
radio.read(&data, sizeof(Signal));
Serial.println(data.pitch);
delay(250);
lastRecvTime = millis();
}
I dont know Ive found the code from a rc hobby blog
Get rid of radio.setAutoAck(false);.
The devices are able to automatically retry,
and you get a chance to check for successful transmission,
if you let it sit at true.
There is no place for any delay in a communication program.
if nothing connected then analogRead work as antenna and gives randomly values back, so yes, it mean data is correct arraive
It was just for to slow down the serial monitor
Moderate the transmitter instead of delaying the receiver.
Autoack is enabled by default it is enough to just delete the False part right?
Yes.
With that call, write will return true always, because it has no way of telling if someone received it.
Ive been thinking that so that was the reason. Thanks a lot !
Thanks a lot for your help
![]()
type casting was the problem
you recieves now even without acknowledgement
Can you explain what you mean I couldnt get it
you has tried to send 16 bytes and receiving only 8. that was issue.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
