Hi guys ! I'm Antoine, a beginner in Arduino. I have some smattering in Python and a basic college level in electronic.
My project is to save acceleration and rotation datas from a rocket flight with a embedded MPU6050 (on GY-521 chip), my board is an Arduino Nano.
I will prefer to use DMP algorythms to reduce errors and i need a polling rate of 200 Hz.
My question is :
I can write on my SDcard and print YPR datas with DMP and Raw datas from the MPU6050 but how to modify the example program MPU6050_DMP6 to export the datas on the SDcard and to add the acceleration datas (not obtained with DMP ?) ?
I've seen this post :
The guy's problem is similar to mine but he's not using the same board so I don't know how to do.
You might want to check here for code to read the MPU6050 and if you search this site you will find code for writing the SD card. Given space and weight is probably an issue as it is on every rocket you might want to use an Arduino ProMini as you will have the same functionality in a much smaller package and it operates at 3.3 V which is handy for communicating with the MPU6050 and the SD card.
You should start with code that reads the MPU6050 alone and debug it, then do the same for writing the SD card, once they are both working as you would like integrate them together. I find it easier to read code and debug for each piece separately when feasible and then integrate. Think crawl, walk and then run.
Maybe someone with an MPU6050 can verify your problem; I haven't looked at your code, but I have run in to similar situations before. Do you have anything in your code that will free up memory? Many times, I've found that if I've run out of memory for variable storage, my project will lock up.
I'll take a look at your code this evening; I can't really answer that reliably, or even a suggestion how to make it cleaner.
One way you could figure out where the problem is happening would be to determine how many bytes 80 data points actually is, create a sketch with just the SD portion of your code and Serial and then throw 90 points worth of data at it through a serial port and have it dump whatever it receives to the card. I use PuTTY for that kind of test.
Basically, build up your code in blocks until it breaks again, the same way you would a lab in college.
I still haven't had a chance to look at your code, but Whandall is on the right track.
You only have 2k of RAM available to the microcontroller. Every time you open the file on the SD, you're setting up a buffer (a portion of RAM dedicated to that file.) If you don't close the file, at least some of that RAM, be it data bytes or just the variables associated with the name and mode, remains in use. 2k can get chewed up very rapidly that way.
What I would suggest would be to just focus on working with the SD file and dumping data to it through Serial until you've got it stable. The thread Whandall is pointing to has some very good information in it.