Read .txt from SD print to serial (another arduino)

Hi everyone, i realized a project which is composed by two arduinos. Once read a weight from a load cell and store it in its SD in a log.txt file like that (for every weight, adding date and time from an RTC):

"*************************************************************READ START
3354g 27/02/2014 19:18:21
**************************************************************READ FINISH"

Then, i store the value of the weight and time in some variables and i send them to the other arduino via serial (PIN1 to PIN0 e GND to GND) with the "EasyTransfer" library.
You should think that there will be about 10 weighted during the day, so, ten times the string i wrote between the sentences...

THE QUESTION IS: is there a method to copy and send via serial (also without storing in variables, it doesn't matter, suggest me the best solution) ALL the string in the log.txt of the "arduino weighted" to the second arduino (creating a new .txt file) WHICH STORE IT IN ITS OWN SD?

I know it's quite complex and maybe not so clear but hope someone could help me... THANKS, Valerio.

You need to provide some way for the two Arduinos to communicate with each other. There is a huge number of options for that and I have no idea which ones you have in mind.

Once they can communicate, you need to design the two sketches so that the sender sends the content of the file when you want it to, and the receiver receives the text from the sender and writes it to a local SD file. It's conceptually simple, but exactly how you do it would depend on what communication mechanism you're going to use.

yeah, @PeterH, is what i'm asking...

I NEED a piece a sketch that allows me to read the entire file from the sd of the first arduino and, passing it via serial (or maybe other communication methods if they will be better), and write the entire file into a new one in the second sd of the second arduino...

Hope i was clear and hope someone could help me! Thanks in advance!

how are the two Arduinos "connected" ?

retronet_RIMBA1ZO:
how are the two Arduinos "connected" ?

They're connected pin1 to pin0 and gnu to gnu with a high quality and short cables. If a different technology like bluetooth, another serial, wifi ecc... could be better, please, suggest to me (with relative sketch). Thanks!

yes, pin 0 & pin 1 are RX & TX for Serial communication - and i think you mean 'GND' ?

Bluetooth is basically Serial but wireless.

have a look at this page;

the relevant functions would be Serial.println() to send, and Serial.read() to receive.

Put the 2 Arduinos on the same SPI bus. SPI bus is capable of 1 megabyte per second data transfer @ 16 MHz clock.

Simplest, not as fast:
Connect both SD chips the SPI bus on one Arduino, you don't need the other but it can be there. XD
A) Select the read-from SD, open file, find and read one buffer of data. Deselect that SD.
B) Select the copy-to SD, open file, append one buffer of data to file. Deselect that SD.
C) Repeat from A until End Of File is reached.

Fast:
Each Arduino/AVR needs 1 free hardware serial port for this. AVR serial ports are capable of full speed master-mode SPI. Put 1 SD on each controller's otherwise unused hardware serial port as a dedicated device. When you open a file on those, it STAYS OPEN and the SEEK stays current. You can pass information from card to card without buffering and the only slowdown will be the slowness of the SD cards if they are low class.
You might sustain near of not 1 MB/sec with fast camera cards.

If all you want is to copy cards then consider that a MEGA2560 has an SPI port plus 3 EXTRA serial ports. It can support 4 SPI channels. It can share/transfer SPI from bus to bus at speed, which is @&$% awesome!

GoForSmoke:
Each Arduino/AVR needs 1 free hardware serial port for this. AVR serial ports are capable of full speed master-mode SPI. Put 1 SD on each controller's otherwise unused hardware serial port as a dedicated device. When you open a file on those, it STAYS OPEN and the SEEK stays current. You can pass information from card to card without buffering and the only slowdown will be the slowness of the SD cards if they are low class.
You might sustain near of not 1 MB/sec with fast camera cards.

YESS, u've perfectly understood @GoForSmoke!
This is what i want, files open and copy directly from one to the other...
i've generally understood the SPI communications BUT if you can, could you paste me some sketch or links that i could modify to make it works? i don't know how to configure, cabling and programming the two arduinos to make them transmit on the SPI bus.

REALLY thanks to you, and if you want to continue help me with these sketches i'll really happy to make a donation to you!

retronet_RIMBA1ZO:
http://arduino.cc/en/Reference/SPI
http://arduino.cc/en/Tutorial/ReadWrite

thanks, but any example of sketch? How should i set the SPI address in the arduino? and the SD card? shouldn't they make an error? Could someone explain me better, please?

VALERiOSPQR:

retronet_RIMBA1ZO:
SPI - Arduino Reference
http://arduino.cc/en/Tutorial/ReadWrite

thanks, but any example of sketch? How should i set the SPI address in the arduino? and the SD card? shouldn't they make an error? Could someone explain me better, please?

did you actually click those links ? and skim through the whole page ??

retronet_RIMBA1ZO:

VALERiOSPQR:

retronet_RIMBA1ZO:
http://arduino.cc/en/Reference/SPI
http://arduino.cc/en/Tutorial/ReadWrite

thanks, but any example of sketch? How should i set the SPI address in the arduino? and the SD card? shouldn't they make an error? Could someone explain me better, please?

did you actually click those links ? and skim through the whole page ??

Yes, i'm talking about the SPI, 'cause i just use the ReadWrite and i know it i wouldn't been surly, just need some examples for the SPI. Thanks again!

the "address" is determined by the SS pin, usually pin 10 on the Arduino Uno.
just look at the Examples in your Arduino IDE.

VALERiOSPQR:

GoForSmoke:
Each Arduino/AVR needs 1 free hardware serial port for this. AVR serial ports are capable of full speed master-mode SPI. Put 1 SD on each controller's otherwise unused hardware serial port as a dedicated device. When you open a file on those, it STAYS OPEN and the SEEK stays current. You can pass information from card to card without buffering and the only slowdown will be the slowness of the SD cards if they are low class.
You might sustain near of not 1 MB/sec with fast camera cards.

YESS, u've perfectly understood @GoForSmoke!
This is what i want, files open and copy directly from one to the other...
i've generally understood the SPI communications BUT if you can, could you paste me some sketch or links that i could modify to make it works? i don't know how to configure, cabling and programming the two arduinos to make them transmit on the SPI bus.

REALLY thanks to you, and if you want to continue help me with these sketches i'll really happy to make a donation to you!

Are you only wanting to copy SD cards?

VALERiOSPQR:

retronet_RIMBA1ZO:
http://arduino.cc/en/Reference/SPI
http://arduino.cc/en/Tutorial/ReadWrite

thanks, but any example of sketch? How should i set the SPI address in the arduino? and the SD card? shouldn't they make an error? Could someone explain me better, please?

When you open your Arduino IDE, under FILE instead of open or sketchbook, click examples and the move down to SD and under that are SD example programs compliant with your version IDE. Try the bottom one, ReadWrite.

The page on that example on the Arduino site explains the wiring and what the code is supposed to do. You load the code and refer to the IDE and the web page until you can use it in your project,

PS: ReadWrite is an SPI example.

double-take: WHAT SPI address? No. SPI slaves have select pins. They are deaf to the bus when not selected. SPI master runs the selects though in some setups some selects and data lines are daisy-chained on one pin.

No address. Pins.

Thanks @GoForSmoke and @retronet_RIMBA1ZO, i try the sketchs you suggest and see the references...

@GoForSmoke, yes, i want to copy ALL the byte of the file in the first SD to the second, without analyzing or simpling anything, just copy in a new file! so i think i'm on the correct way!

I will update soon!

I have another question. The second step is to pass all the .txt files from the sd (where the were copied) to the pc via usb.
Does anyone know some
Method? I have to transfer all the file (like a memory card reader, that i won't use).

Only need 1 AVR and 1 SD to copy from and 1 to copy to.

Here is a good page to bookmark, as are the Reference, Examples and AVR LibC pages for a nice start.

Click on SD on that page and read or you won't know what you're doing or asking about SD.

Then go to the SPI link and see how SPI works.

If you get the full ATMEL datasheet for the ATmega48A though 328P family, section 21 is USART in SPI Mode.
My copy is a PDF and it won't allow me to copy to clipboard as text so please, don't make me type what can be downloaded for free. Get the complete, it is the chip reference for a whole AVR family ending with the 328P.

GoForSmoke:
Only need 1 AVR and 1 SD to copy from and 1 to copy to.

Here is a good page to bookmark, as are the Reference, Examples and AVR LibC pages for a nice start.
Libraries - Arduino Reference

Click on SD on that page and read or you won't know what you're doing or asking about SD.

Then go to the SPI link and see how SPI works.

If you get the full ATMEL datasheet for the ATmega48A though 328P family, section 21 is USART in SPI Mode.
My copy is a PDF and it won't allow me to copy to clipboard as text so please, don't make me type what can be downloaded for free. Get the complete, it is the chip reference for a whole AVR family ending with the 328P.
http://www.atmel.com/devices/ATMEGA328P.aspx

Ok, now it's better, i just know something else about SPI and understood how it works...

...AFTER I'VE OPENED the file in the first arduino and the second file in the second arduino, how can i read and send at the same write and log in the other? i can use the ReadWrite commands but how to send and write once opened the files?
PS: is there a method to give to the file i'm creating a specic name?

Thanks again!

VALERiOSPQR:
...AFTER I'VE OPENED the file in the first arduino and the second file in the second arduino,

Oh no! One Arduino with 2 SD. Each SD must be on a different SPI bus so that both can stay selected the whole time. You could use Two Arduinos but why? Also the current SPI library may need work to be able to use a hardware serial port instead of the regular SPI port.

how can i read and send at the same write and log in the other? i can use the ReadWrite commands but how to send and write once opened the files?
PS: is there a method to give to the file i'm creating a specic name?

Thanks again!

Usually data to and from a file device like SD card is done through a buffer. You read to fill the buffer and you fill the buffer before you write it. You could open two SD device objects each with its own buffer then read a buffer into one, copy that to the other buffer and write that out. Or you could change the library code a bit to make them use the same buffer and save the copy step.
I'm not sure but it might be possible to run both SD's at once using a circular buffer where one fills and the other reads until pointers catch up then one waits. The only thing more direct would be reading the byte from the input SPI port and writing it directly to the output SPI port or gate logic right across the wires.

Open a file that is not present, the name will be the name you gave it within the DOS 8.3 name limits.
The Arduino SD library has no file rename function and given that SD media has limited writes, it is probably a bad idea to want to change the names much. I would simply make the change to the card on my PC to do once.
Remember you can use a computer to prepare data on SD that the Arduino will use later.