Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

OnBoard MicroSD


  • Please log in to reply
17 replies to this topic

#1 fasbaker

fasbaker

    New Member

  • Members
  • Pip
  • 5 posts

Posted 19 May 2012 - 08:06 AM

Hello, I used .net Framework 4.2 I am new with netduinoplus and i wont read/write the microSD card for my netduinoplus. I tested some codes of internet but can't read the microSD. Can help me with a example code for connect with microSD. Best regads Christian

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 May 2012 - 02:19 PM

Hi Christian, What size is your MicroSD card? Does the "\SD" folder appear when you insert your card? BTW, welcome to the Netduino community. Chris

#3 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 19 May 2012 - 05:20 PM

Hello Christian and welcome to the forums.

I have a logging application that writes to the SD card. Here is how I do that.

First, I create the file (Sorry still has my variables in there).

using (var filestream = new FileStream(@"SD\" + folder + SD_HEADER_LOG, FileMode.Create))
{
      StreamWriter streamWriter = new StreamWriter(filestream);
      streamWriter.WriteLine(APP_NAME + (char)32 + getVersion());
      streamWriter.WriteLine("Device MAC ID: " + GetMAC());
      streamWriter.WriteLine("Log Create Time: " + DateTime.Now.ToString());
      streamWriter.WriteLine("------------------------------------------------------------");
      streamWriter.Close();
}

Then when I want to write to the file:

using (var filestream = new FileStream(@"SD\" + folderName + SD_HEADER_LOG, FileMode.Append))
{
 	StreamWriter sw = new StreamWriter(filestream);
 	sw.WriteLine("Data: " + DateTime.Now.ToString() + " - " + myData.ToString());
 	sw.Close();
}

You should be able to use the filestream to also read the files. Most important is to use the "\SD" folder.

There are also some SD cards and some sizes of Cards that do not work. I have had the most success with 2GB cards that are not SDHC.

Hope this helps.

#4 mastronic

mastronic

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationFrench - France (Lille)

Posted 19 May 2012 - 05:23 PM

Hi Christian,

What size is your MicroSD card? Does the "\SD" folder appear when you insert your card?

BTW, welcome to the Netduino community.

Chris


used 2go Micro SD (Not use SD HC

Example code:
using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.IO;


#if(NETDUINO_MINI)
using SecretLabs.NETMF.Hardware.NetduinoMini;
#else
using SecretLabs.NETMF.Hardware.NetduinoPlus;
#endif

namespace NetDuinoPlusMicroSd
{

    /* DEBUG LOG */
//    Insert card now - Inserer votre carte maintenant
//Card Inserted
//Volume found
//#fichier de configuration
//BUFFER_GPS=2048
//FORMAT_DATE=DD/MM/YYYY HH:MM:SS
//Directory count: 1
//Directory: \SD
//file count: 2
//filename: \SD\filename.txt
//filename: \SD\CONFIG.TXT


    public class Program
    {


        static void SD_Insert(object sender, MediaEventArgs args)
        {
            Debug.Print("Card Inserted");
#if(NETDUINO_MINI)
                // Mount SD (for Mini - already present on Plus)
                StorageDevice.MountSD("SD", SPI_Devices.SPI1, Pins.GPIO_PIN_17);
#endif
        }

        static void SD_Eject(object sender, MediaEventArgs args)
        {
            Debug.Print("Card Ejected");
        }

        public static void Main()
        {
            RemovableMedia.Insert += new InsertEventHandler(SD_Insert);
            RemovableMedia.Eject += new EjectEventHandler(SD_Eject);

            ////OEM = 0x22, Model = 0xB1 (Secret Labs VID) and SKU = 0x1000 for Netduino, 0x1001 for Netduino Plus and 0x1002 for Netduino Mini respectively. 
            //Debug.Print("SystemInfo.SystemID.Model :" + SystemInfo.SystemID.Model.ToString());
            //Debug.Print("SystemInfo.SystemID.OEM :" + SystemInfo.SystemID.OEM.ToString());
            //Debug.Print("SystemInfo.SystemID.SKU :" + SystemInfo.SystemID.SKU.ToString());

            Debug.Print("Insert card now - Inserer votre carte maintenant");
            Thread.Sleep(10000);

            // cette partie de code doit etre mis dans la procédure insert ...  + Timeout infinit dans le sleep
            if (VolumeInfo.GetVolumes().Length > 0)
            {
                Debug.Print("Volume found");

                VolumeInfo[] volumes = VolumeInfo.GetVolumes();
                // Netduino PLUS:    SD
                foreach (var volumeInfo in volumes)
                {

                    Debug.Print(volumeInfo.Name + " " + volumeInfo.VolumeLabel);

                }

                try
                {

                    // READ FILE
                    FileStream filestream = new FileStream(@"\SD\config.txt", FileMode.Open);
                    StreamReader reader = new StreamReader(filestream);
                    Debug.Print(reader.ReadToEnd());
                    reader.Close();
                }
                catch(Exception ex)
                {
                    Debug.Print("Exeption Read fichier : " + ex.Message);
                }


                try
                {
                    // WRITE FILE 
                   // FileStream filestream2 = new FileStream(@"\SD\test.txt", FileMode.Open);
                    FileStream filestream2 = new FileStream(@"SD\filename.txt", FileMode.Append, FileAccess.Write, FileShare.None);
                    StreamWriter streamWriter = new StreamWriter(filestream2);
                    streamWriter.WriteLine("Test 123");
                    streamWriter.Close();
                    filestream2.Close();
                }
                catch (Exception ex)
                {
                    Debug.Print("Exeption Write file : " + ex.Message);
                }

                try
                {
                    string[] directories = System.IO.Directory.GetDirectories(@"\");
                    Debug.Print("Directory count: " + directories.Length.ToString());

                    for (int i = 0; i < directories.Length; i++)
                    {
                        Debug.Print("Directory: " + directories[i]);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print("Exeption Read list Directory : " + ex.Message);
                }


                try
                {
                    string[] files = System.IO.Directory.GetFiles(@"\SD");
                    Debug.Print("file count: " + files.Length.ToString());

                    for (int i = 0; i < files.Length; i++)
                    {
                        Debug.Print("filename: " + files[i]);
                        //FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
                        //StreamReader sr = new StreamReader(fs);
                        //Debug.Print("contents: " + sr.ReadToEnd());
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print("Exeption Read list Files : " + ex.Message);
                }


                Thread.Sleep(Timeout.Infinite);
               
            }
            else
                Debug.Print("No volumes found");

 

            Debug.Print("Exiting");


            Thread.Sleep(Timeout.Infinite);
        }


    }
}


And add référence:

Microsoft.SPOT.IO
SecreLabs.NETMF.IO
System.IO


Regards
Thierry

#5 fasbaker

fasbaker

    New Member

  • Members
  • Pip
  • 5 posts

Posted 19 May 2012 - 05:47 PM

Thanks at all I don't know have i mount the microSD, I tested the examples for mount but in this example the SD is in the PIN_D10 and my microSD is in board. StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10); Im used a MicroSD 2GB. Chris when said "Does the "\SD" folder appear when you insert your card?" your refered a label for volumen of SD or a directory inside a SD. Best regards Christian

#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 19 May 2012 - 06:05 PM

If the board is Netduino plus you do not need to mount the SD card. It is auto mounted as long as you have the correct firmware for the Netduino plus on the board. Since it is auto mounted it shows up as Volume \SD. So if you create a folder called "TEST" it would be \SD\TEST. SD is the mount, TEST is the Folder. Most 2GB cards I've used have worked without an issue.

#7 GeekyGirl

GeekyGirl

    New Member

  • Members
  • Pip
  • 2 posts

Posted 20 May 2012 - 08:46 PM

Hi newb here... just a quick question re SD cards... Am I right in thinking that an 8GB card, for example, would not work at all in the NetduinoPlus? I've been trying to do something with one (an 8GB happens to be the only size I have lying around) but I can't seem to access any System.IO functionality. I get errors in Debug mode if I include any System.IO file/directory statements. I'm using v4.2 SDK and firmware. Any input gratefully received Thanks Louise

#8 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 20 May 2012 - 09:32 PM

Hi
newb here... just a quick question re SD cards... Am I right in thinking that an 8GB card, for example, would not work at all in the NetduinoPlus? I've been trying to do something with one (an 8GB happens to be the only size I have lying around) but I can't seem to access any System.IO functionality. I get errors in Debug mode if I include any System.IO file/directory statements. I'm using v4.2 SDK and firmware.
Any input gratefully received
Thanks
Louise


Most 1 or 2 GB ones work. There was a beta version that the 4 & 8 GB worked, but that code is not in 4.2 that I know of, so you are stuck with 1 & 2 GB.

#9 GeekyGirl

GeekyGirl

    New Member

  • Members
  • Pip
  • 2 posts

Posted 20 May 2012 - 09:40 PM

Most 1 or 2 GB ones work. There was a beta version that the 4 & 8 GB worked, but that code is not in 4.2 that I know of, so you are stuck with 1 & 2 GB.

Ok - thanks for the info. I'll have to buy one in!

Cheers

Louise

#10 fasbaker

fasbaker

    New Member

  • Members
  • Pip
  • 5 posts

Posted 21 May 2012 - 02:30 PM

Thanks, I working the SD right. Best Regards Christian

#11 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 06 August 2012 - 07:19 AM

Most 1 or 2 GB ones work. There was a beta version that the 4 & 8 GB worked, but that code is not in 4.2 that I know of, so you are stuck with 1 & 2 GB.

For me, the SD card also is not working because I bought a 8 gieg. (bigger counts :-))
I think the store (mediamarkt) will not exchange the card for a smaller one.

Is there any chance that the SD Card 4&8 Gb support will be implemented in the version 4.2
Because I program in VB, I am stuck on version 4.2
BTW, VB and 4.2 works very well.
Ellen

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 August 2012 - 07:27 AM

Hi Ellen, Once NETMF 4.2 QFE2 ships, we should be able to pull in the 4.1 SD code enhancements. Chris

#13 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 12 August 2012 - 08:01 AM

I can't find SecreLabs.NETMF.IO anywhere except mentioned in this thread. But then I'm only using 4.1. Will this only work with 4.2. I'm just starting out here and I'm looking for something like this to pour over and figure out modify as I need to. Thanks.

#14 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 August 2012 - 04:54 PM

Hi Grant,

I can't find SecreLabs.NETMF.IO anywhere except mentioned in this thread. But then I'm only using 4.1. Will this only work with 4.2. I'm just starting out here and I'm looking for something like this to pour over and figure out modify as I need to.

I would recommend using NETMF 4.2. The SecretLabs.NETMF.IO assembly is included in the Netduino 4.2 SDK (on the download page).

That said, I _believe_ that the Netduino 4.1.1 beta firmware supported SecretLabs.NETMF.IO.dll as well.

Chris

#15 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 14 August 2012 - 12:35 AM

Thanks Mate. Just out of curiosity, How stable is the current 4.2 release. I run beta software all the time and get a kick out of doing so. Some times it's more stable than the stable release. I'm even posting this from a Windows 8 tablet. But I'm new to this and I'm so nervous about hurting what my wife has described as my mistress. Grant.

#16 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 14 August 2012 - 12:53 AM

Hi Grant,

Thanks Mate. Just out of curiosity, How stable is the current 4.2 release. I run beta software all the time and get a kick out of doing so. Some times it's more stable than the stable release. I'm even posting this from a Windows 8 tablet. But I'm new to this and I'm so nervous about hurting what my wife has described as my mistress.


.NET Micro Framework should be hitting the 4.2 QFE2 RTM release any day now. Once it does, it'll become our stable 4.2 firmware release.

It's possible that we'll find some glitches here or there after it ships, and we can address those if they crop up, but there are several bugfixes in 4.2 QFE2 (GC bugfixes, WinUSB drivers to avoid BSOD) that should make it a worthwhile upgrade.

Chris

#17 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 14 August 2012 - 01:38 AM

Terrific. Thanks Again.

#18 michel capua

michel capua

    Member

  • Members
  • PipPip
  • 26 posts

Posted 28 May 2013 - 09:00 AM

Hello,

 

I have the same problem of fasbaker.

I have NP2, I have installed Netduino 4.2 SDK and I use VS2010, the target framework of my Application is .NET Micro Framework 4.2

The size of my MicroSD card is 1Gb.

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;font-size:14px;]Using the Example code of mastronic, I don't found in my project with VS2010: [/color]

 

using Microsoft.SPOT.IO;

using SecretLabs.NETMF.IO;

using SecretLabs.NETMF.Hardware.NetduinoPlus;

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Using the [/color]example of VanderWekke, [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I don't found in my project with VS2010: [/color]

 

the object StreamWriter

 

What is my problem?

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.