Go Down

Topic: Sending .txt file to arduino with zigbee (Read 695 times) previous topic - next topic

Vromoturion

Hi,

i want to send a txt file from pc to arduino through wireless
zigbee protocol using xbee pro S2B and then arduino will store it
in sd memory card.
Is it possible to do so? Have any suggestions of how to do the sending
and the storing? If code is provided it will be a great assistance.
Thank you in advance!!

PaulS

Quote
Is it possible to do so?

Yes.

Quote
Have any suggestions of how to do the sending

Write an application on the PC.

Quote
and the storing?

Use the SD class.

Quote
If code is provided it will be a great assistance.

And you won't have learned a thing.

Vromoturion

Hmmm some explanation is needed...
For sending
The app you suggest in what programming language
must be implemented? How will it be structured?
Doesn't exist a more straightforward way to do this?
For storing
Has the sd class a way to store data from xbee and reconstruct
the file to sd from the packets that we sent from pc or i must write
some sort of function? If i write the function how i do the reconstruction
of the file is there a reference to this proccess?
Thank you!!

zoomkat

For starters I suggest you modify the below example code to capture a string sent from the serial monitor and write the string (or String) captured to the SD card.

Code: [Select]

/*
  SD card read/write

This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4

created   Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.

*/

#include <SD.h>

File myFile;

void setup()
{
// Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
// nothing happens after setup
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Vromoturion

Ok that was really helpful because an idea occured to me...
So i have another question...
Can i sent through x-ctu variables and then have arduino listening to
serial connection and to group them and save it to .txt files like this:
2 3 -5 6
4 8 10 -7
-10 -3 4 5
6 7 8 2
basically a matrix[14][4]
if that can happen then i can figure out the rest...

PaulS

Quote
Can i sent through x-ctu variables

No. You can send VALUES that the receiver might store in a variable.


Vromoturion

Thanks for the response...
Can i ask what do you mean by saying might?
Is there a problem with this aproach? (connection or arduino related)

PaulS

Quote
Can i ask what do you mean by saying might?

Code: [Select]
if(Serial.read() == 'a')

char letter = Serial.read();

In the first statement, the value is not stored in a variable. In the second statement, it is.

Quote
Is there a problem with this aproach? (connection or arduino related)

No. There are possible problems with the implementation. Those can be avoided by using start and end of packet markers and delimiters between values (spaces are fine).

Vromoturion

Now i get it, thank you for the explanation!!

Go Up