Sending most recent SD card entries via bluetooth

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
iqasi096
 
Posts: 27
Joined: Tue Apr 14, 2020 5:08 pm

Sending most recent SD card entries via bluetooth

Post by iqasi096 »

Hello,

I have been using the Adafruit SD card breakout module to send data to my app via an HM-10 bluetooth module. I was looking at designing a solar current data logger such that this current is used to provide charge to a 6000mah lipo battery.

I am currently monitoring the current charge of the battery and overall solar current and storing this data on a 32 GB SD card while transmitting this value with bluetooth via a JSON file so it can update on my phone application.

The reason for the SD card was to be able to retrieve the last saved values once the battery runs out of charge and turns off the Arduino to be able to better calculate the current produced by the Solar Panel.

My question is if there's a way to retrieve the last saved values of my SD card and send them as a JSON file to my app??

I realize that we are able to set the cursor further down the SD file to be able to read the values but I had very little to no success at doing this with my file being around 60.8MB and every input being sized at 51 bytes.

Here is the code I have been using to test:

Code: Select all

/*
  SD card read/write

  This example shows how to read and write data to and from an SD card file
  The circuit:
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10 (for MKRZero SD: SDCARD_SS_PIN)

  created   Nov 2010
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

*/

#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");


  // open the file for reading:
  myFile = SD.open("TEST1.CSV");
 
  if (myFile) {
    Serial.println("TEST1.CSV");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      int fileLength = myFile.available();
      int recordCount = fileLength / 51;
      int lastRecordStart = (recordCount - 1) * 51;
      myFile.seek(lastRecordStart); // Position the read cursor at the start of the last record
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”