How to remove "press any key to continue" in Jeff Rowbergs MPU6050 code

Hi there.

Thanks to the help from this forum i have managed to get data for my project, though a little bodged!

For those who havent seen my project guidance thread, i am trying to use multiple MPU6050 accelerometers to measure the accelerations of the sprung (body of the motorcycle) and unsprung (wheels, brakes, suspension etc.) masses from a motorcycle for my dissertation. thread below;

Currently i am using two accelerometers and Jeff Rowbergs code. One attached to an UNO R3, one to a NANO and having to initialise them separately which is a pain and doesn’t give the data as a matching set so i can see when the masses start to move and i have to proces the data manually. I am currently trying to implement a wireless network of these accelerometers using NRF24L01 radio modules. One of these is attached to a Nano with an accelerometer so each accelerometer has the data processed by the Nano and then the data output is sent to the radio to send to a central Mega which collects the data from all of these sensors (up to 5) and then stores it on an SD card.

My question;

i would like to start all of the sensors, so that they are collecting data, at once and then send the data through using the radio modules. My problem is that in Jeffs code it requires you to “send a character to begin the demo” Preferably i would like to use a simple push to make switch to start the data flow. However i am unsure of how to remove the send any character protocol to change it to a switch. I have tried starting the code using a character and then using a switch but it fills up the fifo buffer, even with just one accelerometer hard wired to an UNO. So how would i go about removing the send a character part to replace with a switch. Attached is the original code taken straight from the example. Thank you

MPU6050_DMP6.ino (16.8 KB)

The problem with hacking example code is that it is just that, example code. It is most often not written with expansion in mind.

However the part you are looking for is all right here:

 // wait for ready
    Serial.println(F("\nSend any character to begin DMP programming and demo: "));
    while (Serial.available() && Serial.read()); // empty buffer
    while (!Serial.available());                 // wait for data
    while (Serial.available() && Serial.read()); // empty buffer again

The lines there do exactly what the comments say. Pull this out and replace it with a while loop that waits for your button press or switch or whatever you want it to wait for at this point.

while(digitalRead(someButton) == HIGH);  // Do nothing until button is pressed
while(digitalRead(someButton) == LOW);  //Do nothing until button is released

Thankyou Delta_G. I had been playing with that block of code for a while before you set me straight. I agree with you about example code. The problem i have is that for this code at least, and I'm guessing other things, is that lots of the intricacies are behind the code in libraries. I'm used to writing my own code in matlab, however after a lot of reading it seems the general consensus is that due to invensense not giving much information about the MPU6050, it is necessary to reverse engineer it which Jeff Rowberg has done. Hopefully one day i'll be good enough i can write my own libraries etc.