Hi all. I am working on a robot project and need some clarification on some things before i can get back to it.
- was answered thanks. ( what was (byte*) doing.
2.am i sending this wrong if so how because every example i have checked out and all the searching and the help from PaulS points to this working.
i have the same structs on both side i am sending and receiving them exact same. how ever i am getting bad data on the RX side.
now i should mention the radio settings work fine all examples work with them so i know it's not hardware. also they would fail and not print there output on good send.
here is the output on the TX side
23.00,41.00,59.00
25.00,49.00,51.00
27.00,48.00,58.00
38.00,42.00,57.00
5.00,41.00,53.00
here is the output on the RX side
0.00,0.00,0.00,0
0.00,0.00,0.00,0
0.00,0.00,0.00,0
0.00,0.00,0.00,0
0.00,0.00,0.00,0
here are the sketches i am using
TX
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(48,49);
void setup(){
Serial.begin(57600);
//**************Start Transiever (NRF24L01) config**************
printf_begin();
printf("\n\rRadio Setup\n\r");
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.setCRCLength(RF24_CRC_16);
//radio.setPayloadSize(12 * sizeof(byte));
radio.setChannel(2);
radio.setAutoAck(true);
radio.openReadingPipe(1,0xF0F0F0F0E1LL);
radio.openWritingPipe(0xF0F0F0F0D2LL);
radio.printDetails();
//**************End Transiever (NRF24L01) config**************
}
typedef struct myBuff{
float imuRoll;
float imuPitch;
float imuYaw;
}myBuff;
myBuff StructBuff;
//**************************************************
//************* Start Main Loop section ************
//**************************************************
void loop()
{
/////////////////////////////////////////////////////////
StructBuff.imuRoll = random(1,40); //
StructBuff.imuPitch = random(41,50); //Temp Values
StructBuff.imuYaw = random(51,60); //
//
/////////////////////////////////////////////////////////
TransStruct();
radio.startListening();
}
//**************************************************
//************* END Main Loop section***************
//**************************************************
//-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+
void TransStruct(){
radio.stopListening();
bool ok = radio.write((byte *)&StructBuff, sizeof(StructBuff));
if (ok)
printbuffs();
//printf("ok...\n\r");
else
printf("failed.\n\r");
delay(10);
}
//-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+
void printbuffs(){
Serial.print(StructBuff.imuRoll);
Serial.print(",");
Serial.print(StructBuff.imuPitch);
Serial.print(",");
Serial.print(StructBuff.imuYaw);
Serial.println();
}
RX
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(8,9);
void setup(){
Serial.begin(57600);
//**************Start Transiever (NRF24L01) config**************
printf_begin();
printf("\n\rRadio Setup\n\r");
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.setCRCLength(RF24_CRC_16);
//radio.setPayloadSize(12 * sizeof(byte));
radio.setChannel(2);
radio.setAutoAck(true);
radio.openReadingPipe(1,0xF0F0F0F0D2LL);
radio.openWritingPipe(0xF0F0F0F0E1LL);
radio.printDetails();
//**************End Transiever (NRF24L01) config**************
}
typedef struct myBuff{
float imuRoll;
float imuPitch;
float imuYaw;
}myBuff;
myBuff StructBuff;
//**************************************************
//************* Start Main Loop section ************
//**************************************************
void loop()
{
RecStruct();
}
//**************************************************
//************* END Main Loop section***************
//**************************************************
//-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+
void RecStruct(){
radio.startListening();
bool ok = radio.read((byte *)&StructBuff, sizeof(StructBuff));
if (ok)
printbuffs();
// printf("ok...\n\r");
else
printf("failed.\n\r");
delay(10);
}
//-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+
void printbuffs(){
Serial.print(StructBuff.imuRoll);
Serial.print(",");
Serial.print(StructBuff.imuPitch);
Serial.print(",");
Serial.print(StructBuff.imuYaw);
Serial.println();
}