{"id":642,"date":"2022-11-23T15:37:49","date_gmt":"2022-11-23T07:37:49","guid":{"rendered":"http:\/\/wordpress.loc\/?p=642"},"modified":"2022-11-23T15:38:13","modified_gmt":"2022-11-23T07:38:13","slug":"esp32_ch1-22","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/11\/23\/642\/","title":{"rendered":"ESP32\uff08ESP8266\uff09\u53caPTC06\u4e32\u53e3\u76f8\u6a5f\u62cd\u7167\u6e2c\u8a66"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>A good and cheap solution for arduino to take picture.<br>\u7c21\u6613\u7684arduino\u62cd\u7167\u65b9\u6848 \u6700\u8fd1\u81c9\u90e8\u8fa8\u8b58\u5df2\u7d93\u6709\u4e00\u4e9b\u6210\u679c\uff0c\u56e0\u6b64\u7814\u7a76\u5982\u4f55\u7528arduino\u62cd\u7167\u7136\u5f8c\u8fa8\u8b58\u4e3b\u4eba\u4f86\u958b\u9580\u4e4b\u985e\u7684\u6307\u4ee4<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-ht-block-toc is-style-rounded htoc htoc--position-wide toc-list-style-plain\" data-htoc-state=\"expanded\"><span class=\"htoc__title\"><span class=\"ht_toc_title\">Table of Contents<\/span><span class=\"htoc__toggle\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"16\" height=\"16\"><g fill=\"#444\"><path d=\"M15 7H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><path d=\"M15 1H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1zM15 13H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><\/g><\/svg><\/span><\/span><div class=\"htoc__itemswrap\"><ul class=\"ht_toc_list\"><li class=\"\"><a href=\"#htoc-\">\u524d\u8a00<\/a><\/li><li class=\"\"><a href=\"#htoc-1\">\u7dda\u8def\u9023\u63a5<\/a><\/li><li class=\"\"><a href=\"#htoc-11\">\u7a0b\u5f0f\u78bc<\/a><\/li><\/ul><\/div><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-\">\u524d\u8a00<\/h2>\n\n\n\n<p>A good and cheap solution for arduino to take picture.<br>\u7c21\u6613\u7684arduino\u62cd\u7167\u65b9\u6848 \u6700\u8fd1\u81c9\u90e8\u8fa8\u8b58\u5df2\u7d93\u6709\u4e00\u4e9b\u6210\u679c\uff0c\u56e0\u6b64\u7814\u7a76\u5982\u4f55\u7528arduino\u62cd\u7167\u7136\u5f8c\u8fa8\u8b58\u4e3b\u4eba\u4f86\u958b\u9580\u4e4b\u985e\u7684\u6307\u4ee4\uff0c\u4f46\u662f\u767c\u73fearduino\u62cd\u7167\u5176\u5be6\u6709\u5f88\u5927\u7684\u554f\u984c\uff0cwemos D1\u88ddOV7670\u5f8c\uff0cpin\u8173\u5e7e\u4e4e\u7528\u5b8c\u7121\u6cd5\u518d\u63a5SD\u5361\uff0c\u6700\u5f8c\u641c\u5c0b\u5230PTC06\u4e32\u53e3\u651d\u5f71\u6a5f(NT$400-600\u4e4b\u9593)\uff0c2 pin\u6709TX RX\u5373\u53ef\u62cd\u7167\u3002 <\/p>\n\n\n\n<p>\u8907\u88fdarduino\u7a0b\u5f0f\u78bc\u5f8c\u5728D1\u57f7\u884c\u537b\u767c\u73fe\u62cd\u7167\u7684\u7d50\u679c\u90fd\u5931\u6557\uff0c\u6a94\u6848\u932f\u8aa4\u7121\u6cd5\u8b80\u53d6\uff0c\u4f46\u662f\u5728UNO\u4e0a\u537b\u662f\u6b63\u5e38\uff0c\u6bd4\u5c0d\u5169\u8005\u62cd\u7167\u7684\u6a94\u6848\u624d\u767c\u73fe\uff0c\u5728ESP8266\u53caESP32\u6703\u5728jpg\u6a19\u982d\u7684\u90e8\u4efd\u7522\u751f\u8aa4\u5dee\uff0c\u56e0\u6b64\u5fc5\u9808\u89c0\u5bdf\u624d\u53ef\u6c7a\u5b9a\u8981\u5982\u4f55\u8655\u7406\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-1\">\u7dda\u8def\u9023\u63a5<\/h2>\n\n\n\n<p>NodeMcu ESP-32s\u63a5\u6cd5\uff1a<br>SD\u5361\u63a5\u6cd5\uff1a<br>\/\/MOSI &#8211; pin 23<br>\/\/MISO &#8211; pin 19<br>\/\/CLK(SCK) &#8211; pin 18<br>\/\/CS &#8211; pin 5<br>PTC06\u63a5\u6cd5\uff1a<br>\/\/TX &#8211; pin12 \/\/RX &#8211; pin13<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-11\">\u7a0b\u5f0f\u78bc<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ 1. SD must be formated to FAT16\n\/\/ 2. As the buffer of softserial has 64 bytes, so the code read 32 bytes each time\n\/\/ 3. Please add the libaray to the lib path\n\/\/****************************\n\/\/SD card attached to SPI bus as follows:\n\/\/MOSI - pin 23\n\/\/MISO - pin 19\n\/\/CLK(SCK)- pin 18\n\/\/CS - pin 5\n\/\/*****************************\n\/\/CAM setup\n\/\/RX - pin12\n\/\/TX - pin13\n\/\/if tx rx set error will get empty data\n#include\n#include\n#include\nHardwareSerial mySerial(1);\n\nbyte ZERO = 0x00;\nbyte incomingbyte;\nlong int a=0x0000,j=0,k=0,count=0,i=0;\nuint8_t MH,ML;\nboolean EndFlag=0;\nFile myFile;\nboolean firsttime=true;\nvoid setup()\n{\nSerial.begin(115200);\nmySerial.begin(115200,SERIAL_8N1,13,12);\n\nSerial.print(\"Initializing SD card...\");\nif (!SD.begin())\n{\nSerial.println(\"initialization failed!\");\nreturn;\n}\nuint8_t cardType = SD.cardType();\nif(cardType == CARD_NONE){\nSerial.println(\"No SD card attached\");\nreturn;\n}\n\nif(cardType == CARD_MMC) {Serial.println(\"MMC\");}\nelse if(cardType == CARD_SD) { Serial.println(\"SDSC\");}\nelse if(cardType == CARD_SDHC) {Serial.println(\"SDHC\");}\nelse {Serial.println(\"UNKNOWN\");}\n\nSerial.println(\"initialization done.\");\nSD.remove(\"\/pic.jpg\");\n\nbyte a&#91;32];\nint ii;\nSetImageSizeCmd(\"m\");\/\/set pic size s=160x120,m=620x240,l=640x480\ndelay(20);\nSendResetCmd();\ndelay(2000); \/\/Wait 2-3 second to send take picture command\nSerial.println(\"Take Pic Command\");\nSendTakePhotoCmd(); \/\/take pic command\nfirsttime=true;\nwhile(mySerial.available()>0)\n{\nincomingbyte=mySerial.read();\n}\n\nmyFile = SD.open(\"\/pic.jpg\", FILE_WRITE); \/\/open file to save pic\nSerial.print(\"Saving to SD\");\nwhile(!EndFlag)\n{ Serial.print(\".\");\nj=0;\nk=0;\ncount=0;\nSendReadDataCmd();\n\ndelay(20);\/\/WAIT\nif(firsttime)\n{ \/\/\u7b2c\u4e00\u6b21\u53ef\u80fd\u8b80\u53d6\u5230\u8868\u982d\uff0c\u56e0\u6b64\u8981\u6539\u6210k>10\uff0c\u8981\u67e5\u770bhex\u8cc7\u6599\nwhile(mySerial.available()>0)\n{\nincomingbyte=mySerial.read();\nk++;\nif((k>10)&amp;&amp;(j&lt;32)&amp;&amp;(!EndFlag))\n{\na&#91;j]=incomingbyte;\nj++;\ncount++;\n}\n}\nfirsttime=false;\n}\nelse\n{\nwhile(mySerial.available()>0)\n{\nincomingbyte=mySerial.read();\nk++;\nif((k>5)&amp;&amp;(j&lt;32)&amp;&amp;(!EndFlag))\n{\na&#91;j]=incomingbyte;\nif((a&#91;j-1]==0xFF)&amp;&amp;(a&#91;j]==0xD9)){EndFlag=1;}\nj++;\ncount++;\n}\n}\n}\n\n\/\/print data to serial\n\/\/ for(j=0;j \/\/ {\n\/\/ if(a&#91;j]&lt;0x10)\n\/\/ Serial.print(\"0\");\n\/\/ Serial.print(a&#91;j],HEX);\n\/\/ Serial.print(\" \");\n\/\/ }\n\/\/ Serial.println();\n\n\/\/save files to sd card\nfor(ii=0; ii {\nmyFile.write(a&#91;ii]);\n}\ni++;\n}\nmyFile.close();\nSerial.println(\"\");\nSerial.println(\"Finished writing data to file\");\n}\n\nvoid loop()\n{\n\n}\nvoid SendResetCmd()\n{\nmySerial.write(0x56);\nmySerial.write(ZERO);\nmySerial.write(0x26);\nmySerial.write(ZERO);\n}\n\nvoid SetImageSizeCmd(String size)\n{\nmySerial.write(0x56);\nmySerial.write(ZERO);\nmySerial.write(0x31);\nmySerial.write(0x05);\nmySerial.write(0x04);\nmySerial.write(0x01);\nmySerial.write(ZERO);\nmySerial.write(0x19);\nif (size==\"s\")\n{\nSerial.println(\"set pic size as 160x120\");\nmySerial.write(0x22);\/\/160*120\n}\nelse if (size==\"m\")\n{\nSerial.println(\"set pic size as 320x240\");\nmySerial.write(0x11);\/\/320*240\n}\nelse if (size==\"l\")\n{\nSerial.println(\"set pic size as 640x480\");\nmySerial.write(ZERO);\/\/640*480\n} else\n{\nSerial.println(\"set pic size as 320x240\");\nmySerial.write(0x11);\/\/320*240\n}\n\n}\nvoid SetBaudRateCmd()\n{ \/\/seem useless\nmySerial.write(0x56);\nmySerial.write(ZERO);\nmySerial.write(0x24);\nmySerial.write(0x03);\nmySerial.write(0x01);\nmySerial.write(0x0D);\nmySerial.write(0xA6);\n}\n\nvoid SendTakePhotoCmd()\n{\nmySerial.write(0x56);\nmySerial.write(ZERO);\nmySerial.write(0x36);\nmySerial.write(0x01);\nmySerial.write(ZERO);\n}\n\nvoid SendReadDataCmd()\n{\nMH=a\/0x100;\nML=a%0x100;\nmySerial.write(0x56);\nmySerial.write(ZERO);\nmySerial.write(0x32);\nmySerial.write(0x0C);\nmySerial.write(ZERO);\nmySerial.write(0x0a);\nmySerial.write(ZERO);\nmySerial.write(ZERO);\nmySerial.write(MH);\nmySerial.write(ML);\nmySerial.write(ZERO);\nmySerial.write(ZERO);\nmySerial.write(ZERO);\nmySerial.write(0x20);\nmySerial.write(ZERO);\nmySerial.write(0x0A);\na+=0x20;\n}\n\nvoid StopTakePhotoCmd()\n{\nmySerial.write(0x56);\nmySerial.write(ZERO);\nmySerial.write(0x36);\nmySerial.write(0x01);\nmySerial.write(0x03);\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A good and cheap solution for arduino to take picture.\u7c21 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-642","post","type-post","status-publish","format-standard","hentry","category-esp32"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=642"}],"version-history":[{"count":1,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/642\/revisions"}],"predecessor-version":[{"id":643,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/642\/revisions\/643"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}