How to send a text file from my Arduino Nano to my phone

Hi there, I am trying to send a text file from my Arduino Nano to my phone using the Serial Bluetooth Terminal app. I know my circuit works as I have tried it with an alternative app but that would only send me data one bit at a time, whereas a text file is better for what I need it for

I have tried looking at a previous question related to this [here] but I am still having issues on my end

Here is my code, please ask if you have any more questions. Thank you

#include <SoftwareSerial.h>
#include <SPI.h>
//for SD card connection
#include <SD.h>

SoftwareSerial bluetooth(0, 1); // RX | TX
File root;

void setup()
{
  Serial.begin(115200);
  bluetooth.begin(9600);
  Serial.println("SD text file sender starting");
  bluetooth.println("SD text file sender starting");
  if (!SD.begin(10))
  {
    Serial.println("initialisation failed!");
    while (1);
  }
  Serial.println("initialisation done.");

  //put text file you want to send here
  File dataFile = SD.open("test.TXT");

  // if the file is available, write to it:
  if (dataFile)
  {
    while (dataFile.available())
    {
      bluetooth.write(dataFile.read());
      //line below does not output on the app
      bluetooth.print("test line");
    }
    dataFile.close();
  }
}

void loop()
{
}

what Nano are you using? I guess it is not a Nano 33 IoT with onboard BLE
what is the Bluetooth device?

I'm not sure on the exact Nano it is but I know it does not have BLE. The Bluetooth device I am using is the HC-05

The dumpfile example included in the SD section of the IDE should be all you need. Something like

/*
This programme reads temperatures from  three DS18B20 sensors at one 
second intervals for transmission over bluetooth - no timestamping

Every tenth reading is recorded on SD card in real numbers to two decimal
places. Each line is timestamped.

A new file is created at midnight using the date as the filename.

Daily files can be read from SD via bluetooth by sending MMDD

  Serial.begin(115200);

Credit to Hacktronics, Mellis & Igoe, Garage Box, Zoomkat, Bildr.org, etc.
Kudos to lar3ry in Saskatchewan, Stanley in KL, Coding Badly in Tx.
*/

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

#define DS1307_ADDRESS 0x68

char filename[] = "00000000.CSV";
File myFile;
char dumpName[] = "00000000.CSV";
File dumpFile;

// Green group Dee Why (red or amber LED shields)
byte InThermo[8] =  {0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0x9F };
byte OutThermo[8] = {0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};
byte DrainThermo[8] = {0x28, 0x54, 0xF7, 0x2D, 0x04, 0x00, 0x00, 0x68}; 
  
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
 
byte  second, minute, hour, weekDay, day, month, year;
int k=0;

const int chipSelect = 4;

float tempC, InTemp, OutTemp, DrainTemp;

// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
char sensorId2[] = "DrainThermo";

char charBuf [13];

String readString;
String StringOne;

void setup() {
  Serial.begin(115200);
  
  delay(300);//Wait for newly restarted system to stabilize
  pinMode(0, INPUT_PULLUP);   // just a precaution for bluetooth
  pinMode(53, OUTPUT);//MEGA use poin 10 if Uno
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) 
  {
    Serial.println("Card failed");
    // don't do anything more:
    return;
  }
  Serial.println("CARD OK");
      GetClock();
      getFileName();
  }

void loop() {
   GetClock();
  if (today != day)
  {
   today = day;
   getFileName(); 
   header();
   daily();

  if (thismonth !=month)
  {
    thismonth=month;
    dailyheader();
  }
  }  
    while (Serial.available()) 
  {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }// end while
  if (readString.length() >0) 
  {  
    getDump();   
   readString="";  
  } // end if
  
  //get the values from the DS8B20's 
  sensors.requestTemperatures();

  InTemp = sensorValue(InThermo);
  OutTemp = sensorValue(OutThermo);  
  DrainTemp = sensorValue(DrainThermo); 
  
  k=k+1;  
  if (k>9 )
  {  
  myFile.print(hour);
  myFile.print(":");
  myFile.print(minute);
  myFile.print(":");
  myFile.print(second);
  myFile.print(",");

  myFile.print(InTemp);
  myFile.print(",");
  myFile.print(OutTemp);
  myFile.print(",");
  myFile.println(DrainTemp);
 
  k=0;
  }
  delay(1000);
}  // loop ends here

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

void getFileName()
{
myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE    
sprintf(filename, "%02d%02d%02d.csv", year, month, day);
myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
}

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
  day = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal 
  return ( (val/16*10) + (val%16) );
}

void getDump() {
   StringOne = "2020" + readString + ".csv";
   StringOne.toCharArray(charBuf, 13);  
     Serial.println("");
     Serial.println(charBuf);
  File dumpFile = SD.open(charBuf);
  if (dumpFile) 
    {
    while (dumpFile.available())
    {
      Serial.write(dumpFile.read());
    }
    dumpFile.close();
    }  
  else {
    Serial.println("error opening file");
       }
  }

Should be reasonably self-explanatory. Strip out what you don't need.
`

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.