Pages: [1]   Go Down
Author Topic: WEB then to SD Card  (Read 1006 times)
0 Members and 1 Guest are viewing this topic.
Houston Area
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good day,

I'm using the ethernet shield and Uno. I'm reading data from a serial port then I go out to the Internet to get info and then write the respone from the NET to the SD card.
I have done this project in pieces and each piece works but I have a problem when I put it all together.

The first time through it works fine but it fails to connect to the SD card after that. I have to reboot.

I have a "client.flush" and "client.stop" at the end of reading data from the URL.
I use "file.begin(4)"  and "SD.open" to open the file and then  "file.close" when done.

Can I use them both as long as I stop one before starting the other?

Thanks
Randy



 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The first time through it works fine but it fails to connect to the SD card after that. I have to reboot.

I have a "client.flush" and "client.stop" at the end of reading data from the URL.
I use "file.begin(4)"  and "SD.open" to open the file and then  "file.close" when done.

Can I use them both as long as I stop one before starting the other?
I use them both without diddling with the SS pins. When I did try to diddle with the SS pins, to ensure that only the correct device was active, it did not work.
Logged

Houston Area
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul for the reply.
Can you give me an example of using ethernet and SD in the same sketch?

I can't get it to work. First iteration it goes out to a URL, reads the data and writes to the SD card.
After that the sd.begin(4) fails. Still reads the data from the URL.

Randy
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SD.begin(4) can only be called once.  This is a bug in the SD.h wrapper for SdFat.

You should not need to call SD.begin() other than in setup unless you change SD cards.

You can fix SD.begin by editing SD.cpp in the libraries\SD folder of the Arduino IDE.

Add a root.close() statement to begin like this:
Code:
boolean SDClass::begin(uint8_t csPin) {
  root.close();
  /*

    Performs the initialisation required by the sdfatlib library.

    Return true if initialization succeeds, false otherwise.

   */
  return card.init(SPI_HALF_SPEED, csPin) &&
         volume.init(card) &&
         root.openRoot(volume);
}
Logged

Houston Area
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,
I will move it to the setup and see if it works.
Logged

Houston Area
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good Afternoon,

Ok no luck so far.
- moves SD.begin(4); to the setup.
- the code change that fat16lib suggested is already in the cpp file.

On the first iteration it writes to to the SD card.
   strcpy_P(prog_buffer, (char*)pgm_read_word(&(string_table[4])));       // UPC file.
   upcFile = SD.open(prog_buffer, FILE_WRITE);
prog_buffer equals the file name and upcFile = 1.

After that prog_buffer still equals the file name but upcFile = 0.
I'm perplexed...


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm perplexed...
And we can't see your code.
Logged

Houston Area
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I could not upload the entire sketch because of the size but I think the problem is memory.
I did some cleanup, and it started working.
I still have more code to add so I will see what happens. I also have another post in programming.
Thanks for your comments.
Logged

Pages: [1]   Go Up
Jump to: