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

Adafruit data logger SD card communication

sd card spi adafruit shield exception

  • Please log in to reply
8 replies to this topic

#1 HaxyMaxy

HaxyMaxy

    New Member

  • Members
  • Pip
  • 7 posts

Posted 22 January 2014 - 02:18 AM

I am unable to communicate with an SD card attached to a netduino 1 (formatted 4.2.0.1) via adafruit pre assembled SD card

logger shield.

 

using System;using System.IO;using Microsoft.SPOT.IO;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.IO;using SecretLabs.NETMF.Hardware.Netduino;namespace _2010testapp{    public class Program    {	    public static void Main()	    {		    StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10);		    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]);		    }		   			 string[] files = System.IO.Directory.GetFiles("SD1");		    Debug.Print("file count: " + files.Length.ToString());		    for (int i = 0; i < files.Length; i++)		    {			    Debug.Print("file: " + files[i]);		    }		    while (true)		    {		    }	    }    }}

 

 

when it gets to the line "string[] files = System.IO.Directory.GetFiles("SD1");"

 

I get an exception "An unhandled exception of type 'System.IO.IOException' occurred in System.IO.dll"

 

I have tried with a 4 gb micro sd card in an adapter and a 16gb sd card.

both have been tried in every format availible in the built in windows sd card formatter.

 

Thank you in advance for any insight to my problem,

Maxwell

 



#2 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 22 January 2014 - 06:18 PM

Hello Maxwell,

 

I think your first problem might be that the Netduino only officially supports SD cards up to 2GB. Have a look at this post: http://forums.netdui...ard/#entry47779

 

 Also, you may want to try changing this line

string[] files = System.IO.Directory.GetFiles(@"SD1");

to this:

string[] files = System.IO.Directory.GetFiles(@"SD1\");

I hope that helps!



#3 HaxyMaxy

HaxyMaxy

    New Member

  • Members
  • Pip
  • 7 posts

Posted 24 January 2014 - 01:15 AM

I tried changing the line and it still threw the exception. I will try to see if i can get my hands on a non sdhc sd card.



#4 wendo

wendo

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 24 January 2014 - 01:28 AM

You typically need to double the backslashes so they don't act as escape chars.

 

This is working code from an N+2

 

 FileStream filestream = new FileStream(@"SDsettingsWhitelist.txt", FileMode.Open); 


#5 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 24 January 2014 - 02:25 AM

 

You typically need to double the backslashes so they don't act as escape chars.

 

This is true, however, the use of the "@" symbol before a string indicates it's a verbatim string literal, which precludes the need to escape things:

 

http://msdn.microsof...0(v=vs.71).aspx



#6 HaxyMaxy

HaxyMaxy

    New Member

  • Members
  • Pip
  • 7 posts

Posted 24 January 2014 - 06:29 AM

2gb card in the mail, will report back with results.



#7 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 25 January 2014 - 07:17 PM

Good luck!



#8 HaxyMaxy

HaxyMaxy

    New Member

  • Members
  • Pip
  • 7 posts

Posted 27 February 2014 - 11:17 AM

The code works fine with a 1gb sd card. Thanks for the help. Hopefully support is added for sdhc in the near future.



#9 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 28 February 2014 - 08:42 PM

Excellent!







Also tagged with one or more of these keywords: sd, card, spi, adafruit, shield, exception

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.