incorrect data values from MPU6050 through NRF24L01 to computer

Hi there.

After a bit of help in getting my accelerometer to start using a push button (thanks Delta_G). I have managed to get the two boards (UNO R3 and NANO) to transmit data from the UNO with an accelerometer attached to a NANO connected to the computer. I have used NRF24L01's to transmit the data from the MPU6050 connected to the UNO through the NRF24L01, to another NRF24L01, to the NANO then through a USB cable t the computer and onto the serial monitor. I have connected the NRF24L01'S as shown on this site;

and the MPU6050 as shown on this site;

The button is a push to make switch attached from ground to pin 6.

My problem is that i get transmission of sorts but it seems to be just a lot of zeroes in the serial monitor like the picture in the attchment (run at 9600 baud);

i have tried all different baud rates from 9600 up to 230800. I believe my problem is that the code is too slow (attached below) as if i run just the uno at 115200 baud, it gives me 3 lots of data, then FIFO Overflow, then another 3 lots and over and over. If i run at 9600 then it gives nothing but FIFO Overflow. Do i need to improve the speed of the code, or is it down to my terrible programming? (apologies in the code for all the // as i'm trying to keep it in there to experiment). Are the 0.00's what the radio is transmitting the FIFO Overflow as? And a quick one, what is the max baud rate the NRF24L01's can run at?

Thankyou all

MPU6050_State_Machine_Receiver_Test.ino (1.21 KB)

MPU6050_DMP6_Transmitter_Test.ino (8.7 KB)

So have half sorted this. I managed to fix it as much as i did out of anger so was not methodical. Things i changed were;

data types to "unsigned long"
stopped sending the tab spaces ("\t") over the radio and just printed them via the receiver end
attached a 10uF capacitor across 3.3v and gnd
changed the amplifier power to max [radio.setPALevel(RF24_PA_MAX);]
changed the data rate [ radio.setDataRate(RF24_2MBPS);]
deleted all the serial prints on the transmitter end. it's not connected, doesn't need them and slows down the program (i believe the zeroes i'm still getting are the FIFO overflow being sent)

if i think of anything else I'll update this thread as it bugs me when people don't share their solutions for people reading at a later date.

Hi there

I posted about this a day or two ago, thread below, and have made some progress

https://forum.arduino.cc/index.php?topic=514841.0

However, i am still having some issues. i have now got the code to produce some meaningful results but every few lines it gives me zeroes like below;

29.08	-1000.00	1700.00	2331.00
29.09	-1003.00	1697.00	2329.00
29.11	-1003.00	1693.00	2328.00
29.12	-1006.00	1692.00	2328.00
29.13	-1007.00	1692.00	2328.00
29.15	-1006.00	1689.00	2327.00
29.16	-1004.00	1684.00	2323.00
29.17	-1005.00	1680.00	2322.00
29.19	-1006.00	1675.00	0.00
2323.00	0.00	0.00	0.00
29.20	-1007.00	1674.00	2325.00
29.21	-1008.00	1672.00	0.00
2321.00	0.00	0.00	0.00
29.23	-1015.00	1625.00	2318.00
29.24	-1017.00	1620.00	2321.00
29.25	-1014.00	1616.00	2328.00
29.27	-1014.00	1613.00	2332.00
29.28	-1014.00	1612.00	2336.00
29.30	-1017.00	1607.00	2343.00
29.31	-1019.00	1604.00	2341.00
29.32	-1023.00	1602.00	2340.00
29.33	-1024.00	1601.00	0.00
2336.00	0.00	0.00	0.00
29.35	-1024.00	1602.00	2332.00
29.36	-1023.00	1596.00	0.00
2335.00	0.00	0.00	0.00
29.38	-1025.00	1593.00	2344.00
29.39	-1024.00	1589.00	0.00
2344.00	0.00	0.00	0.00
29.40	-1026.00	1586.00	2345.00
29.42	4622.00	14040.00	15472.00
29.43	-1033.00	1547.00	2348.00
29.45	-1033.00	1544.00	0.00
2348.00	0.00	0.00	0.00
29.46	-1033.00	1541.00	2350.00
29.47	-1033.00	1538.00	0.00
2350.00	0.00	0.00	0.00
29.49	-1034.00	1535.00	2351.00
29.50	-1036.00	1533.00	2348.00
29.51	-1038.00	1529.00	2349.00
29.53	-1038.00	1526.00	2353.00
29.54	-1040.00	1521.00	2353.00
29.56	-1040.00	1520.00	2356.00
29.57	-1041.00	1518.00	2359.00
29.58	-1040.00	1518.00	2362.00
29.59	-1038.00	1517.00	0.00
2361.00	0.00	0.00	0.00
29.61	-1037.00	1521.00	2361.00
29.62	-1037.00	1520.00	0.00
2359.00	0.00	0.00	0.00

as you can see i am getting some meaningful results but it's still plagued with these zeroes. My thinking is that this is how FIFO Overlow is being sent as if i run the code attached
(MPU6050_State_Machine_Transmitter_Test_Speed) while just printing the Z axis output then i get the following results;

Testing device connections...
MPU6050 connection successful
Initializing DMP...
Enabling DMP...
Enabling interrupt detection (Arduino external interrupt 0)...
DMP ready! Waiting for first interrupt...
-1286
-569
FIFO overflow!
4845
4814
FIFO overflow!
4259
4243
FIFO overflow!
3831
3818
FIFO overflow!
3452
3448
FIFO overflow!
3213
3228
FIFO overflow!
3031
3025
FIFO overflow!
2902
2900
FIFO overflow!
2791
2790
FIFO overflow!
2695
2690

so my question is this. Is there anyway to speed up this code to reduce the FIFO Overflow?

i have tried the suggestions in this thread, including changing the I2C clock speed, DMP output rate and the Baud rate up to 500000.

i have also tried increasing the power amplifier level up to max and the data rate of the radio up to 2MBPS. Is there anything else someone can see where i'm being slowed down.

Thanks, Ross

MPU6050_State_Machine_Transmitter_Test_speed.ino (8.26 KB)

MPU6050_State_Machine_Receiver_Test.ino (1.04 KB)

MPU6050_DMP6.ino (15.5 KB)

Ross46:
I posted about this a day or two ago,

Why start a new Thread?

I have suggested to the Moderator to merge them.

...R

@Ross46, I suggest you do something useful with the return value from RF24::read on the receiver.

(Threads merged.)

Hi there. Sorry for the two threads. I posted the first one and partially solved it and thought it was better to start a new simpler thread. Sorry if that was the wrong thing to do.

@Coding Badly, I'm unsure about what you mean by "do something useful with the return value from RF24::read on the receiver.". My previous thought was that the transmitter code was too slow as if i pasted in the Serial.prints from the example code it runs with no FIFO Overflow. I have looked at the receiver code and my only though is to send the data in one packet instead of four. My hope is to get the data from the MPU6050, transmit it wirelessly to the nano connected to the computer and save the data to an SD card.

My current thought is that it is taking too long to send small packets of data e.g. each value, rather than sending it in one packet. Am i on the right lines or way off?

Sorry for my noobish questions and thread posting.

Thanks

Ross

This, from the receiver code in Reply #2 does not make sense

 while (radio.available()) {

    radio.read(&timemicro, sizeof(timemicro));
    Serial.print(timemicro);

    Serial.print("\t");
    
    radio.read(&AccX, sizeof(AccX));
    Serial.print(AccX);
    
    Serial.print("\t");
    
    radio.read(&AccY, sizeof(AccY));
    Serial.print(AccY);
    
    Serial.print("\t");
    
    radio.read(&AccZ, sizeof(AccZ));
    Serial.println(AccZ);
    }

The nRF24 does not work like Serial so while (radio.available()) is not appropriate. If there is data available the complete message will be available so just use IF.

Also, you seem to be sending several float values separately. If so, then you should be testing radio.available() for each of them. Alternatively you could send an array of up to 8 floats (32 bytes) as a single message, which would make the wireless programming a lot simpler.

...R
Simple nRF24L01+ Tutorial

Hi there

thankyou all of you for your help. @Robin2, i have changed the following block of code;

 #ifdef OUTPUT_READABLE_REALACCEL
            // display real acceleration, adjusted to remove gravity
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetAccel(&aa, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
            
            float timemicro[] = {micros()/1000000.0, 6};
            radio.write(&timemicro, sizeof(timemicro));
                      
            float AccX = {aaReal.x};
            radio.write(&AccX, sizeof(AccX));
            
            float AccY = {aaReal.y};
            radio.write(&AccY, sizeof(AccY));
                       
            float AccZ = {aaReal.z};
            Serial.println(aaReal.z);
            radio.write(&AccZ, sizeof(AccZ));

        #endif

to;

        #ifdef OUTPUT_READABLE_REALACCEL
            // display real acceleration, adjusted to remove gravity
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetAccel(&aa, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
            
            float timemicro[] = {micros()/1000000.0, 6};
            float AccX = {aaReal.x};
            float AccY = {aaReal.y};
            float AccZ = {aaReal.z};
            Serial.println(aaReal.z);

            int  Data[] = {timemicro, AccX, AccY, AccZ};
            radio.write(&Data, sizeof(Data));

        #endif

and the FIFO Overflow is gone. However, now my problem is that if i send the data across all i get is 0.00 repeated in 4 columns. I have been looking into changing the data types and no luck. I have changed the receiver code to;

void loop() {
  radio.startListening();
  if ( radio.available()) {
    while (radio.available()) {

    radio.read(&Data, sizeof(Data));
    
    Serial.print(timemicro);
    Serial.print("\t");
    Serial.print(AccX);
    Serial.print("\t");
    Serial.print(AccY);
    Serial.print("\t");
    Serial.println(AccZ);
    }
    //radio.stopListening();
  }
}

what am i missing here. How low do i have to hang my head in shame? Thanks, Ross

Ross46:
...what am i missing here...

http://snippets-r-us.com/

Ross46:
@Coding Badly, I'm unsure about what you mean by "do something useful with the return value from RF24::read on the receiver.".

RF24::read returns a value. The returned value may help you determine what is going wrong. You are discarding (ignoring) the returned value.

My previous thought was that the transmitter code was too slow...

Another way to word that is, "the receiver code was too fast".

Ok. Apologies for the snippets. I have learnt my lesson! and love the website btw.

I don't know if this is a workaround but i have recieved more reliable results by putting a delay in the code of 15s at 2MBPS. I have tried different delays but this gives the best results, however there are still intermittent zeroes. I have also tried lower data rates but then i have to find the right delay again. Is there a way to find the latency between how long it takes to process the code, send the data, receive the data and print it so that there are no intermittent zeroes, as im taking from the previous post that it's not the MPU6050 at all but more that the receiver is trying to take data that isn't there so outputting zeroes. In other words, how do you code in the correct delay? Thanks for all your help

MPU6050_State_Machine_Receiver_Test_Semi.ino (1.05 KB)

MPU6050_State_Machine_Transmitter_Test_Semi.ino (8.26 KB)

Ross46:
I don't know if this is a workaround

On the Tx side you are still just tossing data into the ether and hoping it lands in the right spot without checking whether it landed anywhere. And on the Rx side you still have while (radio.available()) and are making no attempt to deal logically with separate messages - how do you know that you have not missed one?

"dogs breakfast" is the politest epithet I can think of.

You seem to want to send 4 floating point values so put them in an array and send them as a single message and, on the receive side they will be received into the same sized array with everything in the right place.

...R