Adafruit Data logging shield together with Ethernet shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

Hi there,

Can I use the data logging shield together with the Ethernet shield on an Arduino Duemilanove?

The Ethernet shield uses the digital inputs 10 through 13. From the SdCard.h header file in the Fat16 library, it appears the pin settings for the data logging shield on an Arduino Duemilanove are the same as for the Ethernet shield.

Is it easy to reassign the pins on the data logging shield to others that are not in use?

Thanks,
Ovidiu

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by adafruit »

you would have to reassign the CS pin, which includes cutting the trace on the PCB (not hard just have to be careful) and then also changing it in the header file

User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

Thanks for the fast response! I'm a software engineer, and hardware is just something I do for home projects.

By looking at the diagram below it seems I need not only the CS pin reassigned, but also the MOSI, SCK and MISO pins. Am I missing something?

http://www.ladyada.net/make/logshield/design.html

I presume there's an easy way to solder few wires from the old locations to the new ones. Is this correct? If not, perhaps a future board can implement a cleaner solution?

I'm trying to build a controller for some hardware which I can connect to using my web browser. I'm using the Ethernet shield for connectivity, and I've written some code that implements a basic Web server. I now want to be able to log some data in a set of log files and access them through the web server. Thus having the ability to use both the Ethernet shield and the data logging shield is essential.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by adafruit »

the other pins can be shared

User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

This is good news. I've ordered two data logging boards, as soon as they arrive I'll make the modification and let you know how it works out. Thanks!

User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

All right, it works!

I cut the trace as shown in the picture below. This was the easy part.

Figuring out the software modifications took some time tough, and I spent the better part of this afternoon trying to understand what was going on. I played with the Fat16 library, since this is what I intend to use. I tried changing the value of SPI_SS_PIN in SdCard.h from 10 to some other, unused pin. Using any other pin value from 2 to 9 did not work.

After researching Google a bit, I found the following on another board:

http://asynclabs.com/forums/viewtopic.p ... t=63#p1156
note that on the avr it may still be necessary to keep the original chip select pin as an output to avoid disabling spi on the avr. sounds strange, but i found it in the documentation of the 328p--if pin 2 on port b is not set as output, or held high as an input, then the spi bus will not function as a master.
So my solution is to enable pin 10 as output and set it to high if that is not already chosen as the default SS pin. See the diff file I attached to this message.

Modifying the SdFat is trivial, just use the same idea inside ArduinoPins.h.

I still need to test this together with the EthernetShield, but I have no doubts it will work.
Fat16-changes.txt
Fat16 diff for SdCard.{h,cpp}
(1.26 KiB) Downloaded 345 times
Original board with the trace cut.
Original board with the trace cut.
datalogger-shield.jpg (674.12 KiB) Viewed 8789 times
Modified shield.
Modified shield.
datalogger-shield2.jpg (939.01 KiB) Viewed 8789 times

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by adafruit »

its also mentioned here http://www.ladyada.net/make/logshield/design.html
Finally we have the arduino interface. The Datalogger shield uses 6 pins. Analog 4 and 5 are the i2c hardware pins. The SD card uses Digital pins 13, 12, 11, and 10. The first three are pretty much required. If you really need pin 10, you can edit the library header file and change it from pin 10 to any other pin. BUT you must have pin 10 as an output, if its an input, the SD interface wont work (its a really annoying thing about AVRs - not sure why this is). A standard 6 pin ISP header is available in case you want to program the Arduino with code using a stand-alone programmer

User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

OK, I finally had a chance to test the modified Data Logging shield with the Ethernet shield. With the combination of the two, the Ethernet shield is working just fine, but the modified Data Logging shield is not. :(

Again, the modified Data Logging shield now uses pin 6 as SS instead of the default pin 10. It works just fine by itself with an Arduino board and a modified Fat16 library.

I tried stacking up an unmodified Data Logging shield on top of the modified Data Logging shield. If I modify the Fat16 library to use pin 10, the ls test program works just fine on the unmodified data logging shield. If I change the library to use pin 6 as the SS pin, I get an error and the modified data logging shield does not work. It seems to be the same error whether I stack the Ethernet shield or the unmodified Data Logging shield: the waitForToken() call inside cardCommand() fails with a timeout.

Any thoughts on what's going on?

jaredforshey
 
Posts: 1
Joined: Wed Jun 09, 2010 2:28 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by jaredforshey »

While researching the possibility of using ethernet and SD cards together I ran across this article http://www.arduino.cc/playground/Main/E ... wareSPIMod on the Arduino Playground. Check out the bottom section titled "Buggy Wiznet SPI". Basically there was another hoop the author had to jump through to get the onboard SD card working on the arduino ethernet shield. Maybe this has something to do with it?

User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

Jared, this is awesome! It does turn out the problem was indeed caused by the buggy Wiznet SPI on the Ethernet shield.

I tried the temporary solution first - connect pin 7 to PROG pad and it worked! I then cut the trace from pin 8 and connected pin 8 to the PROG pad as described. This worked too!

So now I have a Data Logging shield and the Ethernet shield working together! Awesome stuff, thanks so much!

To summarize what I have. I modified the Data Logging shield as described in my previous post above, except the CS pin is connected to pin 9. I also applied the patch above, which make pin 10 an output pin and sets it up to HIGH, and changes SPI_SS_PIN to 9 in the SdCard.h in the Fat16 library. I modified the Ethernet shield to cut out the trace from pin 8 and connect pin 8 to the PROG pad.

Thanks everyone for suggestions!

One more thing. The Ethernet shields I got from Adafruit and Sparkfun don't have the SD card holder soldered onto it. Any ideas what's going on? I guess I could save the $20 I paid for the Data Logging shield by simply using the SD card on the Ethernet shield.

User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

Here is a picture of the hardware modifications I've done to the Ethernet Shield, so it can work with the Data Logging shield.
Modifications to the Ethernet Shield
Modifications to the Ethernet Shield
EthernetShieldMods.jpg (972.88 KiB) Viewed 8701 times

User avatar
ovidiu
 
Posts: 13
Joined: Tue May 25, 2010 6:33 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ovidiu »

I just finished writing a tiny web server running on an Arduino Duemilanove with modified Ethernet and Data Logging shields. I can upload files to the Arduino web server using HTTP PUT, and have the files are stored on the SD card. After that the files can be served back and viewed by any web browser.

In the process I've discovered a bug in the Ethernet library that comes with Arduino 018. The read() method cannot differentiate between data not being available on the Ethernet shield and a 0xFF byte. This is a problem if you need to upload binary files like images, zip files etc. to your Arduino web server.

To fix, I've added the following two methods to Client.{h,cpp} (in libraries/Ethernet/Client.h).

Client.h:

Code: Select all

  int read(uint8_t* ch);
  int read(uint8_t *buf, size_t size);
Client.cpp:

Code: Select all

int16_t Client::read(uint8_t *ch) {
  if (!connected() || !available()) {
    return -1;
  }
  return recv(_sock, ch, 1);
}

int16_t Client::read(uint8_t *buf, uint16_t size) {
  uint16_t i;
  for (i = 0; i < size; i++) {
    if (read(buf + i) == -1) {
      break;
    }
  }
  return i;
}
If there's interest in the tiny Arduino web server, I'll make it available as a library.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by adafruit »

very nice! please do post, that would be super cool

ronsonol
 
Posts: 2
Joined: Wed Jun 16, 2010 2:41 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by ronsonol »

I want to place an order for the Arduino Mega, Ethernet shield and Adafruit data logger shield.
Before I place this order, can anyone confirm that these three pieces can work together on the Mega?

I understand that some modifications are required:
rearrange pin assignments on both shields(as descbribed above), and
pin 10 an output pin, and define SPI_SS_PIN to 9 in the SdCard.h in the Fat16 library.

Mostly unsure if all this data applies equally to the Mega board.

ovidiu, I would be very interested in your webserver, as it is similar to what I hope to setup.

Many thanks for your time.

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: Adafruit Data logging shield together with Ethernet shield

Post by fat16lib »

The SPI pins on the Mega are: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS) so it takes a lot of hardware hacking to make it work.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”