{"id":98,"date":"2017-04-09T00:16:05","date_gmt":"2017-04-08T22:16:05","guid":{"rendered":"https:\/\/arduinoforlammers.wordpress.com\/?p=98"},"modified":"2022-03-13T12:47:06","modified_gmt":"2022-03-13T11:47:06","slug":"arduino-uno-mh-sd-card-module","status":"publish","type":"post","link":"https:\/\/arduino.net.pl\/index.php\/arduino-uno-mh-sd-card-module\/","title":{"rendered":"Arduino Uno + MH-SD Card Module"},"content":{"rendered":"\n<p>Dzi\u015b \u0142\u0105czymy&nbsp;modu\u0142 karty SD z Arduino. Inicjujemy, zapisujemy i odczytujemy plik tekstowy na pustej karcie SD. Moja karta ma 1 GB pami\u0119ci i zosta\u0142a sformatowana do&nbsp;FAT32.<br><em><br><strong>Uwaga!<\/strong> W <a href=\"https:\/\/botland.com.pl\/akcesoria-do-kart-pamieci\/1507-modul-czytnika-kart-sd.html\">sklepie Bootland<\/a> zauwa\u017cy\u0142em ostrze\u017cenia, \u017ce \u0142\u0105cz\u0105c modu\u0142 z&nbsp;Arduino (Uno) trzeba zastosowa\u0107 konwerter napi\u0119\u0107. Podobno mo\u017cna spali\u0107 kart\u0119. Zaryzykowa\u0142em, nic si\u0119 nie spali\u0142o (jak dot\u0105d). Mo\u017ce jest podobnie jak z wy\u015bwietlaczem Nokii, kto nie wie temu dzia\u0142a na 5V.;)<\/em><\/p>\n\n\n\n<!--more-->\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-118\" src=\"https:\/\/arduinoforlammers.files.wordpress.com\/2017\/04\/mh-sd-card-module_yar2-e1491755640201.jpg?w=1024\" alt=\"MH-SD Card Module_yar2\" width=\"1024\" height=\"576\">Czytnik kupi\u0142em w&nbsp;sklepie&nbsp;<a href=\"https:\/\/hipros.pl\/akcesoria-czytnik-kart-pamieci-sd-arm-avr-pic,c100,p11,pl.html\">Hipros<\/a>.<\/p>\n\n\n\n<p>Polecam znakomity&nbsp;<a href=\"http:\/\/henrysbench.capnfatz.com\/henrys-bench\/arduino-output-devices\/arduino-lc-studio-sd-card-tutorial\/\">tutorial<\/a> ze strony &#8222;Henry\u2019s Bench&#8221;. Kody poni\u017cej pochodz\u0105 w\u0142a\u015bnie stamt\u0105d.<\/p>\n\n\n\n<p><strong>Schemat po\u0142\u0105cze\u0144 modu\u0142u z Arduino Uno:<\/strong><br>GND-GND<br>MISO-D12<br>SCK-D13<br>MOSI-D11<br>CS-D10<br>5V-5V<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright\"><img decoding=\"async\" src=\"https:\/\/arduinoforlammers.files.wordpress.com\/2017\/04\/aru_mh-sdcardmodule_con2_zm.jpg\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Kod1:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/\/Henry's Bench\n\/\/ LC Studio SD Card Initializing Tutorial\n\/\/Connections:  MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 10\n\n#include &lt;SD.h&gt;\n#include &lt;SPI.h&gt;\n\nint cs = 10; \/\/ Set Chip Select to pin ten\n\nvoid setup()\n{\n  \/\/ Open serial communications and wait for port to open:\n  Serial.begin(9600);\n  while (!Serial) {\n\n  }\n  Serial.println(\"Initializing SD card...\");\n  Serial.println();\n\n  pinMode(cs, OUTPUT);\n\n  \/\/ Documentation says you're supposed to do this\n  \/\/ even if you don't use it:\n  pinMode(SS, OUTPUT);\n\n  \/\/ see if the card is present and can be initialized:\n  if (!SD.begin(cs)) {\n    Serial.println(\"SD did not initiliaze\");\n    while (1) ;\n  }\n  Serial.println(\"SD initialized.\");\n}\n\nvoid loop()\n{\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Kod2:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Henry's Bench\n\/\/ LC Studio SD Card Create and Write to File Tutorial\n\/\/Connections:  MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 10\n\n#include &lt;SD.h&gt;\n#include &lt;SPI.h&gt;\n\nint cs = 10; \/\/ Set Chip Select to pin ten\n\nFile myFile;  \/\/ a File Object\n\nvoid setup()\n{\n\/\/\nchar myFileName&#91;] = \"MyFile.txt\";  \/\/ The name of the file we will create\n\n\/\/ Open serial communications and wait for port to open:\nSerial.begin(9600);\nwhile (!Serial) {\n\n}\nSerial.println(\"Initializing SD card...\");\nSerial.println();\n\npinMode(cs, OUTPUT);\n\n\/\/ Documentation says you're supposed to do this\n\/\/ even if you don't use it:\npinMode(SS, OUTPUT);\n\n\/\/ see if the card is present and can be initialized:\nif (!SD.begin(cs)) {\nSerial.println(\"SD did not initiliaze\");\nwhile (1) ;\n}\nSerial.println(\"SD initialized.\");\n\n\/\/ Lets check to make sure that the SD card doesn't already have our file\nif (! SD.exists(myFileName)){\n\/\/ This next statement will open a file for writing if it exists\n\/\/ If it does not exist, it will create that file. That's what we're doing here.\nmyFile = SD.open(myFileName, FILE_WRITE);\n\/\/ This next statement checks to see if the file\nmyFile.println(\"My 1st Line of Data\");  \/\/ Send Your First Line to that file\nmyFile.flush();  \/\/ Save it.\n}\nelse{\n\/\/ We got here because the file already exists.\n\/\/ Therefore we're simple opening the file and writing to it. We will add another line at the end.\nmyFile = SD.open(myFileName, FILE_WRITE);\nmyFile.println(\"Another Line of Data\");  \/\/ Send Your First Line to that file\nmyFile.flush();\n\n}\n\nSerial.println(\"Done Writing\");\n\n}\nvoid loop()\n{\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Kod3:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Henry's Bench\n\/\/ LC Studio SD Card Read From File Tutorial\n\/\/Connections:  MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 10\n\n#include &lt;SD.h&gt;\n#include &lt;SPI.h&gt;\n\nint cs = 10; \/\/ Set Chip Select to pin ten\n\nFile myFile;  \/\/ a File Object\n\nvoid setup()\n{\n\/\/\nchar myFileName&#91;] = \"MyFile.txt\";  \/\/ The name of the file we will create\nString LineString = \"\";\n\/\/ Open serial communications and wait for port to open:\nSerial.begin(9600);\nwhile (!Serial) {\n\n}\nSerial.println(\"Initializing SD card...\");\nSerial.println();\n\npinMode(cs, OUTPUT);\n\n\/\/ Documentation says you're supposed to do this\n\/\/ even if you don't use it:\npinMode(SS, OUTPUT);\n\n\/\/ see if the card is present and can be initialized:\nif (!SD.begin(cs)) {\nSerial.println(\"SD did not initiliaze\");\nwhile (1) ;\n}\nSerial.println(\"SD initialized.\");\nSerial.println();\nSerial.println(\"Reading MyFile.txt...\");\nSerial.println();\n\n\/\/ Open our File for Reading\nmyFile = SD.open(myFileName, FILE_READ);\n\n\/\/ Keep Reading String until there are no more\nwhile (myFile.available() != 0) {\n\/\/ read the string until we have a newline\n\/\/ Careful on using this where you don't have newlines.\n\nLineString = myFile.readStringUntil('\\n');\nSerial.println(LineString);\n}\nmyFile.close();\n\nSerial.println();\nSerial.println(\"Done\");\n}\n\nvoid loop()\n{\n\n}<\/code><\/pre>\n\n\n\n\n\n<h3 class=\"wp-block-heading\">LINKI<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Guide to SD Card Module with Arduino<ul><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-to-sd-card-module-with-arduino\/#:~:text=The%20SD%20card%20module%20is,using%20the%20SPI%20communication%20protocol.\">https:\/\/randomnerdtutorials.com\/guide-to-sd-card-module-with-arduino\/#:~:text=The%20SD%20card%20module%20is,using%20the%20SPI%20communication%20protocol.<\/a><\/li><\/ul><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Dzi\u015b \u0142\u0105czymy&nbsp;modu\u0142 karty SD z Arduino. Inicjujemy, zapisujemy i odczytujemy plik tekstowy na pustej karcie SD. Moja karta ma 1 GB pami\u0119ci i zosta\u0142a sformatowana do&nbsp;FAT32.Uwaga! W sklepie Bootland zauwa\u017cy\u0142em&#8230;<\/p>\n","protected":false},"author":3,"featured_media":118,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[21,28],"class_list":["post-98","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","tag-mh-sd","tag-sd"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":4,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":4944,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions\/4944"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}