Hello All
how to use an array to store 1000 data point..?
I want to store accelerometer sensor data(x, y, and z-axis) into the array. when array store 1000 element it writes data into a text file in sd card, after that initialize array and again start to store the element into array.
What is the data type of the data? What Arduino are you using?
Pieter
PieterP:
What is the data type of the data? What Arduino are you using?
Pieter
Float data type and i have use Arduino Uno board. for connection, i have used A0, A1, A2 pin.
The Arduino Uno has 2 KiB = 2048 bytes of RAM.
sizeof(float) == 4 bytes → sizeof(float[1000]) == 4000 bytes > 2048 bytes.
system
August 7, 2019, 12:45pm
5
Does the accelerometer really produce float values?
Floating-point values require 4 bytes each. Since we want to store information from all 3 axis per sample, we will need 1000 * 3 * 4 = 12000 bytes for array. our board has 32KB of RAM, so it should have sufficient memory for 1000 samples.
We want to store all 3 axis data so we required 2 dimension array.
Please tell me how to use 2 D array in arduino programming?
How t store sensor data into array.?
Thank You
amitshishodia:
Floating-point values require 4 bytes each. Since we want to store information from all 3 axis per sample, we will need 1000 * 3 * 4 = 12000 bytes for array. our board has 32KB of RAM, so it should have sufficient memory for 1000 samples.
We want to store all 3 axis data so we required 2 dimension array.
Please tell me how to use 2 D array in arduino programming?
How t store sensor data into array.?
Thank You
something like this you mean:
in pseudo-code
const uint8_t axes = 3;
const uint16_t MAX_samples = 1000;
float data_points[MAX_samples][axes]; //declare 2d array
uint16_t i=0;
while (i< MAX_samples){
datapoint[i][0] = axis_1 reading;
datapoint[i][1] = axis_2 reading;
datapoint[i][2] = axis_3 reading;
++i;
delay(x); //if required! :)
}
Float data type and i have use Arduino Uno board. for connection, i have used A0, A1, A2 pin.
our board has 32KB of RAM, so it should have sufficient memory for 1000 samples.
The Arduino UNO has 32K bytes of Flash memory for holding the program and any initialized data, and 2K bytes of SRAM for holding data generated by the program.
sherzaad:
something like this you mean:
in pseudo-code
const uint8_t axes = 3;
const uint16_t MAX_samples = 1000;
float data_points[MAX_samples][axes]; //declare 2d array
uint16_t i=0;
while (i< MAX_samples){
datapoint[i][1] = axis_1 reading;
datapoint[i][2] = axis_2 reading;
datapoint[i][3] = axis_3 reading;
++i;
delay(x); //if required!
}
Yes, sir, i have sent you our code please modified it according to my requirement.
i want array store 1000 data each axis after storing data it sends data into a text file and again starts storing data
#include <Scheduler.h>
#include <time.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_BMP280.h>
#define VBATPIN A7
#define BMP_SCK (SCL)
#define BMP_SDI (SDA)
int led1 = 10;
//int led2 = 11;
//int led3 = 12;
//int led4 = 13;
const int chipSelect = 4;
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;
int RawMin = -14;
int RawMax = 1015;
float refRange = 400;
float refLow = -200;
float rawLowX1 = 395;
float rawLowY1 = 395;
float rawLowZ1 = 395;
float rawRangeX = 216.5;
// Take multiple samples to reduce noise
const int sampleSize = 1;
Adafruit_BMP280 bmp; // I2C
File dataFile;
char filename[15];
uint16_t fileNumber=0;
void setup(){
Serial.begin(250000);
pinMode(led1, OUTPUT);
pinMode(7, INPUT_PULLUP);
Serial.println(F("BMP280 test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
// while (!Serial){
; // wait for serial port to connect. Needed for native USB port only
// }
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
strcpy(filename, "/LOG00000.TXT");
for(uint16_t i = 0; i<10000; i++) {
filename[8] = '0' + i%10;
filename[7] = '0' + (i/10)%10;
filename[6] = '0' + (i/100)%10;
filename[5] = '0' + (i/1000)%10;
filename[4] = '0' + i/10000;
Serial.println(filename);
if (! SD.exists(filename)){
fileNumber=i;
break;
}}
}
uint16_t lineNum=0,lineNumLimit=20000;
uint8_t i = 0;
int count1 = 1;
void loop()
{
//count1++;
//Serial.println(count1);
uint32_t sec = micros() / 1000000;
uint32_t milli = millis();
uint32_t mil = milli % 1000;
//uint32_t minn60 = minn % 60;
uint32_t sec60 = sec % 60;
uint32_t minn = sec / 60;
uint32_t minn60 = minn % 60;
uint32_t hour = sec / 3600;
uint32_t hour60 = hour % 60;
//Read raw values
int xRaw = ReadAxis(xInput);
int yRaw = ReadAxis(yInput);
int zRaw = ReadAxis(zInput);
int gX1 = -((((xRaw-rawLowX1)*refRange)/rawRangeX)+(refLow));
int gY1 = -((((yRaw-rawLowY1)*refRange)/rawRangeX)+(refLow));
int gZ1 = -((((zRaw-rawLowZ1)*refRange)/rawRangeX)+(refLow));
if((lineNum%lineNumLimit) == 0)
{
dataFile.close();
filename[8] = '0' + fileNumber%10;
filename[7] = '0' + (fileNumber/10)%10;
filename[6] = '0' + (fileNumber/100)%10;
filename[5] = '0' + (fileNumber/1000)%10;
filename[4] = '0' + fileNumber/10000;
Serial.print("\ncurrent filename is : ");
Serial.println(filename);
fileNumber++;
dataFile = SD.open(filename, FILE_WRITE);
dataFile.print("HH:MM:SS:mmmm - X1, Y1, Z1");
dataFile.print("----");
}
dataFile.print(hour60);
dataFile.print(":");
dataFile.print(minn60);
dataFile.print(":");
dataFile.print(sec60);
dataFile.print(":");
dataFile.print(mil);
dataFile.print(" ^^^^^ ");
dataFile.print(gX1);
dataFile.print(" , ");
dataFile.print(gY1);
dataFile.print(" , ");
dataFile.print(gZ1);
dataFile.println(" , ");
// dataFile.println(count1);
lineNum++;
//delay(5);
}
// Take samples and return the average
int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
delay(1);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
}
system
August 8, 2019, 7:03am
10
Does the accelerometer really produce float values?
AWOL:
Does the accelerometer really produce float values?
We measure Raw value means ADC value and convert into float value check program. my problem is different i want to store float value into 2 D array.
system
August 8, 2019, 8:05am
12
A simple "no" would have sufficed.