Show Posts
|
|
Pages: [1] 2 3 ... 7
|
|
1
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 10, 2013, 07:07:13 pm
|
From the post I made here http://arduino.cc/forum/index.php/topic,146500.msg1102005.html#msg1102005There is a function called: isAvailable() It possibly returns the number of bytes available, or maybe just a true/false, anyway check it out. Edit, these two functions below tell me that the data is 'payload' size, if the data you put in it is smaller it will be padded upto 'payload' size: I do not quite understand what your trying to get me to do with the payload size. i define payload size at the size of StructBuff so no matter what size StructBuff is payload is always the size of it. How ever it seems there might be an "overflow" issue with it given what Tack said. Unless it auto breaks up the payload and sends them in pieces if that is the case i dont know how the struct on the RX will like that. this is all new territory for me michinyon wrote: Your RX code is also wrong.
When you have radio.available() true, you do not necessarily have a full struct of bytes available.
If your struct is 50 bytes ( whatever ) and your radio serial port has received 20 bytes, then radio.available() will be true and you will attempt to read 50 bytes and there is only 20 bytes received so far and your data will therefore be wrong in some way.
You need to not attempt to read() the data until it is all there. Or else read the data which you have and then wait for the rest to arrive.
and i cheked it comes back true if there is payload. but as Tack pointed out. The max payload size will be 32 bytes IIRC. Once you fix your string issue you need to make sure a single payload doesn't exceed that or it will be truncated.
When using the RF24Network library it uses 12 bytes for the header so that leaves only 20 bytes for the rest of the payload, something that took a while to realize. i am going to need to figure out how to break down my block of data to smaller ones so it does not get truncated before i even continue trying to send any more data the 3 floats from my IMU are already to much data at 24 bytes.
|
|
|
|
|
2
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 08, 2013, 09:58:12 am
|
When you have radio.available() true, you do not necessarily have a full struct of bytes available.
I think you're mistaken about how the RF24 library works. This is not a streaming interface; the radio sends and receives complete packets and returns the whole packet via a single read operation. right get that part but how do i tell if the packet is complete so i can read it. or is simply calling radio.read() doing that?
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 06, 2013, 12:11:41 pm
|
had never used .setRetries it before and saw it in a demo and looked it up on github had not saw the last statement about 15 max. i did setup the radios like the pingpair example and they failed %100 of the time. it's a packet size issue so i had to change the packets and if i dont have * sizeof(byte) in there it fails. so as it stands only thing that works for the following sketchs is. SetpayloadSize(20 * sizeof(byte)); {anything above 20 works so 21 22 23 24} 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.setRetries(15,15); radio.setDataRate(RF24_2MBPS); radio.setCRCLength(RF24_CRC_16); radio.setPayloadSize(24 * sizeof(byte)); radio.setChannel(100); radio.setAutoAck(true); radio.openReadingPipe(1,0xF0F0F0F0E1LL); radio.openWritingPipe(0xF0F0F0F0D2LL); radio.stopListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct StructBuff_t { float imuRoll; float imuPitch; float imuYaw; unsigned int AP; } StructBuff; //************************************************** //************* Start Main Loop section ************ //**************************************************
void loop() { float roll = random(-150,150); float pitch = random(-150,150); float yaw = random(0,360); unsigned int ap = random(0,75);
StuffStructBuff(roll,pitch,yaw,ap); TransStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void TransStruct(){ 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.print(","); Serial.print(StructBuff.AP); Serial.println(); } void StuffStructBuff(float inRoll, float inPitch, float inYaw, unsigned int inAP){//**Working** StructBuff.imuRoll = inRoll; StructBuff.imuPitch = inPitch; StructBuff.imuYaw = inYaw; StructBuff.AP = inAP; }
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.setRetries(15,15); radio.setDataRate(RF24_2MBPS); radio.setCRCLength(RF24_CRC_16); radio.setPayloadSize(24 * sizeof(byte)); radio.setChannel(100); radio.setAutoAck(true); radio.openReadingPipe(1,0xF0F0F0F0D2LL); radio.openWritingPipe(0xF0F0F0F0E1LL); radio.startListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct StructBuff_t { float imuRoll; float imuPitch; float imuYaw; unsigned int AP; } StructBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { RecStruct(); }
//************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void RecStruct(){ if ( radio.available() ) { 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.print(","); Serial.print(StructBuff.AP); Serial.println();
}
TX output -127.00,-41.00,0.00,65 failed. -23.00,79.00,160.00,37 failed. failed. -34.00,85.00,97.00,26 failed. -71.00,-101.00,99.00,21 failed. 35.00,95.00,308.00,16 failed. 58.00,94.00,28.00,65 failed. -128.00,16.00,189.00,74 failed.
RX -127.00,-41.00,0.00,65 -23.00,79.00,160.00,37 -34.00,85.00,97.00,26 -71.00,-101.00,99.00,21 35.00,95.00,308.00,16 58.00,94.00,28.00,65 -128.00,16.00,189.00,74
so size of the struct is 20 it seems. as for the timing man it's slow bout 1.5 updates per sec was hoping for 3 or 4 per sec.
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 05, 2013, 05:45:15 pm
|
I checked my hardware after i was just gunna say yeah i can use the examples and noticed the connector i made was not holding tight to the NRF so i swaped out for a new one on my UNO and ran ping and worked fine. changing delay(10) will fail transmit/rec both even (11) or no delay. the 5,1000 was from trying to achieve less fail by telling it not to retransmit more than 5 times and wait 1 sec in between tries. TX (uno) Now sending 87...ok...Got response 87, round-trip delay: 24 Now sending 1112...ok...Got response 1112, round-trip delay: 22 Now sending 2135...ok...Got response 2135, round-trip delay: 21 Now sending 3158...ok...Got response 3158, round-trip delay: 21 Now sending 4179...ok...Got response 4179, round-trip delay: 23 Now sending 5202...ok...Got response 5202, round-trip delay: 23
RX(Mega2560) Got payload 87...Sent response. Got payload 1112...Sent response. Got payload 2135...Sent response. Got payload 3158...Sent response. Got payload 4179...Sent response. Got payload 5202...Sent response.
so i got excited and tried the old code. but when i got back to the previous TX/RX code it is choppy send/rec and some fails. also if i chage it to even 11ms much less 1000 it is %100 fail agin. Full code as it sits. #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(14 * sizeof(byte)); // radio.setChannel(80); radio.setAutoAck(true); // radio.setRetries(15,15); radio.openReadingPipe(1,0xF0F0F0F0E1LL); radio.openWritingPipe(0xF0F0F0F0D2LL); radio.stopListening(); radio.printDetails();
//**************End Transiever (NRF24L01) config************** } struct imuBuff_t{ float imuRoll; float imuPitch; float imuYaw; } imuBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { ////////////////////////////// imuBuff.imuRoll = 31.99; // imuBuff.imuPitch = -150.82; //Temp Values imuBuff.imuYaw = 3.60; // ////////////////////////////// TransStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void TransStruct(){
bool ok = radio.write((byte *) &imuBuff, sizeof(imuBuff)); if (ok) printbuffs(); else printf("failed.\n\r"); delay(10); } //-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+ void printbuffs(){ Serial.print(imuBuff.imuRoll); Serial.print(","); Serial.print(imuBuff.imuPitch); Serial.print(","); Serial.print(imuBuff.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(14 * sizeof(byte)); // radio.setChannel(80); radio.setAutoAck(true); //radio.setRetries(15,15); radio.openReadingPipe(1,0xF0F0F0F0D2LL); radio.openWritingPipe(0xF0F0F0F0E1LL); radio.startListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct IMU_t{ float imuRoll; float imuPitch; float imuYaw; } imuBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { imuBuff.imuRoll = 0; imuBuff.imuPitch = 0; imuBuff.imuYaw= 0; RecStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void RecStruct(){ if ( radio.available() ) { bool ok = radio.read((byte *)&imuBuff, sizeof(imuBuff)); if (ok) printbuffs(); else printf("failed.\n\r"); } delay(10);
} //-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+ void printbuffs(){ Serial.print(imuBuff.imuRoll); Serial.print(","); Serial.print(imuBuff.imuPitch); Serial.print(","); Serial.print(imuBuff.imuYaw); Serial.println(); }
TX failed. 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 failed. 31.99,-150.82,3.60 failed. 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 failed. 31.99,-150.82,3.60 31.99,-150.82,3.60 failed. failed. 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 failed. 31.99,-150.82,3.60 31.99,-150.82,3.60 failed. failed. failed. 31.99,-150.82,3.60
RX 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60 31.99,-150.82,3.60
|
|
|
|
|
6
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 05, 2013, 12:58:58 pm
|
%100 fail now 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_250KBPS); //radio.setCRCLength(RF24_CRC_16); //radio.setPayloadSize(14 * sizeof(byte)); //radio.setChannel(2); radio.setAutoAck(true); radio.setRetries(5,1000); radio.openReadingPipe(1,0xF0F0F0F0E1LL); radio.openWritingPipe(0xF0F0F0F0D2LL); radio.stopListening(); radio.printDetails();
//**************End Transiever (NRF24L01) config************** } struct imuBuff_t{ float imuRoll; float imuPitch; float imuYaw; } imuBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { ////////////////////////////// imuBuff.imuRoll = 31.99; // imuBuff.imuPitch = -150.82; //Temp Values imuBuff.imuYaw = 3.60; // ////////////////////////////// TransStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void TransStruct(){
bool ok = radio.write((byte *) &imuBuff, sizeof(imuBuff)); if (ok) printbuffs(); else printf("failed.\n\r"); delay(10); } //-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+ void printbuffs(){ Serial.print(imuBuff.imuRoll); Serial.print(","); Serial.print(imuBuff.imuPitch); Serial.print(","); Serial.print(imuBuff.imuYaw); Serial.println(); }
RX #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_250KBPS); //radio.setCRCLength(RF24_CRC_16); //radio.setPayloadSize(14 * sizeof(byte)); //radio.setChannel(2); radio.setAutoAck(true); radio.setRetries(5,1000); radio.openReadingPipe(1,0xF0F0F0F0D2LL); radio.openWritingPipe(0xF0F0F0F0E1LL); radio.startListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct IMU_t{ float imuRoll; float imuPitch; float imuYaw; } imuBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { imuBuff.imuRoll = 0; imuBuff.imuPitch = 0; imuBuff.imuYaw= 0; RecStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void RecStruct(){ if ( radio.available() ) { bool ok = radio.read((byte *)&imuBuff, sizeof(imuBuff)); if (ok) printbuffs(); else printf("failed.\n\r"); } delay(10);
} //-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+ void printbuffs(){ Serial.print(imuBuff.imuRoll); Serial.print(","); Serial.print(imuBuff.imuPitch); Serial.print(","); Serial.print(imuBuff.imuYaw); Serial.println(); }
|
|
|
|
|
8
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 05, 2013, 11:22:24 am
|
You don't clear the receiver buffer before doing the receive, so you will never know whether data you're seeing was actually received, or is garbage left behind from a previous message. thought that i was with the flush(). but i read they were not accessible to users they were hardware calls. so how do i go about flushing the buffer?
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 05, 2013, 08:42:05 am
|
So i took out everything unneeded and setup just a float struct to transmit and added the Start/Stop listining to the setup and flush the buffers on the TX side on fails and RX side on a sucess or fail to make sure i am always geting fresh data on the RX side. I still run into a prob with it only transmitting like the first 1 or 2 or so packets and then stops if i reset RX i "might" get a packet to take. here is my code so far. 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(14 * sizeof(byte)); radio.setChannel(2); radio.setAutoAck(true); radio.openReadingPipe(1,0xF0F0F0F0E1LL); radio.openWritingPipe(0xF0F0F0F0D2LL); radio.stopListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct imuBuff_t{ float imuRoll; float imuPitch; float imuYaw; } imuBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { ////////////////////////////// imuBuff.imuRoll = 31.99; // imuBuff.imuPitch = -150.82; //Temp Values imuBuff.imuYaw = 3.60; // ////////////////////////////// TransStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void TransStruct(){
bool ok = radio.write((byte *) &imuBuff, sizeof(imuBuff)); if (ok) printbuffs(); else printf("failed.\n\r"); uint8_t flush_tx(); delay(10); } //-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+ void printbuffs(){ Serial.print(imuBuff.imuRoll); Serial.print(","); Serial.print(imuBuff.imuPitch); Serial.print(","); Serial.print(imuBuff.imuYaw); Serial.println(); }
RX #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(14 * sizeof(byte)); radio.setChannel(2); radio.setAutoAck(true); radio.openReadingPipe(1,0xF0F0F0F0D2LL); radio.openWritingPipe(0xF0F0F0F0E1LL); radio.startListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct IMU_t{ float imuRoll; float imuPitch; float imuYaw; } imuBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { RecStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void RecStruct(){ if ( radio.available() ) { bool ok = radio.read((byte *)&imuBuff, sizeof(imuBuff)); if (ok) printbuffs(); else printf("failed.\n\r"); uint8_t flush_tx(); } delay(10);
} //-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+ void printbuffs(){ Serial.print(imuBuff.imuRoll); Serial.print(","); Serial.print(imuBuff.imuPitch); Serial.print(","); Serial.print(imuBuff.imuYaw); Serial.println(); uint8_t flush_rx(); }
Output RX side 31.99,-150.82,3.60
but just the first packet most of the time.
|
|
|
|
|
12
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 04, 2013, 10:38:06 am
|
i made the changes and out the radio calls for stop and listen into the setup like they had them in there examples and i flushed the buffers but when i added the radio.available() it worked. sort of. i only get MAX 4 loops and some times 1 or even 0 loops then i reset the RX and retry max 4 but most times less. here is my code also it's slow as hell when it does send a couple sets across like 2 sec or so.. Mirf on the other hand is sending it fine so i think i might just use RF24 to setup the radios and Mirf for Transmitting/Receiving. (resetting TX side never seems to do any good) 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(20 * sizeof(byte)); radio.setChannel(2); radio.setAutoAck(true); radio.openReadingPipe(1,0xF0F0F0F0E1LL); radio.openWritingPipe(0xF0F0F0F0D2LL); radio.stopListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct StructBuff_t { String GPS; float imuRoll; float imuPitch; float imuYaw; unsigned int AP; } StructBuff; //************************************************** //************* Start Main Loop section ************ //**************************************************
void loop() { float roll = random(-150,150); float pitch = random(-150,150); float yaw = random(0,360); String gps = "This is my RF test"; unsigned int ap = random(0,75);
StuffStructBuff(roll,pitch,yaw,ap,gps); TransStruct(); } //************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void TransStruct(){ bool ok = radio.write((byte *) &StructBuff, sizeof(StructBuff)); if (ok) printbuffs(); //printf("ok...\n\r"); else printf("failed.\n\r"); uint8_t flush_tx(); 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.print(","); Serial.print(StructBuff.AP); Serial.println(); Serial.print(StructBuff.GPS); Serial.println(); uint8_t flush_tx(); } void StuffStructBuff(float inRoll, float inPitch, float inYaw, unsigned int inAP, String inGPS){//**Working** StructBuff.imuRoll = inRoll; StructBuff.imuPitch = inPitch; StructBuff.imuYaw = inYaw; StructBuff.AP = inAP; StructBuff.GPS= inGPS; }
RX #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(20 * sizeof(byte)); radio.setChannel(2); radio.setAutoAck(true); radio.openReadingPipe(1,0xF0F0F0F0D2LL); radio.openWritingPipe(0xF0F0F0F0E1LL); radio.startListening(); radio.printDetails(); //**************End Transiever (NRF24L01) config************** } struct StructBuff_t { String GPS; float imuRoll; float imuPitch; float imuYaw; unsigned int AP; } StructBuff; //************************************************** //************* Start Main Loop section ************ //************************************************** void loop() { RecStruct(); }
//************************************************** //************* END Main Loop section*************** //************************************************** //-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+ void RecStruct(){ if ( radio.available() ) { bool ok = radio.read((byte *)&StructBuff, sizeof(StructBuff)); if (ok) printbuffs(); // printf("ok...\n\r"); else printf("failed.\n\r"); uint8_t flush_rx(); } 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.print(","); Serial.print(StructBuff.AP); Serial.println(); Serial.print(StructBuff.GPS); Serial.println(); uint8_t flush_rx(); }
OutPut on RX Side -143.00,-101.00,113.00,8 This is my RF test -127.00,-41.00,0.00,65 This is my RF test -147.00,19.00,189.00,32 This is my RF test -34.00,85.00,97.00,26 This is my RF test
|
|
|
|
|
13
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 03, 2013, 03:24:52 am
|
|
i have changed the payload size and converted the struct to a regular struct with no luck. i can do it with unions and convert from floats and chars to bytes into an output array and send them i was just under the impression i could just use 1 struct and toss that across the link to the other one. anyone know if this is true or not?
|
|
|
|
|
14
|
Using Arduino / Programming Questions / Re: sending structs, need clarification on some things.
|
on: February 02, 2013, 11:23:41 am
|
So i made static values and flushed the buffer and now i get this TX 1.01,22.02,-32.99 1.01,22.02,-32.99 1.01,22.02,-32.99 1.01,22.02,-32.99
RX -0.00,-0.00,-0.00 -0.00,-0.00,-0.00 -0.00,-0.00,-0.00
my TX code #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 = 1.01; // StructBuff.imuPitch = 22.02; //Temp Values StructBuff.imuYaw = -32.99; // // /////////////////////////////////////////////////////////
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"); uint8_t flush_tx(); 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(); uint8_t flush_tx(); }
RX code #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() { radio.startListening(); 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"); uint8_t flush_rx(); 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(); uint8_t flush_rx(); }
|
|
|
|
|