Transfer files to Android device over Bluetooth

Hi guys,

I have to transfer some files from an SD card in the Arduino to an Android device over Bluetooth.

My Bluetooth is CC2540 (link).
The baudrate is 38400.

My current logic for the transfer is something like:

loop() {

  readCommandFromAndroid();

  if(commandIs("getNextLine") {
    readNextLineFromSD();
    SerialBLE.write(line);
  }

  delay(20);
}

This code is working, but there are two things bothering me:

  1. There is overkill with the reading of the command every time.
  2. I have to delay some time ( at least 20ms ), otherwise the Bluetooth halts. If i dont set delay, the bluetooth halts after 3-4 seconds of transfer.

I have tested the Bluetooth in isolation like this:

#include <Arduino.h>
#include <SoftwareSerial.h>
SoftwareSerial SerialBLE(A2, A3);


void setup() {
  SerialBLE.begin(38400);
}

void loop() {
  SerialBLE.write("foo\n");
  delay(20);
}

I am able to read this from the android, no problem. But if i remove the delay, bluetooth halts after 3-4 seconds.

Please advice on what would be the best approach to transfer files.

Also I am very curious why am I forced to put at least 20ms delay (thus making the transfer 20 times slower). Is my bluetooth broken or what?

What is your intention? You talk about transferring files but the programme suggests you want to read lines..I didn't actually know you could do that.

Your problem may be caused by using software serial at that speed

If you want the file, the following might help. It is really just an expansion of the file dump example in the IDE.

//Daily files can be read via bluetooth by sending MMDD

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

#define DS1307_ADDRESS 0x68

char filename[13],charBuf [13],strYr[4];
File myFile, dumpFile;
int  second, minute, hour, weekDay, monthDay, month, year;
const int chipSelect = 4;
String readString;
String stringFive, stringSix;

void setup() {
  Wire.begin();
  Serial.begin(115200);
  Serial.println("Bare test");
  Serial.println("Init SD CARD");
  // make sure that the default chip select pin 53 is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);//Uno 10, MEGA 53
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) 
  {
    Serial.println("Card failed");
    // don't do anything more:011
    return;
  }
  Serial.println("CARD OK");
  delay(2000);
  GetClock();
  Serial.println("today's date for filename");
  Serial.print(year);
  Serial.print("/");
  Serial.print(month);
  Serial.print("/");
  Serial.println(monthDay);

  getFileName();
  Serial.println("active filename");
  Serial.println(filename);
  delay(2000);
}

void loop() {
  GetClock();
  while (Serial.available()) 
  {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }// end while

  if (readString.length() >0) 
  {  
    getDump();   
    readString="";  
  } // end if
} 
byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal bers
  return ( (val/16*10) + (val%16) );
}

void getFileName(){
  sprintf(filename, "%04u%02u%02u.csv", year, month, monthDay);
}

void GetClock(){
  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);

  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  monthDay = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
  year = year +2000;
}

void getDump() {
  dtostrf(year,4, 0, strYr);
  stringSix = strYr + readString + ".csv";
  stringSix.toCharArray(charBuf, 15);  
   File dumpFile = SD.open(charBuf);
  if (dumpFile) 
  {
    Serial.println("DUMP FROM ");
    Serial.println(charBuf);
     delay(2000);
    while (dumpFile.available())
    {
      Serial.write(dumpFile.read());
    }
    dumpFile.close();
  }  
  else {
    Serial.println("error opening file");
  }
}

Hello, this is my first arduino project: sending a file (jpeg, pdf, txt) from an arduino sd card module to android phone using arduino uno and bluetooth module bt-05
It's possible with this hardware?
have you any suggestion about the android app to receive the file?
thank you

For text, yes. See reply # 1. Any Bluetooth terminal programme will suffice

For text, yes.

The process of transferring the bytes in a file is not restricted to transferring only bytes that represent printable characters in an ASCII table.

So, the comment should be:
For any kind of file, yes.

Paul, so you think it's possible to send a picture (exp: jpeg) to an android device using arduino uno, HC-05 and micro sd card shield?