{"id":873,"date":"2021-05-24T07:53:44","date_gmt":"2021-05-23T23:53:44","guid":{"rendered":"https:\/\/104.es\/?p=873"},"modified":"2021-05-24T07:53:44","modified_gmt":"2021-05-23T23:53:44","slug":"nodemcu-python-03","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2021\/05\/24\/nodemcu-python-03\/","title":{"rendered":"NodeMCU\u7684Python\u958b\u767c\u6307\u5357\uff08\u4e09\uff09\u4f7f\u7528ampy\u4e0a\u50b3\u53ca\u57f7\u884cPython\u7a0b\u5f0f"},"content":{"rendered":"\n<p>\u900f\u904e\u524d\u4e00\u500b\u55ae\u5143\u7684\u8aaa\u660e\uff0c\u540c\u5b78\u5011\u61c9\u8a72\u53ef\u4ee5\u77e5\u9053\u5982\u4f55\u5229\u7528MU Editor\u5728NodeMCU\u4e0a\u6e2c\u8a66\u7a0b\u5f0f\u4e86\u3002MU Editor\u5728\u57f7\u884c\u7684\u6642\u5019\u53ef\u4ee5\u81ea\u52d5\u5075\u6e2cNodeMCU\u677f\u7684COM port\u4e26\u53ef\u81ea\u52d5\u9023\u7dda\uff0c\u5728\u57f7\u884c\u4e0a\u975e\u5e38\u65b9\u4fbf\u3002\u7136\u800c\u73fe\u968e\u6bb5\u7684MU Editor\u53ea\u80fd\u7acb\u5373\u57f7\u884c\u7a0b\u5f0f\uff0c\u4e26\u6c92\u6709\u628a\u7a0b\u5f0f\u76f4\u63a5\u653e\u5230\u677f\u5b50\u4e0a\u7684\u529f\u80fd\uff0c\u6240\u4ee5\uff0c\u5728\u9019\u88e1\u6211\u5011\u9084\u8981\u518d\u4ecb\u7d39\u53e6\u5916\u4e00\u500b\u5de5\u5177\uff0campy\u3002<\/p>\n\n\n\n<p>ampy\u662f\u4e00\u500bPython\u7684\u7a0b\u5f0f\uff0c\u5728\u4f7f\u7528\u4e4b\u524d\u9700\u8981\u53e6\u884c\u5229\u7528\u4ee5\u4e0b\u7684\u6307\u4ee4\u5b89\u88dd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install adafruit-ampy<\/code><\/pre>\n\n\n\n<p>\u5b89\u88dd\u5b8c\u6210\u4e4b\u5f8c\uff0c\u5728\u547d\u4ee4\u63d0\u793a\u5b57\u5143\u4e0b\u76f4\u63a5\u4e0b\u9054ampy\u6307\u4ee4\uff0c\u53ef\u4ee5\u770b\u5230\u4ee5\u4e0b\u7684\u4f7f\u7528\u8aaa\u660e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\course\\nodemcu&gt;ampy\nUsage: ampy &#091;OPTIONS] COMMAND &#091;ARGS]...\n\n  ampy - Adafruit MicroPython Tool\n\n  Ampy is a tool to control MicroPython boards over a serial\n  connection.  Using ampy you can manipulate files on the board's\n  internal filesystem and even run scripts.\n\nOptions:\n  -p, --port PORT    Name of serial port for connected board.  Can\n                     optionally specify with AMPY_PORT environment\n                     variable.  &#091;required]\n  -b, --baud BAUD    Baud rate for the serial connection (default\n                     115200).  Can optionally specify with AMPY_BAUD\n                     environment variable.\n  -d, --delay DELAY  Delay in seconds before entering RAW MODE\n                     (default 0). Can optionally specify with\n                     AMPY_DELAY environment variable.\n  --version          Show the version and exit.\n  --help             Show this message and exit.\n\nCommands:\n  get    Retrieve a file from the board.\n  ls     List contents of a directory on the board.\n  mkdir  Create a directory on the board.\n  put    Put a file or folder and its contents on the board.\n  reset  Perform soft reset\/reboot of the board.\n  rm     Remove a file from the board.\n  rmdir  Forcefully remove a folder and all its children from the...\n  run    Run a script and print its output.<\/code><\/pre>\n\n\n\n<p>\u5728\u4e00\u822c\u7684\u60c5\u6cc1\u4e0b\uff0c\u4e0b\u9054\u6307\u4ee4\u6240\u9700\u8981\u4f7f\u7528\u7684\u65d7\u865f\u5c31\u662f\u300c-p\u300d\u6216\u662f\u300c&#8211;port\u300d\uff0c\u9019\u500b\u662f\u7528\u4f86\u6307\u4ee4COM\u9023\u63a5\u57e0\u865f\u7684\u65d7\u865f\uff0c\u4e00\u5b9a\u8981\u6b63\u78ba\u624d\u80fd\u5920\u5b58\u53d6\u5230NodeMCU\u4e2d\u7684\u5167\u5bb9\u3002\u800c\u5f8c\u9762\u7684get\u3001ls\u3001mkdir\u3001put\u7b49\u7b49\u6307\u4ee4\uff0c\u5247\u662f\u5c0dNodeMCU\u9032\u884c\u78c1\u789f\u64cd\u4f5c\u7684\u4e3b\u8981\u547d\u4ee4\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u6211\u5011\u60f3\u8981\u5f97\u77e5\u76ee\u524dNodeMCU\u4e0a\u76ee\u524d\u6709\u54ea\u4e9b\u6a94\u6848\u6216\u76ee\u9304\uff0c\u53ef\u4ee5\u57f7\u884c\u4ee5\u4e0b\u7684\u6307\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ampy --port COM3 ls<\/code><\/pre>\n\n\n\n<p>\u57f7\u884c\u7684\u904e\u7a0b\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>D:\\course\\nodemcu&gt;ampy --port COM3 ls\n\/boot.py\n\/main.py\n\/test.txt<\/code><\/pre>\n\n\n\n<p>\u4e00\u958b\u59cb\u5982\u679c\u6211\u5011\u6c92\u6709\u628a\u4efb\u4f55\u6a94\u6848\u653e\u9032\u53bb\u7684\u8a71\uff0c\u90a3\u9ebc\u5c31\u53ea\u6703\u6709boot.py\u9019\u500b\u6a94\u6848\uff0c\u9019\u662f\u6b63\u5e38\u7684\u73fe\u8c61\u3002\u5982\u679c\u6211\u5011\u60f3\u8981\u6aa2\u8996\u5176\u4e2d\u4efb\u4e00\u500b\u6a94\u6848\uff0c\u53ea\u8981\u4f7f\u7528get\u6307\u4ee4\u5c31\u53ef\u4ee5\u4e86\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ampy --port COM3 get main.py<\/code><\/pre>\n\n\n\n<p>\u57f7\u884c\u4e0a\u8ff0\u6307\u4ee4\u4e4b\u5f8c\uff0c\u5982\u679c\u6a94\u6848\u662f\u5b58\u5728\u7684\uff0campy\u5c31\u6703\u628a\u90a3\u500b\u6a94\u6848\u7684\u5167\u5bb9\u5448\u73fe\u5728\u87a2\u5e55\u4e0a\uff0c\u7528\u9019\u500b\u65b9\u5f0f\u53ef\u4ee5\u6aa2\u8996NodeMCU\u677f\u5b50\u4e0a\u4efb\u4e00\u500b\u6587\u5b57\u6a94\uff08\u5305\u542b\u7a0b\u5f0f\u6a94\uff09\u7684\u5167\u5bb9\u3002<\/p>\n\n\n\n<p>NodeMCU\u7684MicroPython\u9810\u8a2d\u5728\u958b\u6a5f\u7684\u6642\u5019\u6703\u57f7\u884cmain.py\uff0c\u56e0\u6b64\uff0c\u6211\u5011\u53ef\u4ee5\u5728MU Editor\u7de8\u8f2f\u5668\u4e0a\u6e2c\u8a66\u7a0b\u5f0f\uff0c\u6e2c\u8a66\u6210\u529f\u53ef\u4ee5\u9806\u5229\u57f7\u884c\u4e4b\u5f8c\uff0c\u518d\u628a\u5b83\u4ee5main.py\u547d\u540d\uff0c\u4e4b\u5f8c\u518d\u56de\u5230\u547d\u4ee4\u63d0\u793a\u5b57\u5143\uff0c\u900f\u904eampy\u7684put\u6307\u4ee4\u628amain.py\u6a94\u6848\u4e0a\u50b3\uff0c\u50b3\u8f38\u5b8c\u7562\u518d\u6309\u4e0bRST\u6309\u9215\uff0c\u8a72\u7a0b\u5f0f\u5c31\u6703\u4e0d\u65b7\u5730\u904b\u884c\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ampy --port COM3 put main.py<\/code><\/pre>\n\n\n\n<p>\u7576\u7136\uff0c\u6211\u5011\u4e5f\u53ef\u4ee5\u5728\u4e0d\u4e0a\u50b3\u6a94\u6848\u7684\u65b9\u5f0f\u57f7\u884c\u7a0b\u5f0f\uff0c\u8b93\u5728\u672c\u5730\u7684\u7a0b\u5f0f\u5229\u7528NodeMCU\u57f7\u884c\uff0c\u6307\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ampy --port COM3 run test1.py<\/code><\/pre>\n\n\n\n<p>\u540c\u5b78\u5011\u53ef\u4ee5\u628a\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u5132\u5b58\u6210test1.py\uff0c\u7136\u5f8c\u518d\u57f7\u884c\u4e0a\u8ff0\u6307\u4ee4\uff0c\u770b\u770b\u677f\u5b50\u4e0a\u7684\u85cd\u8272LED\u662f\u5426\u6703\u4ee50.2\u79d2\u7684\u9593\u9694\u4e0d\u65b7\u5730\u9583\u720d\u5594\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from machine import Pin\nimport time\n\nled = Pin(2, Pin.OUT)\nwhile True:\n    led.off()\n    time.sleep(0.2)\n    led.on()\n    time.sleep(0.2)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u900f\u904e\u524d\u4e00\u500b\u55ae\u5143\u7684\u8aaa\u660e\uff0c\u540c\u5b78\u5011\u61c9\u8a72\u53ef\u4ee5\u77e5\u9053\u5982\u4f55\u5229\u7528MU Editor\u5728NodeMCU\u4e0a\u6e2c\u8a66\u7a0b\u5f0f\u4e86\u3002MU Editor\u5728\u57f7\u884c\u7684\u6642\u5019\u53ef\u4ee5\u81ea\u52d5\u5075\u6e2cNodeMCU\u677f\u7684COM port\u4e26\u53ef\u81ea\u52d5\u9023\u7dda\uff0c\u5728\u57f7\u884c\u4e0a\u975e\u5e38\u65b9\u4fbf\u3002\u7136\u800c\u73fe\u968e\u6bb5\u7684MU Editor\u53ea\u80fd\u7acb\u5373\u57f7\u884c\u7a0b\u5f0f\uff0c\u4e26\u6c92\u6709\u628a\u7a0b\u5f0f\u76f4\u63a5\u653e\u5230\u677f\u5b50\u4e0a\u7684\u529f\u80fd\uff0c\u6240\u4ee5\uff0c\u5728\u9019\u88e1\u6211\u5011\u9084\u8981\u518d\u4ecb\u7d39\u53e6\u5916\u4e00\u500b\u5de5\u5177\uff0campy\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,20],"tags":[],"class_list":["post-873","post","type-post","status-publish","format-standard","hentry","category-nodemcu","category-20"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/873","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=873"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/873\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}