Go Down

Topic: Transmitting data from a text file from master to Slave HC 05 (Read 274 times) previous topic - next topic

Vismay02

I am trying to send data inside a text file from Master HC-05 to Slave HC-05 and then displaying it in serial monitor.
I have my code below for transmission of data.

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

SoftwareSerial BTSerial(0,1);
File myFile;
char inputString[200];
char inputChar;
int stringIndex = 0;

void setup() {

  Serial.begin(9600);
  BTSerial.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.print("initialization failed !");
    return;
  }
  Serial.print("initialization done");
 

  myFile = SD.open("test.txt");
   if (!myFile) {
    Serial.print("error opening file" );
   
    }
 
}

void loop() {
 inputChar = myFile.read();
  if (inputChar !=' '){
  inputString[stringIndex] = inputChar;
  stringIndex++;
  }
 else{
    BTSerial.write(inputString);
  delay(1000);
  stringIndex = 0;
 }
}

And here's the code for receiver end

#include<SoftwareSerial.h>
SoftwareSerial BTSerial(0,1);
void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);

}

void loop() {
 while (BTSerial.available()) {
    delay(10);
 char inputString[] = {BTSerial.read()};
    Serial.write(inputString);
 }
}

Any help appreciated !

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy