
{"id":6064,"date":"2017-07-21T14:51:17","date_gmt":"2017-07-21T05:51:17","guid":{"rendered":"https:\/\/okiraku-camera.tokyo\/blog\/?p=6064"},"modified":"2017-07-26T11:15:18","modified_gmt":"2017-07-26T02:15:18","slug":"esp32%e9%96%8b%e7%99%ba%e3%83%9c%e3%83%bc%e3%83%89%e3%81%abmicrosd%e3%82%ab%e3%83%bc%e3%83%89%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b","status":"publish","type":"post","link":"https:\/\/okiraku-camera.tokyo\/blog\/?p=6064","title":{"rendered":"ESP32\u958b\u767a\u30dc\u30fc\u30c9\u306bMicroSD\u30ab\u30fc\u30c9\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u3064\u3051\u308b"},"content":{"rendered":"<p>\u79cb\u6708\u96fb\u5b50\u3067\u8cb7\u3063\u305fESP-WROOM-32\u306e\u958b\u767a\u30dc\u30fc\u30c9(DevKit-C)\u306b\u3001amazon\u3067\u898b\u3064\u3051\u305f\u5b89\u3044MicroSD\u30ab\u30fc\u30c9\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u3064\u3051\u3066\u307f\u305f\u3002WROOM-32\u5185\u306eSPI\u30d5\u30e9\u30c3\u30b7\u30e5\u3092\u4f7f\u3063\u305fspiffs\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3084\u30c4\u30fc\u30eb\u304c\u63c3\u3063\u3066\u3044\u306a\u3044\u304b\u3089\u3001\u624b\u3063\u53d6\u308a\u65e9\u304fESP32\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u3092\u4f7f\u3046\u305f\u3081\u306b\u4f7f\u3063\u3066\u307f\u305f\u3002<\/p>\n<h2>CATALEX MicroSD Card Module<\/h2>\n<figure id=\"attachment_6057\" aria-describedby=\"caption-attachment-6057\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/4f5d078b834a325b14145d0840ab4e1f.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-6057\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/4f5d078b834a325b14145d0840ab4e1f-552x414.jpg\" alt=\"\" width=\"552\" height=\"414\" \/><\/a><figcaption id=\"caption-attachment-6057\" class=\"wp-caption-text\">Catalex MicroSD card module<\/figcaption><\/figure>\n<p>amazon\u3067\u4e2d\u56fd\u304b\u3089\u306e\u9001\u6599\u8fbc\u307f\u3067105\u5186\u3067\u58f2\u3063\u3066\u3044\u308b\u3002\u56de\u8def\u56f3\u304c\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u7b49\u4fa1\u56de\u8def\u3092\u8d77\u3053\u3057\u3066\u307f\u305f\u304c\u3001\u8aa4\u308a\u3082\u3042\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n<p><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/CATALEX-MicroSD-EQUIV.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-6065\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/CATALEX-MicroSD-EQUIV-552x345.png\" alt=\"\" width=\"552\" height=\"345\" \/><\/a><\/p>\n<p>Arduino\u7528\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u96fb\u6e90\u3084\u30ed\u30b8\u30c3\u30af\u306f5V\u30ec\u30d9\u30eb\u304c\u60f3\u5b9a\u3055\u308c\u3066\u304a\u308a\u3001\u30dc\u30fc\u30c9\u4e0a\u306b+3.3V\u51fa\u529b\u306e\u4e09\u7aef\u5b50\u30ec\u30ae\u30e5\u30ec\u30fc\u30bf(AMS1117-3.3) \u3068\u30ec\u30d9\u30eb\u5909\u63db\u306b\u3082\u4f7f\u3048\u308b\u30b2\u30fc\u30c8\u4ed8\u30d0\u30c3\u30d5\u30a1IC\u306e74LVC125\u304c\u8f09\u3063\u3066\u3044\u308b\u3002\u305d\u3057\u3066\u3001J2\u7aef\u5b50\u306b\u6765\u3066\u3044\u308bSPI\u63a5\u7d9a\u7528\u306e4\u672c(CS, CSK, MOSI, MISO) \u304c\u30d0\u30c3\u30d5\u30a1\u3092\u4ecb\u3057\u3066MicroSD\u7528\u306e\u30b9\u30ed\u30c3\u30c8\u306b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u308b\u3002\u5404\u4fe1\u53f7\u7dda\u306b\u306f\u76f4\u5217\u306b3.3K\u03a9\u306e\u62b5\u6297\u304c\u5165\u3063\u3066\u3044\u308b\u304c\u3001\u3053\u308c\u306f\u77ed\u7d61\u6642\u306e\u96fb\u6d41\u3092\u5236\u9650\u3059\u308b\u305f\u3081\u3060\u308d\u3046\u3002<br \/>\n74125\u306e4\u3064\u306e\u30d0\u30c3\u30d5\u30a1\u306f\u72ec\u7acb\u3057\u3066\u30a4\u30cd\u30fc\u30d6\u30eb\u53ef\u80fd\u3060\u304c\u3001\u30a4\u30cd\u30fc\u30d6\u30eb\u4fe1\u53f7\u306eOE\u306f\u3059\u3079\u3066GND\u306b\u76f4\u7d50\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3060\u3063\u305f\u3002\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u30b9\u30ec\u30fc\u30d6\u51fa\u529b\u30de\u30b9\u30bf\u30fc\u5165\u529b\u7528\u306eMISO(Master In Slave Out) \u4fe1\u53f7\u304c\u30cf\u30a4\u30a4\u30f3\u30d4\u30fc\u30c0\u30f3\u30b9\u306b\u306a\u308b\u3053\u3068\u306f\u306a\u3044\u304b\u3089\u3001\u30de\u30b9\u30bf\u30fc(ESP32\u5074)\u30681:1\u3067\u63a5\u7d9a\u3059\u308b\u3053\u3068\u306b\u306a\u308b\u3002<\/p>\n<p>ESP32\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u4f7f\u3046\u5834\u5408\u3001\u3053\u306e\u30dc\u30fc\u30c9\u306eJ2\u7aef\u5b50\u306eVCC\u306b+3.3V\u3092\u4e0e\u3048\u3066\u3057\u307e\u3046\u3068\u3001\u30ec\u30ae\u30e5\u30ec\u30fc\u30bf\u306e\u30c9\u30ed\u30c3\u30d7\u30a2\u30a6\u30c8\u306b\u3088\u3063\u3066\u30dc\u30fc\u30c9\u5185\u306eVDD\u306e\u96fb\u5727\u306f2.4\uff5e2.5V\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u3001MicroSD\u30ab\u30fc\u30c9\u306e\u898f\u5b9a\u96fb\u6e90\u96fb\u5727(+2.7\uff5e3.6V)\u306b\u9054\u3057\u306a\u3044\u3002AMS1117\u3092\u5916\u3057\u3066+3.3V\u3092\u4e0e\u3048\u308b\u3053\u3068\u3082\u8003\u3048\u305f\u304c\u3001\u5c0f\u3055\u304f\u3066\u9762\u5012\u306a\u306e\u3067\u958b\u767a\u30dc\u30fc\u30c9\u306e\u96fb\u6e90\u306b\u3082\u306a\u3063\u3066\u3044\u308bUSB\u306eVbus\u304b\u3089+5V\u3092\u4e0e\u3048\u308b\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n<h2>ESP32\u958b\u767a\u30dc\u30fc\u30c9\u3068\u306e\u63a5\u7d9a<\/h2>\n<p>\u30c7\u30fc\u30bf\u30b7\u30fc\u30c8\u306b\u3088\u308c\u3070\u3001ESP32\u3067\u306f\u7279\u5225\u306a\u7528\u9014\u306b\u4f7f\u308f\u308c\u3066\u3044\u308b\u30d4\u30f3\u3092\u9664\u3044\u305f\u3059\u3079\u3066\u306eGPIO\u306bSPI\u6a5f\u80fd\u3092\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u305f\u3060\u3057\u3001\u5165\u529b\u5c02\u7528\u306e\u30d4\u30f3(IO34\uff5eIO39)\u306b\u30de\u30b9\u30bf\u5074\u304c\u51fa\u529b\u3059\u308b\u4fe1\u53f7(SS, CLK, MOSI)\u3092\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002\u4eca\u56de\u306f\u30d6\u30ec\u30c3\u30c9\u30fc\u30dc\u30fc\u30c9\u4e0a\u306e\u914d\u7dda\u306e\u90fd\u5408\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7d50\u7dda\u3068\u3057\u305f\u3002<\/p>\n<figure id=\"attachment_6066\" aria-describedby=\"caption-attachment-6066\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/ESP32-MicroSD1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-6066\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/ESP32-MicroSD1-552x345.png\" alt=\"\" width=\"552\" height=\"345\" \/><\/a><figcaption id=\"caption-attachment-6066\" class=\"wp-caption-text\">ESP32-MicroSD_TEST1<\/figcaption><\/figure>\n<p>\u958b\u767a\u30dc\u30fc\u30c9\u306e\u30d4\u30f3\u756a\u53f7\u306f\u3001WiFi\u30a2\u30f3\u30c6\u30ca\u3092\u4e0a\u306b\u3057\u3066\u90e8\u54c1\u9762\u3092\u898b\u305f\u3068\u304d\u3001\u5de6\u5074\u304c1\uff5e19\u3001\u53f3\u5074\u304c(\u4e0a\u304b\u3089) 38\uff5e20\u3068\u3044\u3046\u3075\u3046\u306b\u3057\u3066\u3044\u308b\u3002\u3061\u3087\u3046\u3069\u3001IO16\uff5eIO19\u304cIO5\u3092\u306f\u3055\u3093\u3067\u4e26\u3093\u3067\u3044\u308b\u306e\u3067\u3001\u305d\u3053\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u305f\u3002MicroSD\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306b\u7acb\u6d3e\u306a\u30d0\u30b9\u30d0\u30c3\u30d5\u30a1\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u3001SPI\u63a5\u7d9a\u306e\u5404\u7dda\u306f\u30d7\u30eb\u30a2\u30c3\u30d7\u3057\u3066\u3044\u306a\u3044\u3002<\/p>\n<p>\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9\u306b\u8f09\u305b\u3066\u7d50\u7dda\u3057\u305f\u3089\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u305f\u3002<\/p>\n<figure id=\"attachment_6068\" aria-describedby=\"caption-attachment-6068\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/f12361159dda91478bec6366e0930d76.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6068 size-large\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/f12361159dda91478bec6366e0930d76-552x414.jpg\" alt=\"\" width=\"552\" height=\"414\" \/><\/a><figcaption id=\"caption-attachment-6068\" class=\"wp-caption-text\">MicroSD \u306e\u8868\u5074<\/figcaption><\/figure>\n<figure id=\"attachment_6067\" aria-describedby=\"caption-attachment-6067\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/f8fca9a2fac6c9443c94983fcd216278.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6067 size-large\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/f8fca9a2fac6c9443c94983fcd216278-552x414.jpg\" alt=\"\" width=\"552\" height=\"414\" \/><\/a><figcaption id=\"caption-attachment-6067\" class=\"wp-caption-text\">\u88cf\u5074<\/figcaption><\/figure>\n<p>\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9\u3068\u3057\u3066\u306f\u3001\u96fb\u6e90\u7528\u306e\u30ec\u30fc\u30eb\u304c\u7247\u5074\u306b\u3057\u304b\u306a\u3044\u3076\u3093\u7d50\u7dda\u3059\u308b\u4f59\u5730\u304c\u5e83\u3044\u30b5\u30f3\u30cf\u30e4\u30c8\u306e\u88fd\u54c1(SAD-101 \u30cb\u30e5\u30fc\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9)\u3092\u4f7f\u3063\u3066\u3044\u308b\u3002<\/p>\n<h2>\u30b9\u30b1\u30c3\u30c1<\/h2>\n<h3>SD_Text.ino\u306e\u5909\u66f4<\/h3>\n<p>\u73fe\u5728(July. 2017) \u306eArduino core for the ESP32 \u306b\u5165\u3063\u3066\u3044\u308bSPI\u304a\u3088\u3073SD\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u305f\u3002\u6700\u521d\u306fSD\/examples\u306eSD_Test.ino \u3092\u4f7f\u3063\u3066\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u305f\u304c\u3001SPI\u63a5\u7d9a\u306b\u4f7f\u3046\u30d4\u30f3\u3092\u5909\u66f4\u3057\u3066\u3044\u308b\u306e\u3067\u3001void setup() \u306e\u6700\u521d\u306e\u65b9\u3092\u3059\u3053\u3057\u5909\u66f4\u3057\u3066\u4f7f\u3063\u305f\u3002<\/p>\n<pre class=\"lang:c++ decode:true\">void setup(){\r\n    Serial.begin(115200);\r\n    if(!SD.begin()){\r\n        Serial.println(\"Card Mount Failed\");\r\n        return;\r\n    }\r\n    uint8_t cardType = SD.cardType();\r\n    ....<\/pre>\n<p>\u30aa\u30ea\u30b8\u30ca\u30eb\u3067\u306f\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306bSPI\u306b\u3064\u3044\u3066\u306f\u7279\u306b\u4f55\u3082\u8003\u616e\u305b\u305a\u306b\u958b\u59cb\u3057\u3066\u3044\u308b\u3002\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u304c\u60f3\u5b9a\u3057\u3066\u3044\u308bSPI\u63a5\u7d9a\u306e\u30d4\u30f3\u914d\u7f6e\u306fArduino \u306e\u305d\u308c\u3092\u524d\u63d0\u306b\u3057\u3066\u304a\u308aSD_Test.ino\u306e\u6700\u521d\u306b\u30b3\u30e1\u30f3\u30c8\u3068\u3057\u3066\u66f8\u304b\u308c\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"lang:c++ decode:true\">enum { sd_sck = 18, sd_miso = 19, sd_mosi = 17, sd_ss = 5 };\r\nvoid setup()\r\n{\r\n  SPI.end();\r\n  SPI.begin(sd_sck, sd_miso, sd_mosi, sd_ss); \r\n  pinMode(16, OUTPUT);\r\n  digitalWrite(16, 1);\r\n  Serial.begin(115200);\r\n  if(!SD.begin(sd_ss, SPI)){\r\n      Serial.println(\"Card Mount Failed\");\r\n      return;\r\n  }\r\n  uint8_t cardType = SD.cardType();\r\n  ....\r\n<\/pre>\n<p>\u4eca\u56de\u306e\u7d50\u7dda\u3067\u30b5\u30f3\u30d7\u30eb\u30b9\u30b1\u30c3\u30c1\u3092\u52d5\u4f5c\u3055\u305b\u308b\u305f\u3081\u3001void setup()\u306e\u5148\u982d\u90e8\u5206\u3092\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3057\u3066\u5b9f\u884c\u3057\u305f\u3002SPI.end(); \u306f\u5b9f\u884c\u958b\u59cb\u6642\u306b\u4f5c\u6210\u3055\u308c\u308b SPIClass \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u30aa\u30ea\u30b8\u30ca\u30eb\u306e\u8a2d\u5b9a\u5185\u5bb9\u3092\u5fd8\u308c\u3066\u3082\u3089\u3046\u305f\u3081\u306b\u5ff5\u306e\u305f\u3081\u306b\u547c\u3093\u3067\u3044\u308b\u3002\u76f4\u5f8c\u306e SPI.begin(); \u306b\u4eca\u56de\u306e\u30d4\u30f3\u914d\u7f6e\u3092\u4e0e\u3048\u3001GPIO16\u306b\u63a5\u7d9a\u3057\u305fLED\u306e\u521d\u671f\u5316\u3092\u884c\u3063\u3066\u3044\u308b\u3002SD.begin() \u306b\u3082 SPI\u306ess(slave select)\u306eGPIO\u756a\u53f7\u304c\u5fc5\u8981\u306a\u306e\u3067\u8ffd\u52a0\u3057\u305f\u3002<\/p>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306a\u5909\u66f4\u306b\u3088\u308a\u3001SD_test.ino\u306f\u7121\u4e8b\u306b\u52d5\u4f5c\u3057\u305f\u3002<\/p>\n<h3>SPI\u306e\u52d5\u4f5c\u5468\u6ce2\u6570\u3092\u5909\u3048\u3066\u307f\u308b<\/h3>\n<p>SPIClass\u30af\u30e9\u30b9\u3084SDFS\u30af\u30e9\u30b9\u306b\u306f\u3001SPI\u306e\u52d5\u4f5c\u5468\u6ce2\u6570\u3092\u5f15\u6570\u3068\u3057\u3066\u3068\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u8a66\u3057\u3066\u307f\u305f\u3002<br \/>\n\u5f53\u521d\u306f SPI.begin() \u306e\u3042\u3068\u3067 SPIClass::setFrequency(uint32_t freq); \u00a0\u3092\u547c\u3093\u3067\u307f\u305f\u304cMicroSD\u30ab\u30fc\u30c9\u306e\u8aad\u307f\u66f8\u304d\u901f\u5ea6\u306b\u5909\u5316\u304c\u306a\u304b\u3063\u305f\u3002\u3088\u304f\u898b\u3066\u307f\u308b\u3068\u3001SDFS\u30af\u30e9\u30b9\u306e begin()\u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u6570\u306b\u3082\u5468\u6ce2\u6570\u306e\u9805\u76ee\u304c\u3042\u308a\u3001\u5b9f\u969b\u306bSPI\u3092\u4ecb\u3057\u3066MicroSD\u3068\u306e\u8aad\u307f\u66f8\u304d\u3092\u884c\u3046 sd_diskio.cpp \u5185\u306e\u95a2\u6570\u306fSDFS\u30af\u30e9\u30b9\u304c\u4fdd\u6301\u3059\u308b\u65b9\u306e\u5024\u3092\u4f7f\u3063\u3066\u3044\u305f\u3002<\/p>\n<p>\u305d\u306e\u3042\u305f\u308a\u3092\u8e0f\u307e\u3048\u3066\u3001SD.begin() \u6642\u306b\u8a2d\u5b9a\u3059\u308b\u5468\u6ce2\u6570\u3068\u3001MicroSD\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u66f8\u304d\u3059\u308b\u969b\u306e\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u305d\u308c\u305e\u308c\u5909\u3048\u3066\u8ee2\u9001\u6642\u9593\u3092\u6e2c\u308b\u30b9\u30b1\u30c3\u30c1\u3092\u66f8\u3044\u3066\u307f\u305f\u3002<\/p>\n<pre class=\"lang:c++ decode:true \">#include \"FS.h\"\r\n#include \"SD.h\"\r\n#include \"SPI.h\"\r\n\/\/\r\n\/\/  1MBytes\u66f8\u3044\u3066\u30011MBytes\u8aad\u3080\u3002\r\n\/\/\r\n#define FILE_SIZE 1048576\r\n\r\nvoid fill_buffer(byte* pBuffer, int size)\r\n{\r\n  memset(pBuffer, 0x55, size \/ 2);\r\n  memset(pBuffer + (size \/ 2), 0xaa, size \/ 2);\r\n}\r\n\r\nbool read_write_test(fs::FS &amp;fs, const char* cpPath, const int buffer_size)\r\n{\r\n  byte* pBuffer = (byte*)malloc(buffer_size);\r\n  if (!pBuffer)\r\n    return false;\r\n  int read_msec = 0;\r\n  int write_msec = 0;\r\n  File f = fs.open(cpPath, FILE_WRITE);\r\n  if (!f) {\r\n    Serial.printf(\"fs.open(%s) FILE_WRITE failed.\\n\", cpPath);\r\n    free(pBuffer);\r\n    return false;\r\n  }\r\n  unsigned int start_time = millis();\r\n  int left = FILE_SIZE;\r\n  while(left &gt; 0) {\r\n    fill_buffer(pBuffer, buffer_size);\r\n    f.write(pBuffer, left &lt; buffer_size ? left : buffer_size);\r\n    left -= buffer_size;\r\n  }\r\n  f.close();\r\n  write_msec = millis() - start_time;\r\n  f = fs.open(cpPath, FILE_READ);\r\n  if (!f) {\r\n    Serial.printf(\"fs.open(%s) FILE_READ failed.\\n\", cpPath);\r\n    free(pBuffer);\r\n    return false;\r\n  }\r\n\r\n  start_time = millis();\r\n  left = FILE_SIZE;\r\n  while(left &gt; 0) {\r\n    f.read(pBuffer, left &lt; buffer_size ? left : buffer_size);\r\n    left -= buffer_size;\r\n  }\r\n  f.close();\r\n  read_msec = millis() - start_time;\r\n  free(pBuffer);\r\n  Serial.printf(\"write : %d \/ read : %d\\n\", write_msec, read_msec);\r\n  return true;\r\n}\r\n\r\nvoid die(const char* p)\r\n{\r\n  Serial.printf(\"\\n%s\\n\", p);\r\n  for(;;) {\r\n    digitalWrite(16, 1);\r\n    delay(500);\r\n    digitalWrite(16, 0);\r\n    delay(500);\r\n  }\r\n}\r\n\r\nenum { sd_sck = 18, sd_miso = 19, sd_mosi = 17, sd_ss = 5 };\r\nvoid setup()\r\n{\r\n  SPI.end();\r\n  SPI.begin(sd_sck, sd_miso, sd_mosi, sd_ss); \r\n  pinMode(16, OUTPUT);\r\n  digitalWrite(16, 1);\r\n  \r\n  Serial.begin(115200);\r\n  if(!SD.begin(sd_ss, SPI)){\r\n      Serial.println(\"Card Mount Failed\");\r\n      return;\r\n  }\r\n  uint8_t cardType = SD.cardType();\r\n  if(cardType == CARD_NONE){\r\n      Serial.println(\"No SD card attached\");\r\n      return;\r\n  }\r\n  Serial.print(\"SD Card Type: \");\r\n  if(cardType == CARD_MMC){\r\n      Serial.println(\"MMC\");\r\n  } else if(cardType == CARD_SD){\r\n      Serial.println(\"SDSC\");\r\n  } else if(cardType == CARD_SDHC){\r\n      Serial.println(\"SDHC\");\r\n  } else {\r\n      Serial.println(\"UNKNOWN\");\r\n  }\r\n\r\n  uint64_t cardSize = SD.cardSize() \/ (1024 * 1024);\r\n  Serial.printf(\"SD Card Size: %lluMB\\n\", cardSize);\r\n  Serial.println(\"-----\");\r\n}\r\n\r\ntypedef struct {\r\n  int freq;\r\n  int bufsize;\r\n} condition_t;\r\n\r\ncondition_t cond[] = {\r\n  { 2000000, 512 },\r\n  { 2000000, 1024 },\r\n  { 2000000, 2048 },\r\n  { 4000000, 512 },\r\n  { 4000000, 1024 },\r\n  { 4000000, 2048 },\r\n  { 8000000, 512 },\r\n  { 8000000, 1024 },\r\n  { 8000000, 2048 },\r\n  { 12000000, 512 },\r\n  { 12000000, 1024 },\r\n  { 12000000, 2048 },\r\n  { 16000000, 512 },\r\n  { 16000000, 1024 },\r\n  { 16000000, 2048 },\r\n  { 20000000, 512 },\r\n  { 20000000, 1024 },\r\n  { 20000000, 2048 },\r\n  {0, 0}\r\n};\r\n\r\nstatic condition_t* pcond = cond;\r\n\r\nvoid loop(){\r\n  int freq = pcond-&gt;freq;\r\n  int bufsize = pcond-&gt; bufsize;\r\n  if (!freq || !bufsize) {\r\n    die(\"finished\");\r\n  }\r\n  pcond++;\r\n  SD.end();\r\n  delay(1);\r\n  Serial.printf(\"read_write_test() freq = %d, bufsize = %d\\n\", freq, bufsize);\r\n  if (!SD.begin(sd_ss, SPI, freq))\r\n    die(\"SD.begin() failed\");\r\n  if (!read_write_test(SD, \"\/read_write.bin\", bufsize))\r\n    die(\"read_write_test() failed\");\r\n}\r\n<\/pre>\n<p>SD\u30ab\u30fc\u30c9\u306e\u30bf\u30a4\u30d7\u3092\u5224\u5b9a\u3057\u3066\u8868\u793a\u3059\u308b\u90e8\u5206\u306f\u3001SD_Test.ino\u304b\u3089\u629c\u7c8b\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>void loop() \u3067\u306f\u3001cond[] \u3068\u3044\u3046\u914d\u5217\u306b\u66f8\u3044\u3066\u3042\u308b\u5468\u6ce2\u6570\u3068\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u9806\u306b\u4f7f\u3044\u306a\u304c\u3089SD.begin() \u3068read_write_test() \u3092\u547c\u3076\u3002<br \/>\nread_write_test() \u306f\u30011024kBytes\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u8fbc\u307f\u3068\u8aad\u51fa\u3057\u3092\u884c\u3046\u304c\u3001\u305d\u306e\u3068\u304d File::write() \u3068 File::read() \u3092\u547c\u3073\u51fa\u3059\u969b\u306e\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u5f15\u6570\u3068\u3057\u3066\u3082\u3089\u3063\u3066\u3044\u308b\u3002loop() \u3067cond[]\u306e\u6700\u5f8c\u307e\u3067\u8aad\u3080\u304b\u3001\u9014\u4e2d\u3067\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u308b\u3068GPIO16\u306b\u63a5\u7d9a\u3057\u305fLED\u3092\u70b9\u6ec5\u3055\u305b\u3066\u7d42\u4e86\u3002<br \/>\n\u4ee5\u4e0b\u304c\u5b9f\u884c\u6642\u306b\u30b7\u30ea\u30a2\u30eb\u30e2\u30cb\u30bf\u306b\u51fa\u529b\u3055\u308c\u305f\u5185\u5bb9\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"striped:false lang:default decode:true\">SD Card Type: SDHC\r\nSD Card Size: 14888MB\r\n-----\r\nread_write_test() freq = 2000000, bufsize = 512\r\nwrite : 9453 \/ read : 5323\r\nread_write_test() freq = 2000000, bufsize = 1024\r\nwrite : 12064 \/ read : 5449\r\nread_write_test() freq = 2000000, bufsize = 2048\r\nwrite : 8897 \/ read : 5373\r\nread_write_test() freq = 4000000, bufsize = 512\r\nwrite : 7171 \/ read : 3175\r\nread_write_test() freq = 4000000, bufsize = 1024\r\nwrite : 8767 \/ read : 3277\r\nread_write_test() freq = 4000000, bufsize = 2048\r\nwrite : 6129 \/ read : 3226\r\nread_write_test() freq = 8000000, bufsize = 512\r\nwrite : 6095 \/ read : 2082\r\nread_write_test() freq = 8000000, bufsize = 1024\r\nwrite : 7098 \/ read : 2209\r\nread_write_test() freq = 8000000, bufsize = 2048\r\nwrite : 4792 \/ read : 2137\r\nread_write_test() freq = 12000000, bufsize = 512\r\nwrite : 5797 \/ read : 1770\r\nread_write_test() freq = 12000000, bufsize = 1024\r\nwrite : 6582 \/ read : 1877\r\nread_write_test() freq = 12000000, bufsize = 2048\r\nwrite : 4400 \/ read : 1819\r\nread_write_test() freq = 16000000, bufsize = 512\r\n[E][sd_diskio.cpp:721] sdcard_mount(): f_mount failed 0x(1)\r\n\r\nSD.begin() failed\r\n<\/pre>\n<p>\u30dc\u30fc\u30c9\u3092\u30ea\u30bb\u30c3\u30c8\u3057\u306a\u304c\u3089\u4f55\u5ea6\u304b\u8a66\u3057\u3066\u307f\u305f\u304c\u3001\u5468\u6ce2\u6570\u304c16000000 (16MHz) \u306b\u306a\u308b\u3068\u6bce\u5ea6sdcard_mount() \u304c\u5931\u6557\u3059\u308b\u3002\u4eca\u56de\u4f7f\u3063\u305fMicroSD\u30ab\u30fc\u30c9(SDHC 16G, class10) \u306b\u3088\u308b\u3082\u306e\u304b\u3001\u3042\u308b\u3044\u306fMicroSD Card\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u3088\u308b\u3082\u306e\u304b\u3002\u6b8b\u5ff5\u306a\u304c\u3089\u3001\u81ea\u7531\u306b\u4f7f\u3048\u308b\u624b\u6301\u3061\u306eMicroSD\u30ab\u30fc\u30c9\u304c1\u679a\u3057\u304b\u306a\u3044\u306e\u3067\u8a66\u305b\u306a\u3044\u3002<\/p>\n<p>\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba512\u30d0\u30a4\u30c8\u30682048\u30d0\u30a4\u30c8\u306e\u3068\u304d\u306e1\u79d2\u3042\u305f\u308a\u306e\u8ee2\u9001\u91cf(kBytes\u5358\u4f4d)\u3092\u30b0\u30e9\u30d5\u306b\u3057\u3066\u307f\u305f\u3002<\/p>\n<figure id=\"attachment_6071\" aria-describedby=\"caption-attachment-6071\" style=\"width: 481px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/0d40a5e4a645fc6b96e767d64ac0878e-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6071 size-full\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/0d40a5e4a645fc6b96e767d64ac0878e-4.png\" alt=\"\" width=\"481\" height=\"293\" \/><\/a><figcaption id=\"caption-attachment-6071\" class=\"wp-caption-text\">read\u3068write (KBytes\/sec)\u3002\u6a2a\u8ef8\u306fSD.begin()\u306b\u4e0e\u3048\u308b\u5468\u6ce2\u6570(MHz)<\/figcaption><\/figure>\n<p>\u8aad\u51fa\u3057\u306e\u65b9\u304c\u5468\u6ce2\u6570\u3092\u4e0a\u3052\u305f\u52b9\u679c\u304c\u9855\u8457\u306b\u3067\u308b\u3002\u66f8\u8fbc\u307f\u304c\u305d\u3046\u3067\u3082\u306a\u3044\u306e\u306f\u3001MicroSD\u30ab\u30fc\u30c9\u81ea\u4f53\u306e\u7279\u6027\u304b\uff1f (\u8ffd\u8a18: \u30ab\u30fc\u30c9\u306e\u8a71\u3058\u3083\u306a\u3055\u305d\u3046\u3067\u3057\u305f\u3002)<\/p>\n<h6>\u8ffd\u8a18<\/h6>\n<p>\u3082\u3046\u3061\u3087\u3063\u3068\u901f\u304f\u306a\u3089\u306a\u3044\u3082\u306e\u304b\u306a\u3001\u3068\u601d\u3063\u3066\u3059\u3053\u3057\u89e6\u3063\u3066\u307f\u305f\u304c\u3001SD.begin() \u306b16MHz\u3092\u4e0e\u3048\u308b\u3068f_mount\u304c\u5931\u6557\u3059\u308b\u306e\u306f\u5909\u308f\u3089\u306a\u3044\u3002\u3067\u306f\u3001\u8aad\u307f\u66f8\u304d\u6642\u306e\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u3088\u308a\u5927\u304d\u304f\u3057\u305f\u3089\u3069\u3046\u306a\u308b\u306e\u304b\u3068\u601d\u3063\u3066\u518d\u5ea6\u8a08\u6e2c\u3057\u3066\u307f\u305f\u3002<\/p>\n<figure id=\"attachment_6076\" aria-describedby=\"caption-attachment-6076\" style=\"width: 481px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/76c691c22c7ef40a64aa64b04f05e90c.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6076 size-full\" src=\"https:\/\/okiraku-camera.tokyo\/blog\/wp-content\/uploads\/2017\/07\/76c691c22c7ef40a64aa64b04f05e90c.png\" alt=\"\" width=\"481\" height=\"293\" \/><\/a><figcaption id=\"caption-attachment-6076\" class=\"wp-caption-text\">12MHz.\u6642\u306e4MBytes\u306eread\u3068write\u901f\u5ea6\u3002\u6a2a\u8ef8\u306f\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3002<\/figcaption><\/figure>\n<p>SD.begin()\u6642\u306b\u306f12000000 \u3092\u4e0e\u3048\u30014MBytes\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3059\u308b\u66f8\u8fbc\u307f\u3068\u8aad\u51fa\u3057\u3092\u3001\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u5909\u3048\u306a\u304c\u3089\u884c\u3063\u305f\u3002\u8aad\u51fa\u3057\u306b\u3064\u3044\u3066\u306f\u3042\u307e\u308a\u52b9\u679c\u306f\u306a\u304b\u3063\u305f(\u304b\u3048\u3063\u3066\u9045\u304f\u306a\u308b)\u3082\u306e\u306e\u3001\u66f8\u8fbc\u307f\u306b\u3064\u3044\u3066\u306f16KBytes\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u4f7f\u3046\u30682KBytes\u306e\u3068\u304d\u306e\u500d\u7a0b\u5ea6\u306e\u901f\u3055\u306b\u306a\u3063\u305f\u3002\u305d\u308c\u3067\u3082400KBytes\/sec\u7a0b\u5ea6\u3067\u3042\u308b\u3002\u8aad\u307f\u66f8\u304d\u3068\u3082\u306b\u3001\u3082\u3046\u3061\u3087\u3063\u3068\u901f\u304f\u3057\u305f\u3044\u3068\u3053\u308d\u3002\u4ed6\u306eMicroSD\u30ab\u30fc\u30c9\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5229\u7528\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u308c\u3070\u3001\u307e\u305f\u8a66\u3057\u3066\u307f\u3088\u3046\u3002<\/p>\n<h2>\u304d\u3087\u3046\u306e\u307e\u3068\u3081<\/h2>\n<ul>\n<li>SDFS::begin() \u3067\u5468\u6ce2\u6570\u3092\u7701\u7565\u3057\u305f\u3068\u304d\u306b\u306f\u30014000000 (4MHz) \u304c\u4e0e\u3048\u3089\u308c\u308b\u3002\u4eca\u56de\u306e\u69cb\u6210\u3067\u306f\u305d\u306e3\u500d\u307e\u3067\u306f\u4f7f\u3048\u305f\u3002<\/li>\n<li>\u5468\u6ce2\u6570\u3092\u9ad8\u304f\u3059\u308b\u3053\u3068\u3067read() \u3082write()\u3082\u9ad8\u901f\u5316\u3059\u308b\u3002\u305d\u306e\u52b9\u679c\u306fread()\u306e\u65b9\u304c\u9855\u8457\u306b\u73fe\u308c\u308b\u3002\u305f\u3060\u3001\u3042\u308b\u7a0b\u5ea6\u4ee5\u4e0a\u5468\u6ce2\u6570\u3092\u9ad8\u304f\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002<\/li>\n<li>read \/ write \u6642\u306e\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u306e\u5909\u66f4\u306f\u3001read()\u3067\u306f\u3042\u307e\u308a\u5f71\u97ff\u3057\u3066\u3044\u306a\u3044\u3088\u3046\u306b\u898b\u3048\u308b\u3002write() \u3067\u306f\u30011kBytes\u306e\u3068\u304d\u3044\u3064\u3082\u9045\u304f\u306a\u308b\u306e\u304c\u3061\u3087\u3063\u3068\u4e0d\u601d\u8b70\u3002\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u304c\u5927\u304d\u3044\u3068\u3044\u3046\u3053\u3068\u3060\u308d\u3046\u304b\u3002<\/li>\n<li>\u3061\u3087\u3063\u3068\u524d\u306b\u4f5c\u3063\u305fweb\u30b5\u30fc\u30d0\u30fc\u306e\u30b9\u30b1\u30c3\u30c1\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u306e\u683c\u7d0d\u3068WiFi\u7d4c\u7531\u3067\u306e\u8aad\u51fa\u3057\u3092\u884c\u3046\u6e96\u5099\u304c\u3067\u304d\u305f\u3053\u3068\u306b\u306a\u308b\u3002\u9ad8\u6027\u80fd\u306aESP32\u3092\u6d3b\u304b\u305b\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u3044\u3046\u3053\u3068\u3067\u3001CMOS\u30ab\u30e1\u30e9\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u3064\u306a\u3052\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u308b\u3002\u3044\u3064\u306b\u306a\u308b\u3053\u3068\u3084\u3089\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u79cb\u6708\u96fb\u5b50\u3067\u8cb7\u3063\u305fESP-WROOM-32\u306e\u958b\u767a\u30dc\u30fc\u30c9(DevKit-C)\u306b\u3001amazon\u3067\u898b\u3064\u3051\u305f\u5b89\u3044MicroSD\u30ab\u30fc\u30c9\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u3064\u3051\u3066\u307f\u305f\u3002WROOM-32\u5185\u306eSPI\u30d5\u30e9\u30c3\u30b7\u30e5\u3092\u4f7f\u3063\u305fspiffs\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306e\u30b3 &hellip; <a href=\"https:\/\/okiraku-camera.tokyo\/blog\/?p=6064\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">ESP32\u958b\u767a\u30dc\u30fc\u30c9\u306bMicroSD\u30ab\u30fc\u30c9\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u3064\u3051\u308b<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[65,84],"class_list":["post-6064","post","type-post","status-publish","format-standard","hentry","category-programming","tag-arduino","tag-esp32"],"_links":{"self":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6064"}],"version-history":[{"count":0,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6064\/revisions"}],"wp:attachment":[{"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/okiraku-camera.tokyo\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}