SD card example for the HYDRA?

Does anyone want to share an SD card example write for the FEZ Hydra? I have been trying all day to do this and it is throwing me exceptions.

I was also wondering what is the point of the hardware drawing block in visual studio if it does not add the code for you? If I drag the SD card should it add the basic code for the device to my program? I am just wondering because otherwise I don’t understand the point.

Usually designer creates the module’s Driver instance it is inside generated part of the partial class. After that you just start using the instance by the name you gave it in the designer.

What kind of exception are you getting? Show your code please.

I am just trying to mount the file system and unmount…I used the following…

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using GHIElectronics.OSH.NETMF.Hardware;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerApp1
    public partial class Program
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
            sdCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
            sdCard.SDCardUnmounted += new SDCard.SDCardUnmountedEventHandler(sdCard_SDCardUnmounted);
            Debug.Print("Program Started");

        void sdCard_SDCardUnmounted(SDCard sender)
            Debug.Print("unmounted sd Card");

        private void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
            Debug.Print("sd Card is Mounted");

I get the following error

[quote]Error 1 The type or namespace name ‘SDCard’ could not be found (are you missing a using directive or an assembly reference?) C:\Users\robm\AppData\Local\Temporary Projects\GadgeteerApp1\Program.cs 28 37 GadgeteerApp1

Add this at the end of your using statements:

using Gadgeteer.Modules.GHIElectronics;

I am surprised that line is missing in your case. It was added for me when I have added sd card in visual designer. Are you on the latest version of the SDK?

Perfect architect!

Now if I want to write to the file what do I need to add. Say for instance I want to save the string “hello world”.

Architect…It was not added. I installed the SDK about2 months ago so I may not have the latest SDK. I am not sure…

Thanks for your help!

@ rgm - review the documentation on writing to a text file here

Please use the available help resources before asking questions like this, There is a LOT of information on this site and other NETMF related sites. If you hit a snag working through those examples or need clarification on a specific piece of code, we’re glad to help.

@ ransomhall

I have already looked through that and I did not find an example of the SD write for the Hydra or Gadgeteer. I had no trouble on the Panda II but this gadgeteer seems to have subtle differences in the SD card usage.

For example on the Panda I instantiate my object in the main() as follows:

PersistentStorage sdPS = new PersistentStorage("SD");

If I try to do the same with the hydra I get an error that I may be misisng a library reference. I would rather not ask but if I cannot find the correct syntax I need to ask :smiley:

@ rgm When you add a class and get missing reference exception you have to make sure the assembly is added to your references and you added appropriate namespace using statement.

The name of the assembly is in the class documentation.

Check this post:

Thanks Architect. It was nice of you to help!

This Hydra has been really frustrating for me to be honest. I had a much easier go with the Panda II but it seems like I cannot get anything to work with this. I have tried to connect analog sensors and they will not read…the ports 13 and 14 on two Hydra boards are not outputting 3.3 V but 1.65 instead…all the while every other board (Arduino, Netduino, Panda, Duinoite etc…) I have is reading correct from the multimeter…there are no real SD write examples to speak of…I have scoured the internet…admittedly I am not a programmer (although I am an engineer)…I cannot find an analog read example either for non gadgeteer sensors? How do you initialize them? How are the pins initialized etc… I just cannot get it to do anything I want it to.

I appreciate your help though :slight_smile:

Let me check my Hydra later today. All VCC pins on all sockets should be 3V3.

here is an example on how to write a line of text to the sdcard using Hydra:
Make sure you are add the following references by right clicking on References and choose add:


using System.IO;
using Gadgeteer;
using Microsoft.SPOT;
using Gadgeteer.Modules.GHIElectronics;

namespace HAMS.Hardware.gadgeteer.GHI_FezHydra.HD
    public partial class Program
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
  sdCard.SDCardMounted += sdCard_SDCardMounted;
            sdCard.SDCardUnmounted += sdCard_SDCardUnmounted;

        private void sdCard_SDCardUnmounted(SDCard sender)
          Debug.Print("card unmouted");

        private void sdCard_SDCardMounted(SDCard sender, StorageDevice sdcard)
           Debug.Print("Card Mounted");

           using (Stream configStream = sdCard.GetStorageDevice().OpenWrite(@ "\test.txt"))
               using (StreamWriter writer = new StreamWriter(configStream))
                   writer.WriteLine("this is a test");
                   Debug.Print("done Writing");

@ Architect

I just plugged a cable to the pin 14 and on the output side I plugged in a cable in what should be pin 10 as follows (pin 10 -> O)

x x x x O
x x x x x

I get a reading of 5 V from what should be the ground! If you follow the socket guide from microsoft and what I assumed to be the normal convention the slot down is applicable on both ends of the cable. I guess it is backwards or something…!!

Can you show a photo of your setup?

Left to right…ground and the anaolog in 1 on port 13. It reads the one on the left as ground. Notch is down. oooops wrong photo!

Lets try this again…

This is it…

You have connected it wrong. This is the main board side of the cable.

I know exactly what you mean now Architect!


I did not even realize that it made a difference!

I am putting everyhting in a box so I wanted them in not outwards…

In any event the AIN1, 3 and 4 are on socket 13.

Remember that pin numbering in the spec applies to the boxed header socket on main board/module. You are measuring in mating cable connector. You have to mirror the pin numbers.

Actually i just flipped them and that map is still the same. It does not make a difference if they are one way or the other.

Or as you said they are mirrored…which I did not know! Knowledge is the key :smiley:

So pin numbering is sorted out now, right?