Help: FIFO Overflow when communicating between two ESP8266's

im using the library ‘ESP8266WiFi.h’ to communicate values between two Node MCU esp-12e boards and my computer. I want to send gyroscopic values into a game service called unity so I set up a left controller as an access point and the right controller and my pc as a station. My PC reads the values and the left controller sends its values and the other controllers values to the PC. (In the future I hope to send information to the controllers to toggle a vibration motor) And this approach works fine when I only have my PC and left controller connected, but as soon as the Right controller connects it works fine for a few seconds, then information sending on both the left controller and right controller abruptly stop, they then start showing the message ‘FIFO Overflow!’ and start sending very choppy and slow messages, followed by only button input when they should be sending both button and gyroscopical input. The first two lines in this example are the correct output from the left controller, then it abruptly stopping, sending out the FIFO message, and proceeding to send out incomplete information over random extended periods of time.

L:0.87,-0.03,-0.00,-0.49:-31,-27,-1503:B_UP,A_UP
R:0.81,0.12,-0.57,0.13:709,-358,1099:B_UP,A_UP
FIFO overflow!
L:B_UP,A_UP

Attached is the code for the left and right controllers. I can give more information if nessecary. Any help is appreciated. Thank you! :smiley:

LeftControllerV1.ino (12.2 KB)

RightControllerV1.ino (10.9 KB)

I think you aren't reading measurements from the MPU fast enough. If you don't read the values out of the MPU's buffer at least as fast as it's generating measurements, you are bound to run into FIFO overflow. You have more or less 3 options:

1.) Don't use the FIFO buffer - do a single shot measurement each time instead
2.) Read new measurements at a higher rate than you send measurements to the other Arduino (just use the "most recent" measurement when communication)
3.) Both read from the MPU and report measurements faster than 10Hz

Power_Broker:
I think you aren't reading measurements from the MPU fast enough. If you don't read the values out of the MPU's buffer at least as fast as it's generating measurements, you are bound to run into FIFO overflow. You have more or less 3 options:

1.) Don't use the FIFO buffer - do a single shot measurement each time instead
2.) Read new measurements at a higher rate than you send measurements to the other Arduino (just use the "most recent" measurement when communication)
3.) Both read from the MPU and report measurements faster than 10Hz

Thank you for the insight, how can i execute these options? Im a bit new to the whole 'FIFO' topic as you might be able to tell. :smiley:

The first approach:

You can request the latest MPU measurement instead of reading the FIFO by doing the following (source):

#include<Wire.h>
const int MPU6050_addr=0x68;
int16_t AccX,AccY,AccZ,Temp,GyroX,GyroY,GyroZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU6050_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU6050_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_addr,14,true);
  AccX=Wire.read()<<8|Wire.read();
  AccY=Wire.read()<<8|Wire.read();
  AccZ=Wire.read()<<8|Wire.read();
  Temp=Wire.read()<<8|Wire.read();
  GyroX=Wire.read()<<8|Wire.read();
  GyroY=Wire.read()<<8|Wire.read();
  GyroZ=Wire.read()<<8|Wire.read();
  Serial.print("AccX = "); Serial.print(AccX);
  Serial.print(" || AccY = "); Serial.print(AccY);
  Serial.print(" || AccZ = "); Serial.print(AccZ);
  Serial.print(" || Temp = "); Serial.print(Temp/340.00+36.53);
  Serial.print(" || GyroX = "); Serial.print(GyroX);
  Serial.print(" || GyroY = "); Serial.print(GyroY);
  Serial.print(" || GyroZ = "); Serial.println(GyroZ);
  delay(100);
}

Second approach:

Use the same code for the IMU, except do NOT use delay() - read the entire FIFO as many times per second as possible, but use a software timer to send the latest measurement to the other Arduino.

Third approach:

Use the same exact code, but without any delay() calls.