Netduino +以太网盾:如何写入SD卡?
我尝试了几个示例程序将数据写入安装在以太网盾上的SD卡,但是没有一个起作用。 SD 卡大小为 4 GB,格式为 FAT32。
以太网扩展板如下:(
在亚马逊购买 - Arduino 以太网扩展板)
这是创建 Netduino 应用程序时不起作用的示例代码(不是Netduino Plus应用程序)(第一行抛出异常):
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("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());
}
}
有示例工作程序吗?
解决方案:
感谢 Chris 和 James,我成功地写入 SD 卡并从中读取。将所有内容放在一起后,我写了一篇文章,以防其他人遇到同样的问题。
I have tried several example programs to write data to the SD card mounted on the Ethernet shield, but none worked. The SD card size is 4 GB and formatted as FAT32.
The Ethernet shield is the following:
(Bought on Amazon - Arduino Ethernet Shield)
And this is example code that doesn't work when creating a Netduino application (not Netduino Plus application) (thefirst line throws an exception):
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("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());
}
}
Is there a example working program?
Solution:
Thanks to Chris and James, I managed to write to the SD card and read from it. After putting everything together, I wrote an article, in case anyone else faces the same issues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Arduino 以太网扩展板的最新版本使用“ICSP”接头(板右侧的 3x2、6 针接头)进行通信。进入 SD 卡的输入/输出数据将通过这些引脚。
为了兼容性,我们在 Netduino 上包含了这些相同的标头;要使用此屏蔽,您需要将适当的接头焊接到您的 Netduino 上。那么你就可以出发了!
顺便说一句,Netduino Plus 集成了 MicroSD 和快速以太网……这也可能是一个简单的解决方案。 http://www.netduino.com/netduinoplus/
Chris(Secret Labs LLC)
The latest revision of the Arduino Ethernet Shield uses the "ICSP" header (3x2, 6-pin header on right side of board) to communicate. The input/output data going to your SD card is going over those pins.
We've included these same headers on the Netduino for compatibility; to use this shield, you'll want to solder the appropriate header onto your Netduino. Then you should be good to go!
BTW, Netduino Plus has integrated MicroSD and fast Ethernet networking...which may be an easy solution as well. http://www.netduino.com/netduinoplus/
Chris (Secret Labs LLC)
我在此论坛页面上找到了参考 http://forums.netduino.com
这让我认为您需要为 SD 卡使用 D4 而不是 D10。我在同一页面上发现了一些其他参考资料,其中提到 D10 是以太网的 SS 引脚。固件可在他们的下载中找到页面目前只有 4.1.0,所以您可能需要跳线,我无法测试它,但论坛链接应该是一个很好的起点。
I found a reference on this forum page http://forums.netduino.com
Which makes me think that you need to use D4 instead of D10 for the SD Card. I found some other references on the same page that mentioned D10 is the SS pin for the Ethernet. The Firmware available on their download page is currently only 4.1.0 so you will probably need the jumper. I can't test this but the forum link should be a good starting point.