The data collection code to the microSD card does not work

Asked 1 years ago, Updated 1 years ago, 307 views

I'd like to use the acceleration sensors called the Spresense and BMI160 to create a code that records the sensor output on the microSD card, but it's not working.

I would like to have the sensor output value recorded on the csv file for every 128 data at the specified sampling rate.
I'm trying with the code below, but what are the problems?
If you actually run it, all 128 data will have the same value.

I don't know much about arduino, so if you have any reference codes, I would appreciate it if you could explain them carefully.

#include<BMI160Gen.h>
# include <CurieIMU.h>
# include <SDHCI.h>
SDClass SD;

#define FFT_LEN1024

void saveData(float*pDst, int dsize, intquantity){
  // contents of the savedata function
  // pDst is the pointer to the data, the next section is the size of the recorded data, and the next section is the number of data stores.
  static intgCounter = 0;// file name followed by
  char filename [16] = {};

  // Return without doing anything when more than the specified number of saves is reached
  if(gCounter>quantity){
    Serial.println("Data accumulated";
    return;
  }

    // open a data storage file
  sprintf(filename, "data%03d.csv", gCounter++);
  // delete a file if it already exists
  if(SD.exists(filename))SD.remove(filename);
  // Open File
  File myFile=SD.open(filename, FILE_WRITE);
  // Write Data
  for(inti=0;i<dsize;++i){
    myFile.println(String(pDst[i], 6));
  }
  myFile.close();//Close file
  Serial.println("Data saved as"+String(filename)));
}


void setup() {
  Serial.begin (230400);
  while(!Serial);

    // Wait for SD card to be inserted
  while(!SD.begin()){
    Serial.println("Insert SD card");
    };

  Serial.println("Initializing IMU device...");
  BMI 160.begin();

  BMI 160.setAccelerometerRange(2);
  BMI 160.setAccelerometerRate (1600);

  // Check acceleration measurement range and acceleration output rate before starting measurement  
  floata=BMI160.getAccelerometerRate();
  floatb=BMI160.getAccelerometerRange();
  Serial.println(a);
  Serial.println(b);
}

void loop() {
  float*ax;
  float*ay;
  float*az; // scaled accelerometer values
  BMI 160.readAccelerometerScaled(*ax,*ay,*az);

  // Show the acceleration as it is on the serial monitor
  // Serial.print("a:\t");
  // Serial.print(ax);
  // Serial.print("\t");
  // Serial.print(ay);
  // Serial.print("\t");
  // Serial.print(az);
  // Serial.println();  

  // Save a csv file with FFT_LEN/8 minutes of data on the microSD 10 times
  saveData(az, FFT_LEN/8,9); // Save z-axis output
}

sense arduino

2023-01-20 23:23

1 Answers

In void loop(), but float*ax; means that there is no variable to store float, only a pointer.The pointer is not pointing to valid memory and is malfunctioning.In the case of embedded microcomputers, most memory spaces are not mapped and often have no protective mechanisms, which will result in garbage values (usually the same value) if read without writing to invalid addresses.

I can't say exactly how to fix it because it depends on the readAccelerometerScaled() specification, but you'll normally have a true array (or float variable).

# The presentation readAccelerometerScaled() is extremely strange.That might also be a debug.

Show questions tagged with

2023-01-21 02:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.