---
title: "Arduino Due + Ethernet Shield + Micro SD HTTP Server app in Microchip Studio"
url: "https://maker.wiznet.io/scarlet/projects/arduino-due-ethernet-shield-micro-sd-http-server-app-in-microchip-studio/"
markdown_url: "https://maker.wiznet.io/scarlet/projects/arduino-due-ethernet-shield-micro-sd-http-server-app-in-microchip-studio/md"
type: "UCC: User Created Content"
author: "E-exp"
author_url: "https://www.youtube.com/watch?v=db6ngwVqeYo"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "E-exp"
original_url: "https://www.youtube.com/watch?v=db6ngwVqeYo"
published: "2023-11-02"
language: "en"
likes: 0
views: 189
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Arduino Due + Ethernet Shield + Micro SD HTTP Server app in Microchip Studio

> This time we do a HTTP request handling server app that loads the web page and a image from a FAT32 formated Micro SD card or from the internal flash memory - g

Original author: E-exp (source: https://www.youtube.com/watch?v=db6ngwVqeYo)

## Article

(6) Arduino Due + Ethernet Shield + Micro SD HTTP Server app in Microchip Studio - YouTube
https://www.youtube.com/watch?v=db6ngwVqeYo

Transcript:
(00:01) hi we are back with rinoda together with the wiznet Ethernet shield and for today I have got a HTTP server and it works that way that uh it loads the web page and also the image from the micro SD card like so we can also send [Music] comments and we can see them right here so we can process them and also if we don't have the micro SD card so if we remove it we will load the default page and the image from the internal flash memory okay so now let's take a look at the project but first a few words how the
(00:56) communication here works so this is our address we have to connect to so let's type it in and we can see a few requests from the browser so the first one is the default web page request so we just send here the HTML file in this case it's located on the micro SD card and after we send the whole page we have to disconnect after we disconnect we connect again and this time we read the next request and this time it's the image file so we send the image file also from the micro SD card because we found it
(01:55) here and after this we also have to disconnect so the browser will not that it received everything and it has to display it so a page like this so now let's take a look at the main function here so let's start off with the top of the file and here we got the variables that hold up the web page this is a web page without the request for the image and this variable holds up the web page that is displayed currently and uh if this is sent the web browser will also ask for the image and this variable holds up the
(02:55) image to send uh those files I mean variables are made with the lvp so in the case of a web page you have to erase the first row right here so it's already deleted and in the case of the image uh you have to also delete those first uh rows the first one here is uh deleted so it's this plus one over here to delete because it puts some headers on the image file and we don't really want to send stuff that is not related to it so
(04:01) like so uh also uh what I got here is a compare function it uh differs from the build one uh which is uh Str Str CMP because we can just simply compare two strings uh with a given length so if they match they the output is one and if a don't match it's set to zero and it's returned so it comes pretty handy next on we got the usual for the SPI transfers initialization of the SPI for the wizet IC and also right here I added a function to make an init to the chip select number one so the micro SD card next on after this this is just the
(05:08) usual to set up the wiznet IC just like it was in the tnet server example the configuration of the uh slot zero of the wiznet IC the usual sending of the messages through the IC also a a function to send the whole page which is the located one in the flash memory so by the way if you want to put something in the flash memory you simply have to declare it as a static constant and it will not be put into the ram just in the flash memory which the do not du has quite a lot but the RAM is quite the issue here okay and the receive function this
(06:14) is the same as in the Tet server example functions here also the same and right here we got the init function for the micro SD card it uses the slot one and right here I have a function to check the existence of a file in the micro SD card so if it exists and it has a size more than zero it's returned that it exists so the size of it if it doesn't exist it will return zero and if it does we have a function to create chunks of data from the file that we want to send and right now uh I'm sending 100 of Charters from the micro
(07:11) SD card to the wiznet IC it can be increased so instead of this it can be 16 so you can send uh really bigger amount of data to make it a little bit speed up and right here we are at the main function so the usual setup of the board the clocks and the peripherals also the USB the chips select the micro SD card the wiiz net SPI and we set up the IC with the socket zero and the usual of checking the statuses of the socket zero and if it is connected we print out who did the call and we check the data that is
(08:16) coming from the web browser so we copy the data here first seven and check if it was a default get method or it was the get for the image here or if it was a post method to send a command so the first one here is uh sending back the image so first of all we check if it is available on the micro SD card if it is it's being read from the micro SD card here and also we have to make sure we got the the chip select one uh active here and after this make sure you got uh chip select zero for the wisnet IC configured and send it the data from the
(09:16) uh micro SD card to the wisnet IC and chunks of data to be exact at least I mean uh the limit here is 100 chapters it can be less because if we are at the end of the file okay and if we don't have the micro SD card here we can send the image from the flash memory which is on the top of the file and we also send it in chunks of data up to 100 Charters it can be also increased for better speed performance and after this we will tell that we are done with sending and we have to disconnect uh you don't really have to
(10:13) make an reset just simply to make sure it's disconnected and then reconnect it so the reconnect goes through going to the beginning of the loop here so we read the status and we reconfigure it and now we check up the web page so if we have the file i. HTML on the micr SD card available we can send it from the micro SD card to the uh web browser through the wizet I see so if we don't we can just send the uh HTML file from the flash memory so after we got it sent we have to also
(11:20) disconnect and reconnect so this reset here is really optional you don't have to use it so if you have a few more sockets in use uh you don't want to use it but in this case it's only one socket so we can do this now let's take a look at the post method so the time we send the command uh for this case add the read right here we check if we have enough data and if we do we just simply copy the last 20 uh Charters from the post and here we check that we got the where we got the pointer to the
(12:27) data so it was F name so right here I'm looking where we got M E equals and then the command so this will be the pointer to the command and we can we can print out the command right here using a for Loop and after this we also have to disconnect okay so we can also send something manually of you if we like to right here but that's pretty much it h one more one more thing to mention here is how to add the micro SD card so let's take a look at the ASF first okay so the ASF loaded and if you add the SD MMC stack you have to make
(13:28) sure after adding it from this side to this side you have this component enabled so this will generate two files which are those two and those are the accesses for applications like the fats and if you go to this file uh those two interface are used for it and if you go right here you can see that those functions are in use because those functions are located in the generated files and also one thing to mention here if you generate it the first time uh you will have the access memory to Ram not enabled so in order in order to use it
(14:27) you have to declare it at the top of the file like so so you will be able to use the access to the micro SD card okay next on the configuration of the board the SPI zero and you can uh use the chip selects here but this is optional because we have to de where the chip select also in the functions to access the micro SD card through the SPI so let's take a look at the outline and let's search for the functions that select and deselect the devices so this right here uh so you have to make sure that the
(15:34) driver knows which pin to use so I added the uh chip select method right here so uh I make sure that the wizet IC is not on so only the micro SD card is receiving uh the data and also in the deselect make sure that it really is deselected for proper communication so with those steps and also one additional right here so the SPI zero chip select one the micro SD card will finally work and also one thing to mention here I had a little bit of problems uh
(16:40) reading the file of the micro SD card because I was using the global variable [Music] here in this place and it always had a error of invalid object so if I change the global variable here to a local it doesn't have any issue so you have to use something like this and after the read I M Copy so this solves the read problem here and this is pretty much it so let's take a look okay so let's reset the board to get the welcome message let's refresh the page so we get the page and the file and uh let's remove the SD
(17:49) card and let's check the files we got there so let's insert the card and let's take a look at it didn't get [Music] detected yeah this something happens so we have to disable and reenable the uh class manager and here we have the files in the micr SD card so let's open the web page with a notepad so this is what's being sent as the default page from the micro SD card so right here you get the image that the browser will be looking
(18:55) for and this image is located here so we can open it and see that this is the exact one that is here and if we refresh refresh the page we got the default one with the uh old image so thanks for watching hope you find it useful in your projects and see you in the next one

---

Source: https://maker.wiznet.io/scarlet/projects/arduino-due-ethernet-shield-micro-sd-http-server-app-in-microchip-studio/
