{"id":2810,"date":"2018-09-16T10:34:08","date_gmt":"2018-09-16T02:34:08","guid":{"rendered":"https:\/\/drho.club\/?p=2331"},"modified":"2018-09-16T10:34:08","modified_gmt":"2018-09-16T02:34:08","slug":"micropython-ampy","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2018\/09\/16\/micropython-ampy\/","title":{"rendered":"\u3010NodeMCU MicroPython\u3011\u4f7f\u7528ampy\u628a\u7a0b\u5f0f\u5beb\u5728NodeMCU\u4e2d"},"content":{"rendered":"<p>\u5728\u524d\u9762\u7684MicroPython\u7684\u958b\u767c\u65b9\u5f0f\u4e2d\uff0c\u6211\u5011\u4f7f\u7528PuTTY\u4ee5REPL\u7684\u65b9\u5f0f\u5728NodeMCU\u4e0a\u76f4\u63a5\u7de8\u5beb\u7a0b\u5f0f\uff0c\u9019\u6a23\u7684\u597d\u8655\u662f\u6240\u6709\u7684\u6307\u4ee4\u90fd\u662f\u5728\u6309\u4e0bEnter\u4e4b\u5f8c\u76f4\u63a5\u57f7\u884c\uff0c\u53ef\u4ee5\u99ac\u4e0a\u770b\u5230\u7d50\u679c\uff0c\u4f46\u554f\u984c\u662f\uff0c\u5982\u679c\u4e0d\u5c0f\u5fc3\u6253\u932f\u5b57\u4e86\uff0c\u5c31\u8981\u518d\u91cd\u4f86\u4e00\u6b21\u3002\u6b64\u5916\uff0c\u6240\u6709\u7684\u7a0b\u5f0f\u5728\u91cd\u65b0\u958b\u6a5f\u5c31\u90fd\u4e0d\u898b\u4e86\uff0c\u8981\u518d\u91cd\u65b0\u8f38\u5165\u4e00\u6b21\uff0c\u9019\u5c0d\u65bc\u8981\u7de8\u5beb\u7a0d\u5fae\u5927\u4e00\u9ede\u7684\u7a0b\u5f0f\u7684\u6211\u5011\u4f86\u8aaa\uff0c\u4f7f\u7528\u4e0a\u6703\u975e\u5e38\u4e0d\u65b9\u4fbf\uff0c\u6240\u5e78\uff0c\u6709\u53e6\u5916\u4e00\u500b\u4f5c\u6cd5\u53ef\u4ee5\u514b\u670d\u9019\u500b\u554f\u984c\u3002<\/p>\n<p>\u5728MicroPython\u4e2d\uff0c\u7cfb\u7d71\u4e0b\u6709\u5169\u500b\u7a0b\u5f0f\u662fNodeMCU\u5728\u4e00\u63a5\u4e0a\u96fb\u6e90\u7684\u6642\u5019\u5c31\u6703\u99ac\u4e0a\u88ab\u57f7\u884c\u7684\u7a0b\u5f0f\uff0c\u4f9d\u5e8f\u662fboot.py\u4ee5\u53camain.py\u3002\u6240\u4ee5\uff0c\u6709\u4e00\u500b\u7c21\u55ae\u7684\u65b9\u5f0f\u5c31\u662f\uff0c\u5982\u679c\u6211\u5011\u5728NodeMCU\u7684\u677f\u5b50\u4e0a\u4e0a\u50b3\u4e00\u500bmain.py\u7684\u7a0b\u5f0f\uff0c\u90a3\u9ebc\u6bcf\u6b21NodeMCU\u4e00\u88ab\u555f\u52d5\u7684\u6642\u5019\uff0c\u5c31\u6703\u5728\u57f7\u884c\u5b8cboot.py\u4e4b\u5f8c\uff0c\u7acb\u5373\u524d\u5f80\u57f7\u884cmain.py\uff0c\u5c31\u53ef\u4ee5\u9054\u5230\u8b93NodeMCU\u812b\u96e2\u96fb\u8166\uff0c\u53ea\u8981\u63a5\u4e0a\u96fb\u6e90\u5c31\u53ef\u4ee5\u904b\u4f5c\u7684\u6a21\u5f0f\u4e86\u3002<\/p>\n<p>\u90a3\u9ebc\u6211\u5011\u61c9\u8a72\u5982\u4f55\u628amain.py\u4e0a\u50b3\uff0c\u5beb\u5728NodeMCU\u7684\u677f\u5b50\u4e0a\u5462\uff1f\u56de\u60f3\u4e00\u4e0b\uff0c\u4e4b\u524d\u6211\u5011\u4f7f\u7528\u7684REPL\u9023\u7dda\u65b9\u5f0f\uff0c\u90fd\u662f\u900f\u904eShell\u4e00\u6b65\u4e00\u6b65\u57f7\u884c\u7a0b\u5f0f\uff0c\u8a72\u7a0b\u5f0f\u4e26\u4e0d\u6703\u88ab\u5beb\u5728\u677f\u5b50\u4e0a\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u60f3\u8981\u4f7f\u7528\u4e0a\u50b3\u7a0b\u5f0f\u6a94\u6848\u7684\u529f\u80fd\uff0c\u9700\u8981\u518d\u5b89\u88dd\u53e6\u5916\u4e00\u500b\u5957\u4ef6\u624d\u884c\uff0c\u9019\u500b\u5957\u4ef6\u5c31\u53eb\u505aampy\uff0c\u8acb\u4f7f\u7528\u4ee5\u4e0b\u7684\u65b9\u5f0f\u5b89\u88dd\uff1a<\/p>\n<p>[code]<br \/>\npip install adafruit-ampy<br \/>\n[\/code]<\/p>\n<p>\u9806\u5229\u5b89\u88dd\u5b8c\u7562\u4e4b\u5f8c\uff0c\u5c31\u53ef\u4ee5\u57f7\u884campy\uff0c\u770b\u770b\u80fd\u5920\u5f97\u5230\u4ec0\u9ebc\u8a0a\u606f\uff1a<\/p>\n<p>[code]<br \/>\n(base) C:\\Users\\USER&gt;ampy<br \/>\nUsage: ampy [OPTIONS] COMMAND [ARGS]&#8230;<\/p>\n<p>  ampy &#8211; Adafruit MicroPython Tool<\/p>\n<p>  Ampy is a tool to control MicroPython boards over a serial connection.<br \/>\n  Using ampy you can manipulate files on the board&#8217;s internal filesystem and<br \/>\n  even run scripts.<\/p>\n<p>Options:<br \/>\n  -p, &#8211;port PORT    Name of serial port for connected board.  Can optionally<br \/>\n                     specify with AMPY_PORT environment variable.  [required]<br \/>\n  -b, &#8211;baud BAUD    Baud rate for the serial connection (default 115200).<br \/>\n                     Can optionally specify with AMPY_BAUD environment<br \/>\n                     variable.<br \/>\n  -d, &#8211;delay DELAY  Delay in seconds before entering RAW MODE (default 0).<br \/>\n                     Can optionally specify with AMPY_DELAY environment<br \/>\n                     variable.<br \/>\n  &#8211;version          Show the version and exit.<br \/>\n  &#8211;help             Show this message and exit.<\/p>\n<p>Commands:<br \/>\n  get    Retrieve a file from the board.<br \/>\n  ls     List contents of a directory on the board.<br \/>\n  mkdir  Create a directory on the board.<br \/>\n  put    Put a file or folder and its contents on the&#8230;<br \/>\n  reset  Perform soft reset\/reboot of the board.<br \/>\n  rm     Remove a file from the board.<br \/>\n  rmdir  Forcefully remove a folder and all its&#8230;<br \/>\n  run    Run a script and print its output.<br \/>\n[\/code]<\/p>\n<p>\u5f9e\u4e0a\u9762\u7684\u6559\u5b78\u8a0a\u606f\u53ef\u4ee5\u770b\u51fa\uff0c\u547d\u4ee4put\u5c31\u662f\u4e0a\u50b3\u6a94\u6848\u7684\u610f\u601d\u3002\u6240\u4ee5\uff0c\u63a5\u4e0b\u4f86\u7684\u6b65\u9a5f\u5c31\u662f\u5728\u81ea\u5df1\u7684\u96fb\u8166\u4e2d\u900f\u904e\u7a0b\u5f0f\u78bc\u7de8\u8f2f\u5668\u7de8\u8f2fmain.py\u9019\u500b\u6a94\u6848\uff0c\u5b58\u6a94\u4e4b\u5f8c\uff0c\u4f7f\u7528ampy &#8211;port COM3 put main.py\u5c31\u53ef\u4ee5\u628a\u6a94\u6848\u4e0a\u50b3\u4e86\u3002\u7a0b\u5f0f\u5167\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>[code language=&#8221;python&#8221;]<br \/>\nfrom machine import Pin<br \/>\nimport time<\/p>\n<p>led = Pin(2, Pin.OUT)<br \/>\nwhile True:<br \/>\n    led.on()<br \/>\n    time.sleep(0.5)<br \/>\n    led.off()<br \/>\n    time.sleep(0.5)<br \/>\n[\/code]<\/p>\n<p>\u57f7\u884c\u7684\u904e\u7a0b\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>[code]<br \/>\nampy &#8211;port COM3 put main.py<br \/>\n[\/code]<\/p>\n<p>\u4e0a\u50b3\u5b8c\u7562\u5982\u679c\u6c92\u6709\u51fa\u73fe\u4efb\u4f55\u932f\u8aa4\u8a0a\u606f\u7684\u8a71\uff0c\u628aNodeMCU\u91cd\u65b0\u555f\u52d5\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u677f\u5b50\u4e0a\u7684LED\u5728\u9583\u720d\u56c9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u524d\u9762\u7684MicroPython\u7684\u958b\u767c\u65b9\u5f0f\u4e2d\uff0c\u6211\u5011\u4f7f\u7528PuTTY\u4ee5REPL\u7684\u65b9\u5f0f\u5728NodeMCU\u4e0a\u76f4\u63a5\u7de8\u5beb\u7a0b\u5f0f\uff0c\u9019\u6a23\u7684\u597d\u8655\u662f\u6240\u6709\u7684\u6307\u4ee4\u90fd\u662f\u5728\u6309\u4e0bEnter\u4e4b\u5f8c\u76f4\u63a5\u57f7\u884c\uff0c\u53ef\u4ee5\u99ac\u4e0a\u770b\u5230\u7d50\u679c\uff0c\u4f46\u554f\u984c\u662f\uff0c\u5982\u679c\u4e0d\u5c0f\u5fc3\u6253\u932f\u5b57\u4e86\uff0c\u5c31\u8981\u518d\u91cd\u4f86\u4e00\u6b21\u3002\u6b64\u5916\uff0c\u6240\u6709\u7684\u7a0b\u5f0f\u5728\u91cd\u65b0\u958b\u6a5f\u5c31\u90fd\u4e0d\u898b\u4e86\uff0c\u8981\u518d\u91cd\u65b0\u8f38\u5165\u4e00\u6b21\u3002\u672c\u7bc7\u6587\u7ae0\u6559\u5927\u5bb6\u5982\u4f55\u8b93NodeMCU\u8a18\u4f4f\u6211\u5011\u7de8\u5beb\u904e\u7684\u7a0b\u5f0f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13],"tags":[108,44],"class_list":["post-2810","post","type-post","status-publish","format-standard","hentry","category-nodemcu","tag-ampy","tag-micropython"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=2810"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2810\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}