problems with Sending .txt file to arduino

Hello everyone,

How can I send .txt from SD card and transmit it to another Arduino. I am working on a project where i have to store data on SD card when i don't have internet connectivity, and I have to read saved data from SD card and transmit it to arduino when i get connectivity back.

What I have achieved: I have saved data to SD card in .txt format after loosing Internet connectivity and I have read data from SD card and printed it on Serial Monitor.

My question is: I am unable to convert this .txt file to String for Serial Transmission to another arduino. just need direction and guidance, how should I work.

Thanks to all in advance :)

I have saved data to SD card in .txt format after loosing Internet connectivity and I have read data from SD card and printed it on Serial Monitor.

So what is the problem? If you can send stuff to the Serial monitor, you can send it anywhere. How do you communicate with the other Arduino?

Maybe showing your code will help us as well to help you.

sterretje:
So what is the problem? If you can send stuff to the Serial monitor, you can send it anywhere. How do you communicate with the other Arduino?

Maybe showing your code will help us as well to help you.

I am new to all this, I don’t know this approach is useful or not,

This is the sketch I am working on:

#include <SPI.h> //for sdcard
#include <SD.h> //for sdcard
#include <Wire.h>

File myFile; //for sdcard write
int pin=16; //for sdcard

void setup()
{

Serial.begin(115200);

while (!Serial)
{
; // wait for serial port to connect.
}

Serial.println(“Initializing SD card…”);

if (!SD.begin(pin))
{
Serial.println(“initialization failed!”);
return;
}
Serial.println(“initialization done.”);
readSDSettings();
}

void loop()
{
}

void readSDSettings()
{
char character;
int a;

myFile = SD.open(“esp.txt”);
if (myFile)
{
while (myFile.available())
{
character = myFile.read();
while((myFile.available()) && (character != ’ '))
{
character = myFile.read();
Serial.write(character);
// char str[15]; //////////////////////////////////////// trying to convert from ASCII
// a=character - ‘0’;
// sprintf(str, " %d",a);
// Serial.print(a);
//Serial.write(a);
}
}
// close the file:
myFile.close();
}
else
{
// if the file didn’t open, print an error:
Serial.println(“error opening settings.txt”);
}
}

Thanks for the code. Please edit your post with the code and use code tags

Type ``` [code] ``` before the code Type ``` [/code] ``` after the code

The result will be likeyour code here It's easier to read and copy and some more advantages.

OK, so we don't know how you're planning to connect your two Arduinos. I2C? Serial? SPI?

In it's simplest form, you can connect the TX pin of the Arduino with the SD card directly to the RX pin of the second Arduino and simply use Serial.read() on that one. What you currently see in the Serial monitor will also be send to the other Arduino. Don't forget to also connect a GND between the two boards.

Note that in that case you can not use the USB port on the second Arduino for communication with the PC (you probably even need to disconnect the wire between the two if you want to upload a sketch to the second Arduino).

Which Arduino's are you using? If you have ones with more than one Serial port (e.g. Mega), you can use the second serial port for communication between the two to prevent this 'problem'. I2C and SPI also don't cause this 'problem'. And lastly you can use SoftwareSerial (basically on any free pin).

Further you might want to design a form of protocol to indicate to the second Arduino e.g. the beginning and the end of the transmission. And the second Arduino might have to indicate to the first one that it has finished processing a bunch of data and is ready to receive a new lot.

e.g. 1) first arduino sends 0x02 (STX) and waits for reply 0x06 (ACK) 2) seconds arduino replies with ACK; it now knows that a bunch of text data is coming 3) first arduino sends a bunch of data (e.g. a line) to second one and waits for ACK 4) second arduino sends ACK when done processing (sending over internet) 5) back to (3) if there is more data to read fro the file 6) first arduino sends 0x03 (ETX); second arduino now knows that the data is complete

See http://www.asciitable.com/ for the numbers

Use serial.write() to send STX, ETX and ACK.