# Arduino Ethernet + SD Card

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/053/118/medium800/arduino_compatibles_3201-09.jpg?1524242587)

This tutorial provides the basics for using a WIZ5500-based Ethernet Shield with an Arduino compatible. The Wiznet WIZ5500 is a modern Ethernet interface chip and is used in the [Ethernet Shield W5500](https://www.adafruit.com/product/2971 "Ethernet Shield W5500")&nbsp;and the [Feather Ethernet Wing](https://www.adafruit.com/product/3201 "Feather Ethernet Wing")&nbsp;available at Adafruit.

The shield form factor works well for ATmega328 based Arduino compatibles like the Arduino Uno R3 and the [Adafruit Metro 328](https://www.adafruit.com/product/2488 "Adafruit Metro 328") (Classic). The shield contains both an Ethernet connection for networks and an SD Card slot for storing data.

The Feather wing works well with a Feather with a SD card slot. The [Feather 32u4 Adalogger](https://www.adafruit.com/product/2795 "Feather 32u4 Adalogger") has an Arduino Leonardo compatible 32u4 processor and a micro-SD card slot. With the Ethernet Feather Wing, it provides the same functionality as the Ethernet Shield+Metro/Uno in a much smaller package. SD and micro-SD are the same for all purposes but the latter is smaller. In this tutorial, when it says do something to an SD card and you are using the Feathers, think micro-SD.

This tutorial assumes you already know the basics of the Arduino IDE, code generation and the Arduino interface. If you are not so familiar with the Arduino IDE, you might check the tutorials in the [Adafruit Learn Arduino Series](../../../category/learn-arduino "Adafruit Learn Arduino Series").

As of the date of this revised tutorial, [Arduino notes their Ethernet Shields are retired](https://store.arduino.cc/usa/catalogsearch/result/?ie=UTF-8&oe=UTF-8&q=Ethernet+shield&domains=&sitesearch=). If you use a retired or third-party Ethernet shield, you may have to use a different Arduino library that supports the chipset the board uses.

**Note that the Ethernet Shield and Feather Wing Adafruit uses is based on the WIZ5500 chip, not the older WIZ5100 chipset or others. The WIZ5500 requires the Ethernet2 library, not the older Ethernet library on Arduino. If you use the older hardware, just be sure you change libraries back from Ethernet2 to Ethernet and double check things.**

This tutorial will go through preparing then using the SD card, both in general then reading the files on a card. The final example will show how to access the SD card remotely over Ethernet. This capability could be the basis for a remote file storage or other program that access a remote Arduino compatible.

# Arduino Ethernet + SD Card

## SD Card Preparation

![](https://cdn-learn.adafruit.com/assets/assets/000/053/117/medium800/arduino_compatibles_SD_Cards.jpg?1524242267)

Danger: 

Ensure you use a computer to pre-format your SD card as FAT16. FAT16 was introduced by Microsoft a long time ago but it is simple and microcontrollers like simple. Many formatting programs support FAT16. Windows supports FAT16 natively with the **format** command and in the File Explorer.

It is suggested that you use the sdcard.org SD Memory Card Formatter app. It is available for PC and Mac.&nbsp;

[SD Card Formatter for SD/SDHC/SDXC](https://www.sdcard.org/downloads/formatter_4/index.html)
Here is a shot of SD Card Formatter with a card inserted.

![](https://cdn-learn.adafruit.com/assets/assets/000/053/119/medium800/arduino_compatibles_Capture.png?1524243108)

# Arduino Ethernet + SD Card

## Reading SD Card Information

The program below is a slightly modified version of the Arduino example&nbsp; **SdFatInfo** program. The main change is to define the SPI select of the WIZ5500 Ethernet chip and set it high (unselected) so the sketch can talk to the SD card only.

For the Ethernet shield, put your formatted SD card into the SD card slot (top side up, don't force it, gentle). Put your shield on your Arduino-compatible board. Power the boards with a suitable power supply recommended for the Arduino. Connect the microcontroller board to your computer with a suitable USB cable.

For the Feathers, place the formatted micro-SD card into the micro-SD card slot in the Adalogger Feather. Plug the board into a USB port on your computer.

Using the Arduino IDE software and select the correct type of Arduino-compatible board and the serial port for the board in the Tools menu. You may have to push the reset button for the operating system to see the serial port. Load the following sketch, compile, and run.

The information about the SD card should be displayed on the serial monitor in the IDE.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Arduino_Ethernet_SD_Card/SDcardTest/SDcardTest.ino

The serial monitor output below is for a micro-SD card formatted in Windows 10 for FAT. It is set for 60MB (it doesn't fill the card, it was an old Raspberry Pi Zero system card). It has several text files and a directory with a couple of files in it. Your Arduino Serial Monitor should display something similar.

![](https://cdn-learn.adafruit.com/assets/assets/000/053/109/medium800/arduino_compatibles_Capture.png?1524235285)

# Arduino Ethernet + SD Card

## Listing Files

Once you are reliably reading SD card information, you can move on to looking at what files might be on the SD card. The code below is the Arduino SD Card Example Listfiles. It is modified to put the WIZ5500 chip select high so the SPI bus is only talking to the SD card.

At this point, please place a few files on the SD card from your computer to get an interesting output rather than using a blank card. It is suggested to put two or three text files with the filenames being no more than 8 characters before the period then end in .txt. An example would be README.txt or todo.txt. You can put the code text files on the card also, having them end in .ino will be fine also.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Arduino_Ethernet_SD_Card/SDfileList/SDfileList.ino

The screen shot below shows information on the same card as in the last sketch but lists the files and their sizes.

![](https://cdn-learn.adafruit.com/assets/assets/000/053/108/medium800/arduino_compatibles_Capture.png?1524234965)

Note in Windows, filenames like WPSETT~1.DAT refer to a longer filename (such as WPSETTINGS.DAT). Microsoft, for compatibility with older software, truncates filenames greater than 8 characters (not including the 3 character file extension) at 6 characters, a tilde (~) character, and a number (in case multiple truncated files exist). The older software cat read and write to the file the same as an 8.3 character file.

The extra information for the long file name is hidden from older software but perfectly safe for newer software. There are no worries opening the shortened filename will somehow corrupt the capability to use the long filenames as long as using the file name per the name you see (and not changing the file name) is observed.

# Arduino Ethernet + SD Card

## Serving Files over Ethernet

Now that all the SD card functionality appears to be working, the program below allows you to view the files on an SD card over the Ethernet interface and download any file you wish.&nbsp;

The program will provide a directory listing of the SD card to a web page. If a directory is clicked, the web page will show the contents of the subdirectory. If a file is clicked, the file will be sent to your computer. If you want to go back up the directory tree, use the browser back button.

The library which provides the WIZ5500 Ethernet functionality is called **Ethernet2**. The Adafruit version of **Ethernet2** has been maintained and should be used instead of the Ethernet2 library available in the Arduino Library Manager. You can get the library code on GitHub at&nbsp;[https://github.com/adafruit/Ethernet2](https://github.com/adafruit/Ethernet2 "https://github.com/adafruit/Ethernet2").&nbsp;

It is suggested that you put the **Ethernet2** code from the Adafruit GitHub repository into your Arduino sketch folder, in the **libraries** subdirectory, in a subdirectory called **Ethernet2**.

For the source code below, you should review the following in the code:

- `Byte array mac[]` is set to a generic MAC address - if you have another device on your home network with the same address, change things a bit. Each value is an 8 bit value in hexadecimal (from 00 to FF).
- `Byte array ip[]` is the Internet Protocol (IP) address of an unused device on your home network. Having the Ethernet board way up at 177 (decimal) is fairly safe - if you know networking and this will not work, if you have your network on a network other than 192.168.1.xxx (say at 192.168.0.xxx or 10.0.0.xxx) change those also. You can find information like this from your Internet router.
- If you want to use DHCP to get an address from your router, uncomment the version of the `Ethernet.begin` call with only the mac address. It may be more difficult to get the address and the address might change is the router gives out a new address. So the default is a fixed address.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Arduino_Ethernet_SD_Card/SDWebBrowse/SDWebBrowse.ino

## Community Fork

There is a [fork of the Ethernet library](https://github.com/SapientHetero/Ethernet) available on GitHub from a community member that is designed to have better performance. Check it out as an alternative to the official release and read more about its features in this [Adafruit Forum post](https://forums.adafruit.com/viewtopic.php?p=1055296#p1055296).

[Ethernet Fork on GitHub](https://github.com/SapientHetero/Ethernet)
# Arduino Ethernet + SD Card

## How it Works and Wrap-up

The main interface for the Ethernet uses code from the standard Arduino example **WebServer** and the SD card code used earlier in the tutorial.

The program implements the very bare bones of an HTML server. The code lists directories then files as an unordered HTML list.&nbsp;

Ensure the project is powered up and connected via an Ethernet cable to your home network. The yellow network activity light should blink now & then on one side of the connection, green on the other. If the lights are not on, check the Ethernet connection.

Open a web browser on a computer on your network and go to address http://192.168.1.177&nbsp;or to the alternate address you coded in your sketch. If you changed the sketch to use DHCP to get a free address from your router, the address received will be print on the serial monitor.

The program should output the heading **Files:** then a list of files on the card. You did put a few test files on the card earlier, yes? If not, no worries, power down the project, eject the SD card, put some text-based files on it, reinsert, and power the project up again.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/052/969/medium800/arduino_compatibles_browseroot.gif?1523569856)

If you click on a file name, the sketch will send the file and the browser will ask you for a location to save the file.

If you click on a directory name, a new web page will appear displaying the files in the subdirectory.

Use the browser back button to go from the text listing screen back to the file list screen.

If there is a request for a file that is not on the SD card, the sketch will return an HTTP 404 error (file not found). Any other error will also return a 404 error.

![](https://cdn-learn.adafruit.com/assets/assets/000/052/968/medium800/arduino_compatibles_browse404.gif?1523569811)

## Wrap-Up
When the original tutorial for using the Ethernet shield and sketch was written 7+ years ago, serving files via Ethernet was pretty novel (read: wicked). Ethernet shields are not as common now. It is likely due to the proliferation of Wi-Fi boards.

Hopefully this updated tutorial will give you the basics for using a microcontroller to access an SD card (or something else) via Ethernet. The same methods can be used if you wire up a SD card breakout to the your microcontroller pins, just be sure to check for any necessary code changes.

Most newer microcontroller boards have more memory, so a more robust web server capability may considered. Perhaps you can look at this code and consider a new implementation with an Adafruit Express board and CircuitPython. The future awaits our innovation.

If you come up with great designs, please share them in the [Adafruit forums](https://forums.adafruit.com/) and in the&nbsp;[Adafruit Discord chat](http://adafru.it/discord).


## Featured Products

### Ethernet Shield for Arduino - W5500 Chipset

[Ethernet Shield for Arduino - W5500 Chipset](https://www.adafruit.com/product/2971)
The W5500 Ethernet Shield for Arduino from Seeed Studio is a great way to set up your projects with internet connectivity with just a single chip. &nbsp;Similar to the[Arduino Ethernet Shield](https://www.adafruit.com/product/201), but with a newer chipset, this ethernet shield...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/2971)
[Related Guides to the Product](https://learn.adafruit.com/products/2971/guides)
### Adafruit METRO 328 Fully Assembled - Arduino IDE compatible

[Adafruit METRO 328 Fully Assembled - Arduino IDE compatible](https://www.adafruit.com/product/50)
We sure love the ATmega328 here at Adafruit, and we use them&nbsp;_a lot_&nbsp;for our own projects. The processor has plenty of GPIO, Analog inputs, hardware UART SPI and I2C, timers and PWM galore - just enough for most simple projects. When we need to go small, we use a <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/50)
[Related Guides to the Product](https://learn.adafruit.com/products/50/guides)
### Adafruit Feather 32u4 Adalogger

[Adafruit Feather 32u4 Adalogger](https://www.adafruit.com/product/2795)
Feather is the new development board from Adafruit, and like its namesake it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather 32u4 Adalogger** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2795)
[Related Guides to the Product](https://learn.adafruit.com/products/2795/guides)
### Adafruit Ethernet FeatherWing

[Adafruit Ethernet FeatherWing](https://www.adafruit.com/product/3201)
Wireless is wonderful, but sometimes you want the strong reliability of a wire. If your Feather board is going to be part of a permanent installation, this **Ethernet FeatherWing** will let you add quick and easy wired Internet. Just plug in a standard

Out of Stock
[Buy Now](https://www.adafruit.com/product/3201)
[Related Guides to the Product](https://learn.adafruit.com/products/3201/guides)
### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)

## Related Guides

- [Adafruit Ethernet FeatherWing](https://learn.adafruit.com/adafruit-wiz5500-wiznet-ethernet-featherwing.md)
- [Arduino Lesson 3. RGB LEDs](https://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds.md)
- [Low Power WiFi Datalogger](https://learn.adafruit.com/low-power-wifi-datalogging.md)
- [Multi-tasking the Arduino - Part 1](https://learn.adafruit.com/multi-tasking-the-arduino-part-1.md)
- [Adafruit PN532 RFID/NFC Breakout and Shield](https://learn.adafruit.com/adafruit-pn532-rfid-nfc.md)
- [WiFi Controlled LED Christmahanukwanzaa Tree](https://learn.adafruit.com/wifi-controlled-led-christmahanukwanzaa-tree.md)
- [Adafruit Proto Shield for Arduino](https://learn.adafruit.com/adafruit-proto-shield-arduino.md)
- [Ladyada's Learn Arduino - Lesson #1](https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-1.md)
- [Smart Measuring Cup](https://learn.adafruit.com/smart-measuring-cup.md)
- [Circuit Playground Sound-Controlled Robot](https://learn.adafruit.com/circuit-playground-sound-controlled-robot.md)
- [Adafruit 4-Channel ADC Breakouts](https://learn.adafruit.com/adafruit-4-channel-adc-breakouts.md)
- [DS1307 Real Time Clock Breakout Board Kit](https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit.md)
- [DIY 8x2 LCD Shield](https://learn.adafruit.com/diy-8x2-lcd-shield.md)
- [Arduino Lesson 6. Digital Inputs](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs.md)
- [Arduino Lesson 4. Eight LEDs and a Shift Register](https://learn.adafruit.com/adafruit-arduino-lesson-4-eight-leds.md)
- [Tiny Arduino Music Visualizer](https://learn.adafruit.com/piccolo.md)
