Panda + SD Card + Impressions

Brand new to FEZ line. Just started playing around. Shot a video of my impressions and attaching my own SD adapter. Great stuff all around.

Keep it EZ!

I like the connector :slight_smile: are you going to make a wiki page explaining how you wired the sd card?

That was a awesome first project! I agree with Gus … please post an article somewhere with wiring instructions.

-Eric

Great work GlingON :clap:
I would also like to see a wiring diagram as I need something like this for my Panda.

Regards
Geir

Sine this seem to be interesting to a lot of users. I added 200 experience points to your account and 300 more if you make a wiki page detailing to anyone how they can wire an SD connector to FEZ Panda

Here is my very preliminary project page that right now is just basically holding the wiring/pin diagram (which is the brunt of it). I’ll be adding some more about SD sockets and a full explanation of the wiring.

(link removed)

Very nice diagram. You should add your video to that page too.
When done let me know and I will add your points.

Thanks GlingON. That is just what I needed.
By the way, have you seen this?
[url]http://www.instructables.com/id/Cheap-DIY-SD-card-breadboard-socket/[/url]

@ Geir, that is really cool, there are some crafty people out there! At the same time, SD Card sockets are almost as cheap as headers!

I got the final version up. Lots of diagrams, hopefully it’s helpful.
(link removed)

Points are added, thanks :slight_smile:

Just wanted to add a “Mitu”(pronounce “me too”). After reading the original post, I built one of these as well. I won’t be posting a project page 'cuz I didn’t do much original. Here is a picture of the finished project. Like GlingOn I started by soldering a 10-Pin right angle male header to the panda, and a 10-Pin female header to a scrap of Radio Shack prototype board. I then added the SD card socket, http://www.sparkfun.com/commerce/product_info.php?products_id=136.
It should be noted that care must be exercised when soldering the socket since not all the pins conform to the 0.1" or 2.54mm spacing. Specifically, pins 8, 9 and 10 are quite close together, but they will fit if you shift to the right a bit :D.
After soldering the socket, it is a simple matter of wiring. One caviat, because the socket is surface mount it will have to be mounted on the circuit side of the board, but to secure the header properly, it must be mounted on the component side. This can lead to pin confussion, so it may be worthwhile to add a piece of tape or a label to the socket and the header to keep the pin designation correct. After that it was a piece-o-cake (Note: I am a Software Engineer and have not done any hardware for over 40 years, so when I say its FEZ, it is FEZ!)
I have attached my schematic and will attach the photo colage to the next post (is that ok)

As promised here is the circuit side of the adapter and the header on the Panda.

Oh and here is the collage I should have made in the first place. Sorry for the waste of posts.

This code uses the SD card adapter I made to present a web page from the SD card. It is not a web server by any stretch of the imagination yet, but it does allow you to put a file called page.html on the SD card and send that file as the response to a query for a page.


using System;
using System.IO;
using System.Text;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
using GHIElectronics.NETMF.Net.Sockets;
using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;



namespace FEZ_Panda_SD_Card_based_Web_server
{
    public class Program
    {
        public static void Main()
        {
            const Int32 c_port = 80;
            byte[] ip = { 192, 168, 11, 98 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 11, 100 };
            byte[] mac = { 43, 185, 44, 2, 206, 127 };
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, false);
            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 8, 8, 8, 8 });      // Google DNS
            Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);
            server.Bind(localEndPoint);

            // 1. Make sure the SD Card is accessible and
            PersistentStorage sdPS = new PersistentStorage("SD");
            // 2. Can be mounted.
            sdPS.MountFileSystem();
            // 3. Assume one storage device is available, access it through
            //    Micro Framework and display available files and folders:
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                server.Listen(1);//Int32.MaxValue);

                while (true)
                {
                    // Wait for a client to connect.
                    Socket clientSocket = server.Accept();

                    // Process the client request.  true means asynchronous.
                    new ProcessClientRequest(clientSocket, true);
                }
            }
            else
            {
                Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
            }
            // Unmount
            sdPS.UnmountFileSystem();
        }
        private static string ReadPage(string pageFile)
        {
            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            FileStream htmHandle = new FileStream(rootDirectory + @ "\Page.html", FileMode.Open, FileAccess.Read);
            byte[] page = new byte[htmHandle.Length];
            int bytesRead = htmHandle.Read(page, 0, page.Length);
            htmHandle.Close();
            return bytesToString(page);
        }


        // The following comes from http://www.fezzer.com/project/97/readwrite-from-sdusd-card/
        /// <SUMMARY>         
        /// Converts a byte array to a string         
        /// </SUMMARY>         
        /// <PARAM name="bytes"></PARAM>         
        /// <RETURNS></RETURNS>         
        public static string bytesToString(byte[] bytes)
        {
            string s = string.Empty;
            for (int i = 0; i < bytes.Length; ++i)
            {
                s += (char)bytes[i];
            }
            return s;
        }
    /// <summary>
    /// Processes a client request.
    /// </summary>
        internal sealed class ProcessClientRequest
        {
            private Socket m_clientSocket;
 
            /// <summary>
            /// The constructor calls another method to handle the request, but can 
            /// optionally do so in a new thread.
            /// </summary>
            /// <param name="clientSocket"></param>
            /// <param name="asynchronously"></param>
            public ProcessClientRequest(Socket clientSocket, Boolean asynchronously)
            {
                m_clientSocket = clientSocket;
 
                if (asynchronously)
                    // Spawn a new thread to handle the request.
                    new Thread(ProcessRequest).Start();
                else ProcessRequest();
            }
 
            /// <summary>
            /// Processes the request.
            /// </summary>
            private void ProcessRequest()
            {
                const Int32 c_microsecondsPerSecond = 1000000;
 
                // 'using' ensures that the client's socket gets closed.
                using (m_clientSocket)
                {
                    // Wait for the client request to start to arrive.
                    Byte[] buffer = new Byte[1024];
                    if (m_clientSocket.Poll(5 * c_microsecondsPerSecond,
                        SelectMode.SelectRead))
                    {
                        // If 0 bytes in buffer, then the connection has been closed, 
                        // reset, or terminated.
                        if (m_clientSocket.Available == 0)
                            return;
 
                        // Read the first chunk of the request (we don't actually do 
                        // anything with it).
                        Int32 bytesRead = m_clientSocket.Receive(buffer,
                            m_clientSocket.Available, SocketFlags.None);
 
                        // Return a static HTML document to the client.
                        String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n";
                     s += ReadPage(@ "\Page.html");
                        m_clientSocket.Send(Encoding.UTF8.GetBytes(s));
                    }
                }
            }
        }

    }
}

feel free to critique but since I just wipped this up this morning, I know it is awfully rough.

Great code example but why didn’t you start a new thread instead of replying to this one so more users can see it?

I replied because this thread because this was more in the way of a “ME TOO” and was not a big step beyond what had already been done. I am working on making the web stuff work a little better( handle types other than text). If I figure that out, then I may start a new thread.
I hope I didn’t do something wrong here?

Not wrong. Actually what you did is very cool and it is worth being in new thread so the community can see it :slight_smile: