Arduino Due Flash (RAM) storage

Hey guys,
I am working on a project nowadays. I wrote a code by which the Arduino Due board collects the Accelerometer values (x,y,z) form the ADXL345 Accelerometer and displays them. The code I am using right now is as follows:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup(void)
{
Serial.begin(115200);
if(!accel.begin())
{
Serial.println(“Ooops, no ADXL345 detected … Check your wiring!”);
while(1);
}

accel.setRange(ADXL345_RANGE_16_G);
accel.setDataRate(ADXL345_DATARATE_3200_HZ);

}

void loop(void)
{
sensors_event_t event;
accel.getEvent(&event);

Serial.print(event.acceleration.x); Serial.print(" “);
Serial.print(event.acceleration.y); Serial.print(” “);
Serial.print(event.acceleration.z); Serial.println(” ");

}

I am using this accelerometer at 3200Hz so it is unable to print all of the 3200 values on the screen in 1 second. So I came up with an idea to store those values first in the flash (RAM) of my Due board and then display them after some time. So can anyone please guide me of how to store the data coming out from Accelerometer to the flash of Arduino Due and display it on the screen after some time. Sharing the code will be highly appreciated.
Thanks in advance and have a nice day.

Regards,
Daniyal

Flash is not RAM. What you want to do is store in RAM. But, RAM is not FLASH memory.

You can create an array and store stuff in it then display it later. Something like:

float accelData[3200][3]
uint16_t dataPos;

accelData[dataPos][0] = event.acceleration.x;
accelData[dataPos][1] = event.acceleration.y;
accelData[dataPos][2] = event.acceleration.z;
dataPos++;
if (dataPos > 3199) dataPos = 0; //figure out something to do when array is full

Thank you very much for your reply. Because I am an amateur in this field so can you please state the complete code that I will use? I mean where will I add the code written by you? Secondly, how will I display the values on the screen? Is the code written by you enough to store and display the values? So to avoid confusion please can you write the complete code which I will be using to do the required task? Thank you again for the great help.

daniyal179:
Thank you very much for your reply. Because I am an amateur in this field so can you please state the complete code that I will use? I mean where will I add the code written by you?
Secondly, how will I display the values on the screen? Is the code written by you enough to store and display the values?
So to avoid confusion please can you write the complete code which I will be using to do the required task?
Thank you again for the great help.

Well, nobody is likely to go an write all the code for you,even if this doesn’t look like a homework assignment.

You should do yourself a great favor and learn at least the basics of C, in order to understand data structures and data types as well as basic program structures. Otherwise, you will get stuck at each and every corner you are trying to take with your project(s).

As for the same posted, I am not sure if the array should be of the type float, a more efficient way might be to use a simple int_16 instead, cutting the RAM requirement in half and also helps to cut down on float libraries to be pulled in and bloating the code…

Ralf

I'm not sure that'd help. (Though seriously, this is not a free development agency ;-)

The basic problem - that you're taking in data faster than you can report it - still remains. Yes, you can buffer, but the rate difference is unchanged.

My suggestion would be to use the other USB port on the due and use SerialUSB. That should allow you to log at 3200 Hz to the host.

Thank you very much guys. I appreciate your answers and also understood the need to learn C language. But can you please guide me that where in my code should I insert the following code for it to work:

float accelData[3200][3] uint16_t dataPos;

accelData[dataPos][0] = event.acceleration.x; accelData[dataPos][1] = event.acceleration.y; accelData[dataPos][2] = event.acceleration.z; dataPos++; if (dataPos > 3199) dataPos = 0;

Secondly, how will I use SerialUSB port to buffer the data?

Thank you very much for the help

Replace instances of "Serial" with use of "SerialUSB". e.g., instead of using Serial.println(); use SerialUSB.println(); etc. Arduino does come with documentation, you know. ;-)

Otherwise, seriously, you're asking us to do your programming for you, that won't work so well.