1

this is my setup: I have an arduino uno + mpu-6050 + nrf24l01 all attached together and am transmitting data from that mpu-6050 to another arduino with an nrf24l01 attached to it. I got the arduinos to communicate with each other and transmit data ( ypr) wirelessly but it's still laggy and jumpy. Before I was getting FIFO overfull messages but I managed to somewhat fix that. Yet the data being transferred is still not running to stable nor smoothly. PLEASE HELP ME find the problem why these arduinos aren't transferring data fluently and smoothly. I posted the Receiver and transmitter codes down below. Also, I am illustrating the code on Processing 3.2.3, hence the teapot parts. THANK YOU

**************************RECEIVER*****************************************

{    
    #include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"


// format used for the InvenSense teapot demo
#define OUTPUT_TEAPOT


RF24 radio(7, 8);//pin assignment
unsigned long t0;
unsigned long t1;
float ypr[3];
uint8_t teapotPacket[14] = { };



void setup()
{
  pinMode(13,OUTPUT);

  while (!Serial);
  Serial.begin(115200);

  radio.begin();
  radio.openReadingPipe(1, 0xF0F0F0F0A1LL);
  radio.openReadingPipe(2, 0xF0F0F0F0A2LL);

  radio.startListening();
  t0=0;
}
byte pipeNum=0; //variable to hold which reading pipe sent data
void loop()
{  
  t1=millis();
  /*digitalWrite(13,HIGH);
  delay(500);
  digitalWrite(13,LOW);
  delay(500);
  */
  if (t1-t0>100){
  if (radio.available(&pipeNum))
  {


    typedef struct YPR_RX {
      int y; 
      int p;
      int r;
    } YPR_RX;
    YPR_RX ypr_rx;


    //radio.read(&ypr_rx, sizeof(ypr_rx));
   // teapotPacket = new uint8_t teapoPacket(radio.getPayload)

    radio.read(&teapotPacket, sizeof(teapotPacket));
   // radio.read(&teapotPacket, sizeof(radio.getPayloadSize()));
//    radio.SetDatarate();
    uint8_t newTeapot[14] = {'$', 0x02, teapotPacket[2],teapotPacket[3],teapotPacket[4],teapotPacket[5],teapotPacket[6],
                                        teapotPacket[7],teapotPacket[8],teapotPacket[9], 0x00, 0x00, '\r', '\n' };
    Serial.write(newTeapot, 14);
    newTeapot[11]++;


            Serial.print(newTeapot[2]);
            Serial.print("\t");
            Serial.print(newTeapot[3]);
            Serial.print("\t");
            Serial.print(newTeapot[4]);
            Serial.print("\t");
            Serial.print(newTeapot[5]);
            Serial.print("\t");
            Serial.print(newTeapot[6]);
            Serial.print("\t");
            Serial.print(newTeapot[7]);
            Serial.print("\t");
            Serial.print(newTeapot[8]);
            Serial.print("\t");
            Serial.println(newTeapot[9]);



/*
    Serial.print(ypr_rx.y);
    Serial.print("\t");
    Serial.print(ypr_rx.p);
    Serial.print("\t");
    Serial.print(ypr_rx.r);
    Serial.print("\t");
    Serial.println();
    */

    t0=t1;

    //Serial.println("X-acceleration");
    //int number=atol(text);
    //Serial.println(number);
    //Serial.println((int)text);
    //Serial.println(value);
    //delay(100);

  }
  }


}
}

*********************************TRANSMITTER************************************

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"


// format used for the InvenSense teapot demo
#define OUTPUT_TEAPOT


RF24 radio(7, 8);//pin assignment
unsigned long t0;
unsigned long t1;
float ypr[3];
uint8_t teapotPacket[14] = { };



void setup()
{
  pinMode(13,OUTPUT);

  while (!Serial);
  Serial.begin(115200);

  radio.begin();
  radio.openReadingPipe(1, 0xF0F0F0F0A1LL);
  radio.openReadingPipe(2, 0xF0F0F0F0A2LL);

  radio.startListening();
  t0=0;
}
byte pipeNum=0; //variable to hold which reading pipe sent data
void loop()
{  
  t1=millis();
  /*digitalWrite(13,HIGH);
  delay(500);
  digitalWrite(13,LOW);
  delay(500);
  */
  if (t1-t0>100){
  if (radio.available(&pipeNum))
  {


    typedef struct YPR_RX {
      int y; 
      int p;
      int r;
    } YPR_RX;
    YPR_RX ypr_rx;


    //radio.read(&ypr_rx, sizeof(ypr_rx));
   // teapotPacket = new uint8_t teapoPacket(radio.getPayload)

    radio.read(&teapotPacket, sizeof(teapotPacket));
   // radio.read(&teapotPacket, sizeof(radio.getPayloadSize()));
//    radio.SetDatarate();
    uint8_t newTeapot[14] = {'$', 0x02, teapotPacket[2],teapotPacket[3],teapotPacket[4],teapotPacket[5],teapotPacket[6],
                                        teapotPacket[7],teapotPacket[8],teapotPacket[9], 0x00, 0x00, '\r', '\n' };
    Serial.write(newTeapot, 14);
    newTeapot[11]++;


            Serial.print(newTeapot[2]);
            Serial.print("\t");
            Serial.print(newTeapot[3]);
            Serial.print("\t");
            Serial.print(newTeapot[4]);
            Serial.print("\t");
            Serial.print(newTeapot[5]);
            Serial.print("\t");
            Serial.print(newTeapot[6]);
            Serial.print("\t");
            Serial.print(newTeapot[7]);
            Serial.print("\t");
            Serial.print(newTeapot[8]);
            Serial.print("\t");
            Serial.println(newTeapot[9]);



/*
    Serial.print(ypr_rx.y);
    Serial.print("\t");
    Serial.print(ypr_rx.p);
    Serial.print("\t");
    Serial.print(ypr_rx.r);
    Serial.print("\t");
    Serial.println();
    */

    t0=t1;

    //Serial.println("X-acceleration");
    //int number=atol(text);
    //Serial.println(number);
    //Serial.println((int)text);
    //Serial.println(value);
    //delay(100);

  }
  }


}
5
  • Could you please describe a bit more, what's the exact issue you have? As "not stable and smooth" is rather generic.
    – Avamander
    Commented Mar 25, 2017 at 8:10
  • Why does the receiver do a 100 ms wait? Commented Mar 25, 2017 at 14:13
  • @avamander The problem it doesn't have regular readings. Like when I have the mpu-6050 plugged directly into my computer the readings run smoothly and dont lag. When I make wirelessly, the information lags some and its all skippy along with some lag. Especially when I put it on Processing for visuals, it lags and randomly skips readings. I'm just not sure what the problem is, maybe something with the buffer? Commented Mar 26, 2017 at 17:37
  • As always with nRF24L01+, attach a 1000uF electrolytic capacitor to the GND and 3.3V on the module itself.
    – Avamander
    Commented Mar 26, 2017 at 19:33
  • The possible problem could be with the hardware setup? Could it not be something with the code itself? Commented Mar 26, 2017 at 20:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.