{"id":283,"date":"2019-09-02T16:12:46","date_gmt":"2019-09-02T08:12:46","guid":{"rendered":"https:\/\/aichh.com\/?p=283"},"modified":"2020-12-24T09:17:25","modified_gmt":"2020-12-24T01:17:25","slug":"%e6%a0%91%e8%8e%93%e6%b4%bezero-w-gpio%e6%8e%a7%e5%88%b6","status":"publish","type":"post","link":"https:\/\/aichh.com\/283.html","title":{"rendered":"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236"},"content":{"rendered":"<h2>0.\u00a0 \u6982\u8ff0<\/h2>\n<p>\u672c\u6587\u4ecb\u7ecd\u6811\u8393\u6d3e Zero W\u7684GPIO\u63a7\u5236\uff0c\u5e76\u7528LED\u770b\u6548\u679c\u3002<\/p>\n<h3>0.1 \u6811\u8393\u6d3eGPIO\u7f16\u53f7\u65b9\u5f0f<\/h3>\n<h2>1.\u00a0 \u51c6\u5907<\/h2>\n<h3>1.1 \u786c\u4ef6<\/h3>\n<ul>\n<li>\u6811\u8393\u6d3ePi Zero W<\/li>\n<li>LED\uff083mm\u62165mm\uff09<\/li>\n<li>1K\u03a9\u7535\u963b<\/li>\n<li>\u675c\u90a6\u7ebf3\u6839<\/li>\n<li>\u7535\u8111\uff08\u6211\u7528Windows 7\uff09<\/li>\n<\/ul>\n<h1>GPIO\u529f\u80fd<img loading=\"lazy\" decoding=\"async\" title=\"j8header-photo-zero-large-400x230-1\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2020\/12\/j8header-photo-zero-large-400x230-1.png\" width=\"400\" height=\"230\"><\/h1>\n<p>\u6811\u8393\u6d3e\u63d0\u4f9b\u4e8640\u4e2aPIN\u53e3\uff0c\u5927\u81f4\u7684\u5b9a\u4e49\u5982\u4e0b\u3002\u5176\u4e2d\u9ec4\u8272\u7684GPIO PIN\u53e3\u670926\u4e2a\u3002 \u5176\u4f59\u7684\u662f\u4f9b\u7535\u63a5\u53e3\u548c\u63a5\u5730\u53e3\u3002\u6bcf\u4e2aGPIO\u63a5\u53e3\u90fd\u53ef\u4ee5\u7528\u4f5c\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u4f7f\u7528\u3002\u00a0<strong>\u6bcf\u4e2aGPIO\u9488\u811a\u90fd\u6709\u7f16\u53f7\uff0c\u4f46\u662f\u7f16\u53f7\u4e0d\u662f\u7ebf\u6027\u7684\u3002\u00a0<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2020\/12\/j8header-zero-large-220x400-1.png\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c2\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c2\u5f20-AiCHH Ideas\" ><\/p>\n<p>&nbsp;<\/p>\n<h2>\u9488\u811a\u7535\u538b<\/h2>\n<p>&nbsp;<\/p>\n<p>2\u4e2a\u7ea2\u8272\u7684\u9488\u53e3\u63d0\u4f9b\u4e865V\u7684\u8f93\u51fa\u7535\u538b\uff0c2\u4e2a\u6a58\u8272\u7684\u9488\u53e3\u63d0\u4f9b3.3V\u8f93\u51fa\u7535\u538b\u3002 \u800c8\u4e2a\u9ed1\u8272\u9488\u53e3\u4f5c\u4e3a\u63a5\u5730\u4e3a0V\u3002 \u5176\u4ed6\u7684\u63a5\u53e3\u53ef\u4ee5\u63d0\u4f9b\u8f93\u5165\u8f93\u51fa\u529f\u80fd\u3002\u6240\u4ee5\u4f5c\u8f93\u51fa\u65f6\u53ef\u4ee5\u63d0\u4f9b3.3V\u7535\u538b\uff0c\u800c\u4f5c\u4e3a\u8f93\u5165\u65f6\u80fd\u627f\u53d73.3V\u7535\u538b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u8f93\u5165\/\u8f93\u51fa<\/h2>\n<p>&nbsp;<\/p>\n<p>\u5bf9\u4e8eGPIO\u63a5\u53e3\u6765\u8bf4\uff0c\u6700\u91cd\u8981\u7684\u5c31\u662f\u8f93\u5165\u548c\u8f93\u51fa\u529f\u80fd\u3002\u5bf9\u4e8e\u8ba1\u7b97\u673a\u6765\u8bf4\u80fd\u8bc6\u522b\u7684\u53ea\u67090\u548c1\uff0c\u800c\u5bf9\u4e8e\u6570\u5b57\u7535\u8def\u6765\u8bf4\u901a\u8fc7\u9ad8\u4f4e\u7535\u5e73\u6765\u8868\u793a\u8f93\u51fa\u7684\u503c\u662f0\u8fd8\u662f1\u3002 \u56e0\u4e3a\u6811\u8393\u6d3eGPIO\u63a5\u53e3\u7684\u7535\u538b\u662f3.3V\u3002\u6240\u4ee5\u75283.3V\u8868\u793a\u9ad8\u7535\u5e73\uff0c\u4e5f\u5c31\u662f1\uff0c\u800c\u75280V\u8868\u793a\u4f4e\u7535\u5e73\uff0c\u4e5f\u5c31\u662f0\u3002\u4e00\u822c\u6765\u8bf4\u9ad8\u4f4e\u7535\u5e73\u4f1a\u662f\u4e00\u4e2a\u7535\u538b\u8303\u56f4\u3002<\/p>\n<p>\u5728\u4e70\u5916\u8bbe\u7684\u65f6\u5019\u53d1\u73b0\uff0c\u6709\u4e9b\u8bbe\u5907\u662f5V\u9ad8\u7535\u5e73\uff0c\u6709\u4e9b\u662f3.3V\u3002\u4e86\u89e3\u5230\u5355\u7247\u673a\u5206\u4e3a3.3V\u548c5V\uff0c\u5c31\u662f\u6307\u7684\u662fGPIO\u63a5\u53e3\u7684\u7535\u538b\u3002\u5982\u679c\u7528GPIO\u53e3\u4ea7\u751f\u4e00\u4e2a3.3V\u7684\u9ad8\u7535\u5e73\u7ed9\u4e00\u4e2a5V\u7684\u8bbe\u5907\uff0c\u53ef\u80fd\u4f1a\u88ab\u8ba4\u4e3a\u662f\u4f4e\u7535\u5e73\uff0c\u5982\u679c\u76f4\u63a5\u63a5\u4e0a\u4e00\u4e2a5V\u8bbe\u5907\u4f5c\u4e3a\u8f93\u5165\u7535\u5e73\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6811\u8393\u6d3e\u70e7\u574f\u3002\u6240\u4ee5\u4f7f\u7528\u5916\u8bbe\u662f\u8981\u6ce8\u610f\u8fd9\u4e2a\u5916\u8bbe\u7684\u7535\u538b\u662f5V\u8fd8\u662f3.3V\u3002<\/p>\n<p>\u5f53GPIO\u7528\u505a\u8f93\u5165\u65f6\uff0c\u4f1a\u6709\u9ad8\u7535\u5e73\u3001\u4f4e\u7535\u5e73\u3001\u9ad8\u963b\u6001\u4e09\u4e2a\u72b6\u6001\u3002\u9ad8\u963b\u6001\uff0c\u6307\u7684\u662f\u7535\u8def\u7684\u4e00\u79cd\u8f93\u51fa\u72b6\u6001\uff0c\u65e2\u4e0d\u662f\u9ad8\u7535\u5e73\u4e5f\u4e0d\u662f\u4f4e\u7535\u5e73\uff0c\u8fd9\u4e2a\u65f6\u5019\u56e0\u4e3a\u72b6\u6001\u4e0d\u786e\u5b9a\uff0c\u8bfb\u53d6GPIO\u65f6\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u4e0d\u6b63\u786e\u3002\u6240\u4ee5\u5f15\u5165\u4e86\u4e0a\u62c9\u548c\u4e0b\u62c9\u7535\u963b\u7684\u6982\u5ff5\u3002<\/p>\n<ul>\n<li><span class=\"bjh-p\">\u4e0a\u62c9\u7535\u963b\uff1a\u7535\u963b\u4e00\u7aef\u63a5VCC\uff0c\u4e00\u7aef\u63a5\u903b\u8f91\u7535\u5e73\u63a5\u5165\u5f15\u811a(\u5982\u5355\u7247\u673a\u5f15\u811a)<\/span><\/li>\n<li><span class=\"bjh-p\">\u4e0b\u62c9\u7535\u963b\uff1a\u7535\u963b\u4e00\u7aef\u63a5GND\uff0c\u4e00\u7aef\u63a5\u903b\u8f91\u7535\u5e73\u63a5\u5165\u5f15\u811a(\u5982\u5355\u7247\u673a\u5f15\u811a)<\/span><\/li>\n<\/ul>\n<blockquote><p>A GPIO pin designated as an input pin can be read as high (3V3) or low (0V). This is made easier with the use of internal pull-up or pull-down resistors. Pins GPIO2 and GPIO3 have fixed pull-up resistors, but for other pins this can be configured in software.<\/p><\/blockquote>\n<p>\u4ece\u5b98\u7f51\u6587\u6863\u770b\uff0c\u6811\u8393\u6d3e\u6bcf\u4e2aGPIO\u63a5\u53e3\u90fd\u6709\u4e0a\u62c9\u548c\u4e0b\u62c9\u7535\u963b\uff0c\u5927\u90e8\u5206\u662f\u53ef\u4ee5\u901a\u8fc7\u8f6f\u4ef6\u7684\u65b9\u5f0f\u6765\u8bbe\u7f6e\u3002\u6240\u4ee5\u6811\u8393\u6d3e\u5728\u8fde\u63a5\u5916\u8bbe\u65f6\u53ef\u4ee5\u4e0d\u9700\u8981\u5916\u90e8\u7684\u4e0a\u62c9\u6216\u4e0b\u62c9\u7535\u963b\u3002\u800c\u662f\u521d\u59cb\u5316\u65f6\u8bbe\u7f6e\u4e00\u4e0b\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u66f4\u591a\u4e0a\u4e0b\u62c9\u7535\u963b\u7684\u6982\u5ff5\u53ef\u4ee5\u53c2\u8003\uff1a<\/p>\n<p class=\"p-name entry-title\"><span style=\"color: #0000ff;\"><a class=\"u-url\" style=\"color: #0000ff;\" href=\"http:\/\/www.raspberryvi.org\/stories\/pull-up-and-pull-down-resistors.html#\" target=\"_blank\" rel=\"noopener noreferrer\">Pull-up and pull-down Resistors<\/a><\/span><\/p>\n<p class=\"title-article\"><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/blog.csdn.net\/dengjin20104042056\/article\/details\/47837963\" target=\"_blank\" rel=\"noopener noreferrer\">\u4e0a\u62c9\u7535\u963b\u4e0e\u4e0b\u62c9\u7535\u963b\u6709\u4ec0\u4e48\u4f5c\u7528<\/a><\/span><\/p>\n<p><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/blog.csdn.net\/mxgsgtc\/article\/details\/52565670\" target=\"_blank\" rel=\"noopener noreferrer\">GPIO\u7535\u8def\u56fe\u4ee5\u53ca\u4e0a\u62c9\u7535\u963b\u7684\u4f5c\u7528<\/a><\/span><\/p>\n<p><span style=\"color: #0000ff;\"><a id=\"cb_post_title_url\" style=\"color: #0000ff;\" href=\"https:\/\/www.cnblogs.com\/lulipro\/p\/7675167.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u4e0a\u62c9\u7535\u963b\u548c\u4e0b\u62c9\u7535\u963b<\/a><\/span><\/p>\n<p class=\"postTitle\"><span style=\"color: #0000ff;\"><a id=\"cb_post_title_url\" class=\"postTitle2\" style=\"color: #0000ff;\" href=\"https:\/\/www.cnblogs.com\/sunshine-jackie\/p\/8413901.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u7535\u963b\uff084\uff09\u4e4b\u4e0a\u62c9\u7535\u963b\u4e0e\u4e0b\u62c9\u7535\u963b\u8be6\u89e3<\/a><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>GPIO\u6570\u636e\u4f20\u8f93<\/h2>\n<p>&nbsp;<\/p>\n<p>\u548c\u5916\u8bbe\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1\u4e3b\u8981\u901a\u8fc7GOIP\u63a5\u53e3\u8fdb\u884c\u8f93\u5165\u548c\u8f93\u51fa\u3002GPIO\u63a5\u53e3\u63d0\u4f9b\u4e86\u53ef\u7f16\u7a0b\u7684\u65b9\u5f0f\u4ece\u5916\u8bbe\u8bfb\u53d6\u6216\u5411\u5916\u8bbe\u53d1\u9001\u72b6\u6001\u6570\u636e\u3002\u901a\u8fc7\u63a7\u5236\u63a7\u5236\u9ad8\u4f4e\u7535\u5e73\u53ef\u4ee5\u8f93\u51fa\u4e0d\u540c\u72b6\u6001\uff0c\u6240\u4ee5\u7528\u505a\u5f00\u5173\u63a7\u5236\u662f\u975e\u5e38\u7b80\u5355\u6709\u6548\u7684\u3002\u4f5c\u4e3a\u8f93\u5165\u65f6\u53ef\u4ee5\u8bfb\u53d6\u6570\u503c\u6216\u8005\u662f\u72b6\u6001\u3002\u867d\u7136\u6bcf\u6b21\u53ea\u80fd\u4f20\u90120\u548c1\u8fd9\u6837\u7684\u6570\u636e\uff0c\u4f46\u662f\u591a\u6b21\u8fde\u7eed\u4f20\u90120\u548c1\u7ec4\u5408\u8d77\u6765\uff0c\u5c31\u53ef\u4ee5\u4f20\u9012\u590d\u6742\u7684\u6570\u636e\u3002 \u6bd4\u5982\u6e29\u5ea6\u4f20\u611f\u5668\u5c31\u662f\u7528GPIO\u53e3\u901a\u8fc7\u5355\u603b\u7ebf\u534f\u8bae\u8fdb\u884c\u6570\u636e\u4ea4\u6362\u3002 \u901a\u8fc7GPIO\u53ef\u4ee5\u8fdb\u884c\u5404\u79cd\u534f\u8bae\u7684\u901a\u4fe1\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>PWM<\/h3>\n<p>&nbsp;<\/p>\n<p>\u8109\u51b2\u5bbd\u5ea6\u8c03\u5236(PWM)\uff0c\u662f\u82f1\u6587\u201c<a class=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Pulse-width_modulation\">Pulse Width Modulation<\/a>\u201d \u7684\u7f29\u5199\uff0c\u7b80\u79f0\u8109\u5bbd\u8c03\u5236\uff0c\u662f\u5229\u7528\u5fae\u5904\u7406\u5668\u7684\u6570\u5b57\u8f93\u51fa\u6765\u5bf9\u6a21\u62df\u7535\u8def\u8fdb\u884c\u63a7\u5236\u7684\u4e00\u79cd\u975e\u5e38\u6709\u6548\u7684\u6280\u672f\u3002\u6bd4\u5982\u4f3a\u670d\u7535\u673a\u4f7f\u7528\u8f93\u5165PWM\u4fe1\u53f7\u7684\u8109\u51b2\u5bbd\u5ea6\u6765\u786e\u5b9a\u5b83\u4eec\u7684\u65cb\u8f6c\u89d2\u5ea6\uff0cLCD\u663e\u793a\u5668\u57fa\u4e8ePWM\u4fe1\u53f7\u7684\u5e73\u5747\u503c\u6765\u63a7\u5236\u5b83\u4eec\u7684\u4eae\u5ea6\u3002PWM\u662f\u6839\u636e<strong>\u9891\u7387<\/strong>\u548c<strong>\u5360\u7a7a\u6bd4<\/strong>\u8fdb\u884c\u9707\u8361\u7684\u6570\u5b57\u4fe1\u53f7\uff08\u65b9\u6ce2\uff09<\/p>\n<ul>\n<li>\u5468\u671f(Period)\uff1a\u8109\u51b2\u4fe1\u53f7\u4ece\u4e00\u4e2a\u4e0a\u5347\u6cbf\u5230\u4e0b\u4e00\u4e2a\u4e0a\u5347\u6cbf\u7684\u65f6\u95f4<\/li>\n<li>\u9891\u7387(Frequency)\uff1a\u63cf\u8ff01\u79d2\u949f\u5185\u8109\u51b2\u5468\u671f\u53d1\u751f\u7684\u6b21\u6570<\/li>\n<li>\u5360\u7a7a\u6bd4(Duty): \u4e00\u4e2a\u5468\u671f\u4e2d\u9ad8\u7535\u5e73\u65f6\u95f4\u5360\u6574\u4e2a\u5468\u671f\u65f6\u95f4\u7684\u767e\u5206\u6bd4<\/li>\n<\/ul>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675088-1300-pwm-signal.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675088-1300-pwm-signal.png\" width=\"815\" height=\"227\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c3\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c3\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e0d\u540c\u7684\u5360\u7a7a\u6bd4\u6765\u63a7\u5236\u8109\u51b2\u5bbd\u5ea6\u6216\u8005\u4fe1\u53f7\u7684\u5e73\u5747\u503c \uff0c\u4ece\u800c\u8fbe\u5230\u63a7\u5236\u5916\u90e8\u8bbe\u5907\u7684\u76ee\u7684\u3002\u4e0b\u56fe\u662f\u5360\u7a7a\u6bd4\u4e3a0\uff0c25%\u548c100%\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675088-1230-pwm-duty.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675088-1230-pwm-duty.png\" width=\"930\" height=\"460\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c4\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c4\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p>PWM\u6709\u786c\u4ef6\u548c\u8f6f\u4ef6\u4e24\u79cd\u8f93\u51fa\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\u8f6f\u4ef6\u65b9\u6cd5\uff1a\u5c06\u666e\u901aGPIO\u5f15\u811a\u4f5c\u4e3aPWM\u8f93\u51fa\u5f15\u811a\uff0c\u4f9d\u636e\u5b9e\u9645\u9700\u6c42\uff0c\u914d\u7f6e\u597d\u8ba1\u65f6\u5668\uff0c\u5728\u6307\u5b9a\u8ba1\u65f6\u5468\u671f\u7ffb\u8f6cGPIO\u5f15\u811a\u7535\u5e73\uff0c\u5b9e\u73b0PWM\u529f\u80fd\u3002\u901a\u8fc7\u7ec8\u7aef\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5360\u7528CPU\uff0c\u7cbe\u5ea6\u5dee\uff0c\u63a7\u5236\u590d\u6742<\/li>\n<li>\u786c\u4ef6\u65b9\u6cd5\uff1a\u5728\u539f\u7406\u56fe\u8bbe\u8ba1\u65f6\uff0c\u5c06\u652f\u6301\u786c\u4ef6PWM\u7684\u5f15\u811a\u4f5c\u4e3aPWM\u8f93\u51fa\u5f15\u811a\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u914d\u7f6e\u5bc4\u5b58\u5668\uff0c\u91c7\u7528\u786c\u4ef6\u5b9e\u73b0PWM\u529f\u80fd\u4e86\u3002\u901a\u8fc7\u4e8b\u4ef6\u65b9\u5f0f\u5b9e\u73b0\uff0c\u4e0d\u5360\u7528CPU\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><em><strong>\u5728\u6811\u8393\u6d3e\u4e0a\uff0c\u6240\u6709GPIO\u63a5\u53e3\u90fd\u652f\u6301\u8f6f\u4ef6\u65b9\u5f0f\u8f93\u51faPWMi\u4fe1\u53f7\uff0cGPIO12\u3001GPIO13\u3001GPIO18\u3001GPIO19\u652f\u6301\u786c\u4ef6\u65b9\u5f0f\u8f93\u51fa\u4fe1\u53f7\u3002<\/strong><\/em><\/p>\n<blockquote><p>PWM (pulse-width modulation)<\/p>\n<ul>\n<li>Software PWM available on all pins<\/li>\n<li>Hardware PWM available on GPIO12, GPIO13, GPIO18, GPIO19<\/li>\n<\/ul>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>I2C<\/h3>\n<p>&nbsp;<\/p>\n<p>I2C (<a class=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/I%C2%B2C\">Inter-Integrated Circuit<\/a>)\u662f\u4e00\u79cd\u7b80\u5355\u3001\u53cc\u5411\u4e8c\u7ebf\u5236\u540c\u6b65\u4e32\u884c\u603b\u7ebf\u3002\u5b83\u53ea\u9700\u8981\u4e24\u6839\u7ebf\u5373\u53ef\u5728\u8fde\u63a5\u4e8e\u603b\u7ebf\u4e0a\u7684\u5668\u4ef6\u4e4b\u95f4\u4f20\u9001\u4fe1\u606f\u3002\u4e3b\u8981\u7528\u6765\u548c\u4e00\u4e9b\u7b80\u5355\u7684\u5916\u8bbe\u8fdb\u884c\u5c0f\u6570\u636e\u7684\u4f20\u8f93\u3002\u4e00\u822c\u8fde\u63a5\u4e00\u4e9b\u4f20\u611f\u5668\u6216\u9a71\u52a8\u5668\uff0c\u6bd4\u5982\u901f\u5ea6\u4f20\u611f\u5668\u3001\u6e29\u5ea6\u4f20\u611f\u5668\u3001LCD\u663e\u793a\u5668\u6216\u7535\u52a8\u9a6c\u8fbe\u3002<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675131-4259-i2c-connections.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675131-4259-i2c-connections.png\" width=\"845\" height=\"327\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c5\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c5\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p><strong>I2C\u662f\u4e00\u4e2a\u540c\u6b65\u4e32\u884c\uff08synchronous\u00a0serial\u00a0\uff09\u63a5\u53e3<\/strong>\u3002\u4f7f\u75283\u6761\u603b\u7ebf\u8fdb\u884c\u8fde\u63a5\u3002\u5206\u4e3a\u4e3b\u4ece\u8bbe\u5907\uff0c\u4e3b\u4ece\u8bbe\u5907\u53ef\u4ee5\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<ul>\n<li>Shared clock signal (SCL)\uff1a \u56e0\u4e3aI2C\u662f\u4e32\u884c\u7684\uff0c\u6240\u4ee5\u9700\u8981SCL\u65f6\u949f\u603b\u7ebf\u53d1\u51fa\u4fe1\u53f7\u6765\u540c\u6b65\u4e3b\u4ece\u8bbe\u5907\u95f4\u7684\u6570\u636e\u4f20\u8f93\uff0c\u53d1\u51fa\u65f6\u949f\u4fe1\u53f7\u7684\u8bbe\u5907\u4e3aMaster\uff0c\u800c\u8fde\u63a5\u7684\u8bbe\u5907\u4e3aSlave\u3002<\/li>\n<li>Shared data line (SDA)\uff1a\u4e3b\u4ece\u8bbe\u5907\u95f4\u901a\u8fc7SDA\u603b\u7ebf\u8fdb\u884c\u6570\u636e\u4f20\u8f93\uff0c\u56e0\u4e3a\u53ea\u6709\u4e00\u6839\u6570\u636e\u7ebf\uff0c\u6240\u4ee5<strong>I2C\u63a5\u53e3\u662f\u534a\u53cc\u5de5<\/strong><\/li>\n<li>Common ground reference (GND) : \u63a5\u5730<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>I2C\u63a5\u53e3\u652f\u6301\u591a\u4e2a\u8bbe\u5907\u8fde\u63a5\u5728\u540c\u4e00\u4e2a\u603b\u7ebf\u4e0a\u3002\u6bcf\u4e2a\u8bbe\u5907\u90fd\u6709\u81ea\u5df1\u7684\u5730\u5740\uff0c\u4f46\u662f\u8fd9\u4e2a\u5730\u5740\u662f\u8f6f\u4ef6\u5b9e\u73b0\u7684\uff0c\u8fd9\u4e2a\u5730\u5740\u75287bit\u8868\u793a\uff0c\u6240\u4ee5\u7406\u8bba\u4e0aI2C\u6700\u591a\u53ef\u4ee5\u8fde\u63a5128\u4e2a\u8bbe\u5907\u3002\u800c\u56e0\u4e3a\u901a\u4fe1\u534f\u8bae\u4e2d\u5e26\u4e0a\u4e86\u8bbe\u5907\u5730\u5740\uff0c \u6240\u4ee5\u540c\u65f6\u53ea\u80fd\u548c\u4e00\u4e2a\u8bbe\u5907\u901a\u4fe1\uff0c\u8bbe\u5907\u53ea\u4f1a\u54cd\u5e94\u4f20\u9012\u7ed9\u81ea\u5df1\u5730\u5740\u7684\u6570\u636e\u3002I2C\u63a5\u53e3\u4f20\u8f93\u901f\u7387\u6709Master\u7684\u65f6\u949f\u9891\u7387\u51b3\u5b9a\u3002\u6811\u8393\u6d3e\u4e0a\u9ed8\u8ba4\u662f100KHZ\u3002\u8fd9\u4e2a\u9700\u8981\u6839\u636e\u5916\u8bbe\u6765\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u6811\u8393\u6d3e\u4e0a\u63d0\u4f9b\u4e862\u7ec4I2C\u63a5\u53e3\uff0c\u5206\u522b\u662fGPIO2\u3001GPIO3\u548cGPIO0\u3001GPIO1\u3002\u4f46\u662fGPIO0\u548cGPIO1\u662f\u4f5c\u4e3aEEPROM\uff0c\u8fd9\u4e2a\u4e3b\u8981\u662f\u7528\u6765\u5237\u4e3b\u677f\u4e0a\u7684ROM\uff0c\u6240\u4ee5\u4e0d\u7528\u6765\u548c\u5916\u8bbe\u8fdb\u884c\u901a\u4fe1\u3002<\/strong><\/p>\n<blockquote><p>I2C<\/p>\n<ul>\n<li>Data: (GPIO2); Clock (GPIO3)<\/li>\n<li>EEPROM Data: (GPIO0); EEPROM Clock (GPIO1)<\/li>\n<\/ul>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<h3>SPI<\/h3>\n<p>&nbsp;<\/p>\n<p>SPI\u662f\u4e32\u884c\u5916\u8bbe\u63a5\u53e3\uff08<a class=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Serial_Peripheral_Interface_Bus\">Serial Peripheral Interface<\/a>\uff09\u7684\u7f29\u5199\u3002\u662f\u4e00\u79cd\u9ad8\u901f\u7684\uff0c\u5168\u53cc\u5de5\uff0c\u540c\u6b65\u7684\u901a\u4fe1\u603b\u7ebf\u3002SPI\u6709\u6bd4\u8f83\u9ad8\u7684\u4f20\u8f93\u901f\u5ea6\uff0c\u6240\u4ee5\u9002\u5408\u7528\u770b\u6765\u8fdb\u884c\u5e26\u5bbd\u8981\u6c42\u6bd4\u8f83\u9ad8\u7684\u6570\u636e\u4f20\u8f93\uff0c\u6bd4\u5982\u56fe\u50cf\u7684\u4f20\u8f93\u3002\u5f88\u591a\u4f20\u611f\u5668\u90fd\u652f\u6301SPI\u548cI2C\u63a5\u53e3\u3002<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675131-7305-spi-connections.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675131-7305-spi-connections.png\" width=\"845\" height=\"387\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c6\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c6\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p><strong>SPI\u662f\u4e00\u4e2a\u540c\u6b65\u4e32\u884c\uff08synchronous\u00a0serial\u00a0\uff09\u63a5\u53e3<\/strong>\u3002\u4f7f\u75285\u6761\u603b\u7ebf\u8fdb\u884c\u8fde\u63a5\u3002\u5206\u4e3a\u4e3b\u4ece\u8bbe\u5907\uff0c\u4e3b\u4ece\u8bbe\u5907\u53ef\u4ee5\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<ul>\n<li>Master Out Slave In (MOSI)\u00a0 \u6570\u636e\u603b\u7ebf\uff0c\u7528\u4e8emaster\u5411slave\u53d1\u9001\u6570\u636e<\/li>\n<li>Master In Slave Out (MISO) \u6570\u636e\u603b\u7ebf\uff0c\u7528\u4e8emaster\u63a5\u6536slave\u53d1\u6765\u7684\u6570\u636e<\/li>\n<li>Shared clock signal (CLK) \u65f6\u949f\u603b\u7ebf\uff0c\u56e0\u4e3aSPI\u662f\u4e00\u4e2a\u540c\u6b65\u63a5\u53e3\uff0c\u6240\u4ee5\u4e5f\u9700\u8981\u65f6\u949f\u603b\u7ebf\u6765\u540c\u6b65\u4f20\u8f93<\/li>\n<li>Common ground reference (GND) \u63a5\u5730<\/li>\n<li>CS \u7247\u9009\u4fe1\u53f7\u7ebf\uff0c\u5982\u679c\u53ea\u6709\u4e00\u4e2a\u8bbe\u5907\u4e0d\u9700\u8981<\/li>\n<\/ul>\n<p>\u56e0\u4e3a<strong>SPI\u4f7f\u7528\u4e86\u4e24\u6761\u6570\u636e\u7ebf\u4f20\u8f93\u6570\u636e\uff0c\u6240\u4ee5\u662f\u5168\u53cc\u5de5\u6a21\u5f0f<\/strong>\u3002 SPI\u540c\u6837\u652f\u6301\u591a\u4e2a\u8bbe\u522b\u8fde\u63a5\uff0c\u4f46\u662f\u548cI2C\u4e0d\u540c\u7684\u662f\uff0cSPI Slave\u8bbe\u5907\u5730\u5740\u662f\u7528\u786c\u4ef6\u65b9\u5f0f\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u6bcf\u4e2a\u8bbe\u5907\u6709\u4e00\u4e2aCS\u603b\u7ebf\u548cMaster\u8bbe\u5907\u60f3\u4e86\u3002\u8fd9\u6837Master\u53ef\u4ee5\u540c\u65f6\u548c\u591a\u4e2aSlave\u8bbe\u5907\u8fdb\u884c\u901a\u4fe1\u3002 SPI\u7684\u4f20\u8f93\u719f\u8651\u4e5f\u662f\u7531Master\u662f\u65f6\u949f\u89e6\u53d1\u9891\u7387\u51b3\u5b9a\u7684\uff0c\u4e00\u822c\u4e3a16MHz \u5230 25MHz\uff0c \u76f8\u6bd4I2C\u8981\u5feb\u4e86\u5f88\u591a\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u6811\u8393\u6d3e\u63d0\u4f9b\u4e862\u7ec4SPI\u63a5\u53e3\uff0c\u5176\u4e2dSPI0\u63d0\u4f9b\u4e862\u4e2a\u7247\u9009\u63a5\u53e3\uff0cSPI1\u63d0\u4f9b\u4e863\u4e2a\u7247\u9009\u63a5\u53e3\uff0c\u6240\u4ee5\u6811\u8393\u6d3e\u6700\u591a\u5e94\u8be5\u53ef\u4ee5\u8fde\u63a55\u4e2aSPI\u8bbe\u5907<\/strong><\/p>\n<blockquote><p>SPI<\/p>\n<ul>\n<li>SPI0: MOSI (GPIO10); MISO (GPIO9); SCLK (GPIO11); CE0 (GPIO8), CE1 (GPIO7)<\/li>\n<li>SPI1: MOSI (GPIO20); MISO (GPIO19); SCLK (GPIO21); CE0 (GPIO18); CE1 (GPIO17); CE2 (GPIO16)<\/li>\n<\/ul>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<h3 class=\"devsite-page-title\">UART<\/h3>\n<p>&nbsp;<\/p>\n<p>\u901a\u7528\u5f02\u6b65\u6536\u53d1\u4f20\u8f93\u5668\uff08\u00a0<a class=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Universal_asynchronous_receiver\/transmitter\">Universal Asynchronous Receiver Transmitter<\/a>)\uff0c \u4e00\u822c\u4e5f\u7b80\u79f0\u4e3a\u4e32\u53e3\uff08<strong><em>serial ports<\/em><\/strong>\uff09\u3002\u6211\u4eec\u5728\u4f7f\u7528\u7535\u8111\u65f6\u4e5f\u7ecf\u5e38\u901a\u8bf4\u4e32\u53e3\uff0c\u6bd4\u5982\u8001\u7684COM\u53e3\u3001\u73b0\u5728\u7684USB\u53e3\u3002\u6240\u4ee5\u5927\u5bb6\u8bf4\u4e32\u53e3\u4e00\u822c\u662f\u4e00\u4e2a\u603b\u79f0\uff0c\u800c\u5355\u7247\u673a\u4e0a\u4e00\u822c\u4e66\u4e32\u53e3\u6307\u7684\u662fUART\uff0c\u5b83\u4f7f\u7528TTL\u7535\u5e73\uff082.6V-5V\u4e3a1\uff0c0\u4e3a0-0.4V\uff09\uff0c\u800c\u7535\u8111\u4e0a\u7684COM\u53e3\u4f7f\u7528RS232\u7535\u5e73 (\u903b\u8f911=-3V\uff5e-15V\u903b\u8f910=+3\uff5e+15V) \u3002<a href=\"https:\/\/wenku.baidu.com\/view\/a5df03bb856a561253d36f4e.html\"><span id=\"doc-tittle-0\">\u4e32<wbr \/>\u53e3<wbr \/>\u3001<wbr \/>C<wbr \/>O<wbr \/>M<wbr \/>\u53e3<wbr \/>\u3001<wbr \/>T<wbr \/>T<wbr \/>L<wbr \/>\u3001<wbr \/>R<wbr \/>S<wbr \/>\u2013<wbr \/>2<wbr \/>3<wbr \/>2<wbr \/>\u3001<wbr \/>R<wbr \/>S<wbr \/>\u2013<wbr \/>4<wbr \/>8<wbr \/>5<wbr \/>\u533a<wbr \/>\u522b<wbr \/>\u8be6<wbr \/>\u89e3<\/span><\/a><\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675132-4703-uart-connections.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675132-4703-uart-connections.png\" width=\"807\" height=\"140\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c7\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c7\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p>UART\u63a5\u53e3\u662f\u5f02\u6b65\u63a5\u53e3\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u65f6\u949f\u603b\u7ebf\u3002\u8bbe\u5907\u4e4b\u95f4\u7684\u4f20\u8f93\u901f\u7387\u662f\u53ef\u4ee5\u534f\u5546\u7684\uff0c\u6240\u4ee5\u662f\u901a\u7528\u63a5\u53e3\u3002 \u8bbe\u5907\u76f4\u63a5\u901a\u8fc7RX\u548cTX\u4e24\u4e2a\u6570\u636e\u603b\u7ebf\u8fde\u63a5\uff0c\u6240\u4ee5\u662f\u5168\u53cc\u5de5\u6a21\u5f0f\u3002UART\u63a5\u6536\u5230\u7684\u6570\u636e\u4f1a\u653e\u5230\u4e00\u4e2aFIFO\u961f\u5217\u4e2d\uff0c\u76f4\u5230\u8bbe\u5907\u8bfb\u53d6\u3002UART\u652f\u63013\u7ebf\u548c5\u7ebf\u4e24\u79cd\u8fde\u63a5\u65b9\u5f0f\uff1a<\/p>\n<blockquote>\n<ul>\n<li>3-Wire ports include data receive (RX), data transmit (TX), and ground reference (GND) signals.<\/li>\n<li>5-Wire ports add request to send (RTS) and clear to send (CTS) signals used for\u00a0<strong><em>hardware flow control<\/em><\/strong>. Flow control allows the receiving device to indicate that its FIFO buffer is temporarily full and the transmitting device should wait before sending any more data.<\/li>\n<\/ul>\n<\/blockquote>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675133-8615-uart-flow-control.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675133-8615-uart-flow-control.png\" width=\"787\" height=\"180\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c8\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c8\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p>5\u7ebf\u76f8\u6bd43\u7ebf\u591a\u4e86RTS\u548cCTS\u4e24\u6761\u63a7\u5236\u603b\u7ebf\u3002\u4f5c\u7528\u5c31\u662f\u5f53FIFO\u961f\u5217\u6ee1\u4e86\u7684\u65f6\u5019\u901a\u77e5\u8bbe\u5907\u6682\u65f6\u4e0d\u8981\u4f20\u9012\u6570\u636e\u3002\u548cI2C\u4ee5\u53caSPI\u4e0d\u540c\u7684\u662f\uff0cUART\u662f\u70b9\u5bf9\u70b9\u901a\u4fe1\u3002\u901f\u5ea6\u6bd4I2C\u5757\uff0c\u4f46\u662f\u53ef\u80fd\u8981\u6bd4SPI\u6162\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u6811\u8393\u6d3e\u5728GPIO14\u548cGPIO15 \u63a5\u53e3\u63d0\u4f9b\u4e86UART\u529f\u80fd\uff0c\u4f46\u662f\u6ca1\u6709\u63d0\u4f9bRTS\u548cCTS\u603b\u7ebf\uff0c\u6240\u4ee5\u53ea\u80fd\u4ee53\u7ebf\u7684\u65b9\u5f0f\u8fde\u63a5\u3002<\/strong><\/p>\n<blockquote>\n<ul>\n<li>Serial\n<ul>\n<li>TX (GPIO14); RX (GPIO15)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<h3>\u5c0f\u7ed3<\/h3>\n<p>&nbsp;<\/p>\n<p>\u4e4b\u524d\u5bf9GPIO\u7684\u7406\u89e3\u6709\u70b9\u504f\u5dee\uff0c\u8ba4\u4e3a\u666e\u901aGPIO\u53e3\u53ea\u80fd\u53d1\u90010\uff0c1\u4f5c\u4e3a\u5f00\u5173\uff0c\u800c\u5176\u4ed6I2C,SPI\u7b49\u63a5\u53e3\u53ef\u4ee5\u53d1\u9001\u8d1f\u8d23\u7684\u6570\u636e\u3002 \u540e\u6765\u53d1\u73b0\u4e00\u4e9b\u5916\u8bbe\u5c31\u662f\u901a\u8fc7\u666e\u901aGPIO\u53e3\u6765\u8fdb\u884c\u4e86\u5355\u603b\u7ebf\u901a\u4fe1\u3002 \u6240\u4ee5GPIO\u786e\u5b9e\u53ea\u80fd\u4ea7\u751f\u9ad8\u4f4e\u7535\u5e73\uff0c\u4f46\u662f\u5982\u679c\u8fde\u7eed\u4ea7\u751f\uff0c\u5c31\u53ef\u4ee5\u8fde\u7eed\u7684\u53d1\u9001\u6570\u636e\u7ed9\u8bbe\u5907\u3002 \u800cI2C, SPI\u8fd9\u4e9b\u603b\u7ebf\u672c\u8d28\u4e5f\u90fd\u662f\u53d1\u9001\u7535\u5e73\uff0c\u4e0d\u540c\u7684\u662f\u4ed6\u4eec\u662f\u6309\u6307\u5b9a\u7684\u534f\u8bae\u65b9\u5f0f\u53d1\u9001\u3002 \u800c\u5b9e\u9645\u5916\u8bbe\u4e2d\u6709\u5f88\u591a\u662f\u81ea\u5b9a\u4e49\u534f\u8bae\uff0c\u6240\u4ee5\u7406\u8bba\u4e0a\u65e0\u8bba\u662f\u81ea\u5b9a\u4e49\u534f\u8bae\uff0c\u8fd8\u662f\u6807\u51c6\u7684I2C,SPI\u8fd9\u4e9b\u534f\u8bae\uff0c\u90fd\u662f\u53ef\u4ee5\u7528\u4efb\u610f\u7684GPIO\u53e3\u6765\u901a\u4fe1\u7684\u3002<\/p>\n<p>\u53ea\u662fPI\u4e0a\u5b9a\u4e49\u4e86I2C, SPI\u8fd9\u6837\u7684\u63a5\u53e3\uff0c\u5982\u679c\u4e0d\u4f7f\u7528\u8fd9\u4e9b\u63a5\u53e3\uff0c\u800c\u7528\u666e\u901aGPIO\u63a5\u53e3\u5c31\u9700\u8981\u81ea\u5df1\u6765\u5b9e\u73b0\u8fd9\u4e2a\u534f\u8bae\uff0c\u800c\u4e0d\u80fd\u4f7f\u7528\u5df2\u6709\u7684I2C,SPI\u7684\u5e93\u6765\u901a\u4fe1\u3002\u5bf9\u4e8e\u81ea\u5b9a\u4e49\u534f\u8bae\u4e5f\u662f\u4e00\u6837\u3002\u5176\u5b9e\u8bbe\u5907\u7684\u9488\u811a\u662f\u53ef\u4ee5\u4efb\u610fGPIO\u7684\u3001\u53ea\u662f\u5982\u679c\u4f7f\u7528\u4e86\u5df2\u6709\u7684\u5e93\u6587\u4ef6\uff0c\u9700\u8981\u4fee\u6539\u5bf9\u5e94\u7684\u9488\u811a\u8bbe\u7f6e\u3002\u6240\u4ee5GPIO\u529f\u80fd\u662f\u975e\u5e38\u5f3a\u5927\u7684\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528GPIO\u6765\u548c\u4efb\u610f\u534f\u8bae\u7684\u8bbe\u5907\u901a\u4fe1\uff0c\u53ef\u4ee5\u7528GPIO\u6765\u6a21\u62dfUSB\u901a\u4fe1\uff0c\u8bbe\u7f6e\u4f60\u53ef\u4ee5\u6a21\u62df\u786c\u76d8IDE\u63a5\u53e3\u548c\u786c\u76d8\u901a\u4fe1\u3002\u5f53\u7136\u5728\u901f\u5ea6\u4e0a\u53ef\u80fd\u4f1a\u6709\u9650\u5236\u3002<\/p>\n<h2>\u7f16\u7a0b\u9488\u811a<\/h2>\n<p>&nbsp;<\/p>\n<p>\u4f7f\u7528\u4e0d\u540c\u7684\u5e93\u5728\u7f16\u7a0b\u65f6\u5019\u5bf9\u5e94\u7684\u9488\u811a\u7684\u7f16\u53f7\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u6240\u4ee5\u8981\u6839\u636e\u5e93\u6765\u8bbe\u7f6e\u9488\u811a\u7684\u7f16\u53f7\u3002\u7f51\u4e0a\u7684\u56fe\u611f\u89c9\u6807\u6ce8\u7684\u90fd\u4e0d\u662f\u5f88\u6e05\u695a\uff0c\u6240\u4ee5\u81ea\u5df1\u91cd\u65b0\u753b\u4e86\u4e00\u4e2a<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675137-2074-gpio.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1570675137-2074-gpio.png\" width=\"1238\" height=\"1303\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c9\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c9\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><\/h3>\n<h3>1.2 GPIO\u63a5\u53e3<\/h3>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411835-5810-20180703112153400-2046480266.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411835-5810-20180703112153400-2046480266.png\" width=\"505\" height=\"464\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c10\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c10\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<h3>1.3 \u63a5\u7ebf<\/h3>\n<p>\u9996\u5148\u6211\u4eec\u628aLED\u548c\u6811\u8393\u6d3e\u8fde\u63a5\u3002LED\u7684\u6b63\u6781\u4e32\u8054\u4e00\u4e2a1K\u03a9\u7535\u963b\u63a5\u6811\u8393\u6d3e\u7684GPIO18(pin12)\uff0c\u8d1f\u6781\u63a5\u5730\u3002\uff08\u6ce8\u610f\uff0c\u4e0b\u9762\u501f\u7528\u4e86\u522b\u4eba\u4e00\u5f20\u56fe\uff0c\u56fe\u4e2dLED\u6b63\u6781\u63a5\u5728pin11\u4e0a\uff0c\u6211\u4eec\u662f\u63a5\u5728pin12\u4e0a\uff09<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411832-6857-20180703112224679-101447640.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411832-6857-20180703112224679-101447640.png\" width=\"418\" height=\"250\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c11\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c11\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<h2>2.\u00a0 \u6d4b\u8bd5<\/h2>\n<h3>2.1 \u8fde\u63a5\u7535\u8111\u548cPi Zero W<\/h3>\n<p>\u7528putty\u8fde\u63a5\u7535\u8111\u548cPi Zero W\uff0c\u770b\u672c\u6587\u6700\u540e\u7684\u53c2\u8003\u6587\u6863\u3002Host Name\u586braspberrypi.local\uff0c\u7aef\u53e322\uff0c\u7528\u6237\u540dpi\uff0c\u5bc6\u7801raspberry\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1aboot<\/strong><strong>\u5206\u533a\u6709\u4e00\u4e2a\u540d\u4e3assh<\/strong><strong>\u7684\u7a7a\u6587\u672c\u6587\u4ef6\uff0c\u8fd9\u4e2assh<\/strong><strong>\u6587\u4ef6\u5bb9\u6613\u4e22\u5931\uff0c\u5982\u679cssh<\/strong><strong>\u4e0d\u80fd\u767b\u5f55\u4e86\uff0c\u5148\u68c0\u67e5ssh<\/strong><strong>\u662f\u5426\u4e22\u5931\u3002<\/strong><\/p>\n<h3>2.2 \u7528Shell\u547d\u4ee4\u76f4\u63a5\u63a7\u5236GPIO<\/h3>\n<ul>\n<li>\u4f7fGPIO18\u4ece\u5185\u6838\u7a7a\u95f4\u66b4\u9732\u5230\u7528\u6237\u7a7a\u95f4\u4e2d<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo echo 18 &gt; \/sys\/class\/gpio\/export<\/p>\n<p>&gt; \u662fIO\u91cd\u5b9a\u5411\u7b26\u53f7\uff0cIO\u91cd\u5b9a\u5411\u662f\u6307\u6539\u53d8linux\u6807\u51c6\u8f93\u5165\u548c\u8f93\u51fa\u7684\u9ed8\u8ba4\u8bbe\u5907\uff0c\u6307\u5411\u4e00\u4e2a\u7528\u6237\u5b9a\u4e49\u7684\u8bbe\u5907\u3002echo 18 &gt; export\u5c31\u662f\u628a18\u5199\u5165\u5230export\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u6267\u884c\u8be5\u64cd\u4f5c\u4e4b\u540e\uff0c\/sys\/class\/gpio\u76ee\u5f55\u4e0b\u4f1a\u589e\u52a0\u4e00\u4e2agpio18\u6587\u4ef6\u5939\u3002<\/p>\n<ul>\n<li>\u67e5\u770bGPIO18\u5f15\u811a\uff08\u5728Liunx\u4e2d\u8bbe\u5907\u90fd\u4ee5\u6587\u4ef6\u7684\u5f62\u5f0f\uff0c\u5f15\u811a\u4e5f\u662f\u8bbe\u5907\uff09<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ cd \/sys\/class\/gpio\/gpio18<\/p>\n<p>pi@raspberrypi:\/sys\/class\/gpio\/gpio18 $ ls<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411876-6143-20180703112454707-1335363228.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411876-6143-20180703112454707-1335363228.png\" width=\"550\" height=\"36\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c12\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c12\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<ul>\n<li>\u8bbe\u7f6eGPIO18\u4e3a\u8f93\u51fa\u6a21\u5f0f<\/li>\n<\/ul>\n<p>pi@raspberrypi:\/sys\/class\/gpio\/gpio18 $ sudo echo out &gt; direction<\/p>\n<ul>\n<li>\u5411value\u6587\u4ef6\u4e2d\u8f93\u51651\uff0cGPIO\u8f93\u51fa\u9ad8\u7535\u5e73\uff0cLED\u70b9\u4eae<\/li>\n<\/ul>\n<p>pi@raspberrypi:\/sys\/class\/gpio\/gpio18 $ sudo echo 1 &gt; value<\/p>\n<ul>\n<li>\u5411value\u6587\u4ef6\u4e2d\u8f93\u51650\uff0cGPIO\u8f93\u51fa\u4f4e\u7535\u5e73\uff0cLED\u7184\u706d<\/li>\n<\/ul>\n<p>pi@raspberrypi:\/sys\/class\/gpio\/gpio18 $ sudo echo 0 &gt; value<\/p>\n<ul>\n<li>\u8fd4\u56de\u5bb6\u76ee\u5f55<\/li>\n<\/ul>\n<p>pi@raspberrypi:\/sys\/class\/gpio $ cd ~<\/p>\n<ul>\n<li>\u6ce8\u9500GPIO18\u63a5\u53e3<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo echo 18 &gt; \/sys\/class\/gpio\/unexport<\/p>\n<p>&nbsp;<\/p>\n<h3>2.3 \u7528Shell\u811a\u672c\u63a7\u5236GPIO<\/h3>\n<ul>\n<li>\u65b0\u5efa\u4e00\u4e2a\u540d\u4e3aledonoff.sh\u7684\u811a\u672c\u3002<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo nano ledonoff.sh<\/p>\n<p>\u811a\u672c\u5199\u4e0b\u9762\u7684\u5185\u5bb9\uff1a<\/p>\n<p>echo $1 &gt; \/sys\/class\/gpio\/export<\/p>\n<p>echo out &gt; \/sys\/class\/gpio\/gpio$1\/direction<\/p>\n<p>echo 1 &gt; \/sys\/class\/gpio\/gpio$1\/value<\/p>\n<p>sleep\u00a05\u00a0\u00a0 #\u5ef6\u65f65\u79d2<\/p>\n<p>echo 0 &gt; \/sys\/class\/gpio\/gpio$1\/value<\/p>\n<p>echo $1 &gt; \/sys\/class\/gpio\/unexport<\/p>\n<p>\u8bf4\u660e\uff1ashell\u811a\u672c\u53ef\u4f20\u5165\u53c2\u6570\uff0c\u4f8b\u5982$1\u4ee3\u8868\u7b2c1\u4e2a\u53c2\u6570\uff0c$2\u4ee3\u8868\u7b2c2\u4e2a\u53c2\u6570\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002<\/p>\n<ul>\n<li>\u4e3aledonoff.sh\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo chmod +x ledonoff.sh<\/p>\n<ul>\n<li>\u8fd0\u884c\u811a\u672c<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo .\/ledonoff.sh 18<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1aLED\u70b9\u4eae\uff0c\u6301\u7eed5\u79d2\u949f\u5173\u95ed\u3002<\/p>\n<h3>2.4 \u7528Python\u901a\u8fc7PRI.GPIO\u547d\u4ee4\u63a7\u5236GPIO<\/h3>\n<p>\u7528Python\u63a7\u5236GPIO\uff0c\u6700\u4fbf\u6377\u7684\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528python\u7c7b\u5e93\uff0c\u6bd4\u5982\u6811\u8393\u6d3e\u7cfb\u7edf\u672c\u8eab\u96c6\u6210\u7684RPi.GPIO\u3002<\/p>\n<p>\u5728putty\u7684ssh\u7ec8\u7aef\u8f93\u5165\u547d\u4ee4\uff1a<\/p>\n<ul>\n<li>\u8fdb\u5165python\u4ea4\u4e92\u754c\u9762<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ python<\/p>\n<p>&gt;&gt;&gt; \u8fd9\u662fpython\u7684\u63d0\u793a\u7b26\u3002<\/p>\n<ul>\n<li>\u5bfc\u5165python\u7c7b\u5e93RPi.GPIO\uff0c\u547d\u540d\u4e3a\u522b\u540d\u4e3aGPIO<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; import RPi.GPIO as GPIO<\/p>\n<p>\u5f15\u5165\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 GPIO \u6a21\u5757\u7684\u51fd\u6570\u4e86\u3002<\/p>\n<ul>\n<li>\u8bbe\u7f6eBOARD\u7f16\u7801\u65b9\u5f0f\uff0c\u57fa\u4e8eBCM<\/li>\n<\/ul>\n<p>\u6811\u8393\u6d3e3 GPIO\u5206\u4e3a\u5982\u4e0b\u7684\u4e09\u79cd\u7f16\u7801\u65b9\u5f0f\uff1a\u7269\u7406\u5f15\u811aBOARD\u7f16\u7801\uff0cBCM\u7f16\u7801\uff0c\u4ee5\u53ca wiringPi \u7f16\u7801\u3002<\/p>\n<p>&gt;&gt;&gt; GPIO.setmode(GPIO.BCM)<\/p>\n<ul>\n<li>\u8f93\u51fa\u6a21\u5f0f<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; GPIO.setup(18,GPIO.OUT)<\/p>\n<ul>\n<li>GPIO18\u8f93\u51fa\u9ad8\u7535\u5e73\uff0cLED\u70b9\u4eae<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; GPIO.output(18,GPIO.HIGH)<\/p>\n<ul>\n<li>GPIO18\u8f93\u51fa\u4f4e\u7535\u5e73\uff0cLED\u7184\u706d<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; GPIO.output(18,GPIO.LOW)<\/p>\n<ul>\n<li>\u7528\u5b8c\u540e\u8fdb\u884c\u6e05\u7406<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; GPIO.cleanup()<\/p>\n<ul>\n<li>\u9000\u51fapython\u4ea4\u4e92\u754c\u9762<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; Ctrl+D<\/p>\n<h3>2.5 \u7528Python\u811a\u672c\u63a7\u5236GPIO<\/h3>\n<ul>\n<li>\u65b0\u5efa\u4e00\u4e2a\u540d\u4e3ablinky.py\u7684\u811a\u672c\u3002<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo nano blinky.py<\/p>\n<p>\u811a\u672c\u5199\u4e0b\u9762\u7684\u5185\u5bb9\uff1a<\/p>\n<p>import RPi.GPIO as GPIO<\/p>\n<p>import time<\/p>\n<p>GPIO.setmode(GPIO.BCM)<\/p>\n<p>GPIO.setup(18,GPIO.OUT)<\/p>\n<p>while True:<\/p>\n<p>GPIO.output(18,GPIO.HIGH)<\/p>\n<p>time.sleep(1)<\/p>\n<p>GPIO.output(18,GPIO.LOW)<\/p>\n<p>time.sleep(1)<\/p>\n<p>&nbsp;<\/p>\n<p>GPIO.cleanup()<\/p>\n<p>\u8bf4\u660e\uff1awhile True\u4e0b\u9762\u7684\u5faa\u73af\u4f53\u8981\u7f29\u8fdb\uff0c\u7528\u7a7a\u683c\u6216Tab\uff08\u4f46\u4e0d\u80fd\u6df7\u7528\uff09\u952e\u7f29\u8fdb\u5c31\u884c\u3002<\/p>\n<ul>\n<li>\u4e3ablinky.py\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo chmod +x blinky.py<\/p>\n<ul>\n<li>\u8fd0\u884cPython\u811a\u672c<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo python blinky.py<\/p>\n<p>LED\u95ea\u70c1\u3002<\/p>\n<ul>\n<li>\u505c\u6b62\u8fd0\u884c<\/li>\n<\/ul>\n<p>\u7528 Ctrl+C \u6765\u4e2d\u65ad\u5faa\u73af\u3002<\/p>\n<h2>3. \u501f\u52a9wiringPi GPIO\u7528C\u8bed\u8a00\u63a7\u5236GPIO<\/h2>\n<p>\u6811\u8393\u6d3e\u5185\u6838\u4e2d\u5df2\u7ecf\u7f16\u8bd1\u81ea\u5e26\u4e86gpio\u7684\u9a71\u52a8\uff0c\u6211\u4eec\u5e38\u901a\u8fc7\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5199\u597d\u7684\u5e93\u51fd\u6570\u6765\u5b8c\u6210\u5177\u4f53\u7684\u64cd\u4f5c\uff0c\u6bd4\u8f83\u5e38\u89c1\u7684\u64cd\u4f5c\u5e93\u51fd\u6570\u6709\uff1a<\/p>\n<ul>\n<li>Python GPIO<\/li>\n<\/ul>\n<p>Python GPIO\u5df2\u7ecf\u96c6\u6210\u5230\u4e86\u6811\u8393\u6d3e\u5185\u6838\uff0c\u4e3a\u6811\u8393\u6d3e\u5b98\u65b9\u8d44\u6599\u4e2d\u63a8\u8350\u4e14\u5bb9\u6613\u4e0a\u624b\u3002python GPIO\u662f\u4e00\u4e2a\u5c0f\u578b\u7684python\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5b8c\u6210raspberry\u76f8\u5173IO\u53e3\u64cd\u4f5c\uff0c\u4f46\u662fpython GPIO\u5e93\u8fd8\u6ca1\u6709\u652f\u6301SPI\u3001I2C\u6216\u80051-wire\u7b49\u603b\u7ebf\u63a5\u53e3\u3002<\/p>\n<p>\u5e38\u89c1C\u8bed\u8a00\u5e93\u6709\uff1a<\/p>\n<ul>\n<li>wiringPi (http:\/\/wiringpi.com\/)<\/li>\n<\/ul>\n<p>wiringPi\u9002\u5408\u90a3\u4e9b\u5177\u6709C\u8bed\u8a00\u57fa\u7840\uff0c\u5728\u63a5\u89e6\u6811\u8393\u6d3e\u4e4b\u524d\u5df2\u7ecf\u63a5\u89e6\u8fc7\u5355\u7247\u673a\u6216\u8005\u5d4c\u5165\u5f0f\u5f00\u53d1\u7684\u4eba\u7fa4\u3002wiringPi\u7684API\u51fd\u6570\u548carduino\u975e\u5e38\u76f8\u4f3c\uff0c\u8fd9\u4e5f\u4f7f\u5f97\u5b83\u5e7f\u53d7\u6b22\u8fce\u3002\u4f5c\u8005\u7ed9\u51fa\u4e86\u5927\u91cf\u7684\u8bf4\u660e\u548c\u793a\u4f8b\u4ee3\u7801\uff0c\u8fd9\u4e9b\u793a\u4f8b\u4ee3\u7801\u4e5f\u5305\u62ecUART\u8bbe\u5907\uff0cI2C\u8bbe\u5907\u548cSPI\u8bbe\u5907\u7b49\u3002<\/p>\n<ul>\n<li>BCM2835 C Library (http:\/\/www.airspayce.com\/mikem\/bcm2835\/)<\/li>\n<\/ul>\n<p>BCM2835 C Library\u53ef\u4ee5\u7406\u89e3\u4e3a\u4f7f\u7528C\u8bed\u8a00\u5b9e\u73b0\u7684\u76f8\u5173\u5e95\u5c42\u9a71\u52a8\uff0cBCM2835 C Library\u7684\u9a71\u52a8\u5e93\u5305\u62ecGPIO. SPI\u548cUART\u7b49\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b66\u4e60BCM2835 C Library\u719f\u6089BCM2835\u76f8\u5173\u7684\u5bc4\u5b58\u5668\u64cd\u4f5c\u3002\u5982\u679c\u6709\u673a\u4f1a\u5f00\u53d1\u6811\u8393\u6d3e\u4e0a\u7684linux\u9a71\u52a8\uff0c\u6216\u81ea\u4e3b\u5f00\u53d1python\u6216PHP\u6269\u5c55\u9a71\u52a8\uff0c\u53ef\u4ee5\u4eceBCM2835 C Library\u627e\u5230\u4e0d\u5c11\u7684\u201c\u7075\u611f\u201d\u3002<\/p>\n<h3>3.1 WiringPi GPIO\u5b89\u88c5<\/h3>\n<p>WiringPi\u662f\u5e94\u7528\u4e8e\u6811\u8393\u6d3e\u5e73\u53f0\u7684GPIO\u63a7\u5236\u5e93\u51fd\u6570\uff0cWiringPi\u9075\u5b88GUN Lv3\u3002wiringPi\u4f7f\u7528C\u6216\u8005C++\u5f00\u53d1\u5e76\u4e14\u53ef\u4ee5\u88ab\u5176\u4ed6\u8bed\u8a00\u5305\u8f6c\uff0c\u4f8b\u5982python\u3001ruby\u6216\u8005PHP\u7b49\u3002<\/p>\n<p>wiringPi\u5305\u62ec\u4e00\u5957gpio\u63a7\u5236\u547d\u4ee4\uff0c\u4f7f\u7528gpio\u547d\u4ee4\u53ef\u4ee5\u63a7\u5236\u6811\u8393\u6d3eGPIO\u7ba1\u811a\u3002\u7528\u6237\u53ef\u4ee5\u5229\u7528gpio\u547d\u4ee4\u901a\u8fc7shell\u811a\u672c\u63a7\u5236\u6216\u67e5\u8be2GPIO\u7ba1\u811a\u3002<\/p>\n<ul>\n<li>wiringPi\u5b89\u88c5<\/li>\n<\/ul>\n<p>\u66f4\u65b0\u5217\u8868\uff1a<\/p>\n<p>pi@raspberrypi:~ $ sudo apt-get update<\/p>\n<p>\u66f4\u65b0\u8f6f\u4ef6\uff1a<\/p>\n<p>pi@raspberrypi:~ $ sudo apt-get upgrade<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<p>pi@raspberrypi:~ $ sudo apt-get install wiringpi<\/p>\n<ul>\n<li>\u6d4b\u8bd5<\/li>\n<\/ul>\n<p>wiringPi\u5305\u62ec\u4e00\u5957gpio\u547d\u4ee4\uff0c\u4f7f\u7528gpio\u547d\u4ee4\u53ef\u4ee5\u63a7\u5236\u6811\u8393\u6d3e\u4e0a\u7684\u5404\u79cd\u63a5\u53e3\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6307\u4ee4\u53ef\u4ee5\u6d4b\u8bd5wiringPi\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<p>pi@raspberrypi:~ $ gpio -v<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411866-6040-20180703113211110-1063038922.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411866-6040-20180703113211110-1063038922.png\" width=\"485\" height=\"183\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c13\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c13\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<ul>\n<li>\u67e5\u770bGPIO\u56fe<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ gpio readall<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411861-1283-20180703113240409-1897450357.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411861-1283-20180703113240409-1897450357.png\" width=\"558\" height=\"375\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c14\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c14\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<h3>3.2 \u7f16\u5199\u4ee3\u7801<\/h3>\n<ul>\n<li>\u65b0\u5efa\u4e00\u4e2a\u540d\u4e3aled_blink.c\u7684\u6e90\u7a0b\u5e8f<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo nano led_blink.c<\/p>\n<ul>\n<li>\u5185\u5bb9\u5982\u4e0b<\/li>\n<\/ul>\n<p>#include &lt;wiringPi.h&gt;<\/p>\n<p>int main(void) {<\/p>\n<p>wiringPiSetup();<\/p>\n<p>pinMode (1, OUTPUT);<\/p>\n<p>for(;;) {<\/p>\n<p>digitalWrite(1, HIGH);delay (500);<\/p>\n<p>digitalWrite(1, LOW);delay (500) ;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u8bf4\u660e\uff1a\u770b\u770b\u4e0a\u4e00\u5c0f\u8282\u7684\u56fe\uff0cBCM\u7f16\u53f7\u7684GPIO18\u5f15\u811a\u5728wiringPi\u7f16\u53f7\u4e2d\u662f1\u3002<\/p>\n<h3>3.3 \u7f16\u8bd1\u8fd0\u884c<\/h3>\n<ul>\n<li>\u7f16\u8bd1<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ gcc led_blink.c -o led_blink -l wiringPi<\/p>\n<p>-l wiringPi\u8868\u793a\u52a8\u6001\u52a0\u8f7dwiringPi\u5171\u4eab\u5e93\u3002<\/p>\n<ul>\n<li>\u8fd0\u884c<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ sudo .\/led_blink<\/p>\n<p>\u7528 Ctrl+C \u6765\u4e2d\u65ad\u5faa\u73af\u3002<\/p>\n<h2>4.\u00a0 \u501f\u52a9BCM2835 C Library\u7528C\u8bed\u8a00\u63a7\u5236GPIO<\/h2>\n<h3>4.1 \u4e0b\u8f7d\u5b89\u88c5<\/h3>\n<p>\u5148\u770b\u770b\u6700\u65b0\u7248\u672c\uff1ahttp:\/\/www.airspayce.com\/mikem\/bcm2835<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411870-5535-20180703113408106-567821135.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2019\/09\/1567411870-5535-20180703113408106-567821135.png\" width=\"558\" height=\"162\" alt=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c15\u5f20\" title=\"\u6811\u8393\u6d3eZero W GPIO\u63a7\u5236 \u6811\u8393\u6d3e \u7b2c15\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<ul>\n<li>\u4e0b\u8f7dbcm2835-1.56.tar.gz<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ wget http:\/\/www.airspayce.com\/mikem\/bcm2835\/bcm2835-1.56.tar.gz<\/p>\n<ul>\n<li>\u89e3\u538b\u7f29<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ tar xvzf bcm2835-1.56.tar.gz<\/p>\n<ul>\n<li>\u914d\u7f6e\u7f16\u8bd1<\/li>\n<\/ul>\n<p>\u8fdb\u5165\u538b\u7f29\u4e4b\u540e\u7684\u76ee\u5f55:<\/p>\n<p>pi@raspberrypi:~ $ cd bcm2835-1.56<\/p>\n<p>\u6267\u884c\u914d\u7f6e\u547d\u4ee4\uff1a<\/p>\n<p>pi@raspberrypi:~\/bcm2835-1.56 $ .\/configure<\/p>\n<p>pi@raspberrypi:~\/bcm2835-1.56 $ make<\/p>\n<ul>\n<li>\u6267\u884c\u68c0\u67e5<\/li>\n<\/ul>\n<p>pi@raspberrypi:~\/bcm2835-1.56 $ sudo make check<\/p>\n<ul>\n<li>\u5b89\u88c5bcm2835\u5e93:<\/li>\n<\/ul>\n<p>pi@raspberrypi:~\/bcm2835-1.56 $ sudo make install<\/p>\n<h3>4.2 \u7f16\u5199\u4ee3\u7801<\/h3>\n<ul>\n<li>\u65b0\u5efa\u4e00\u4e2a\u540d\u4e3ablink_led.c\u7684\u6e90\u7a0b\u5e8f<\/li>\n<\/ul>\n<p>pi@raspberrypi:~\/bcm2835-1.56 $ cd ~<\/p>\n<p>pi@raspberrypi:~ $ sudo nano blink_led.c<\/p>\n<ul>\n<li>\u5185\u5bb9\u5982\u4e0b<\/li>\n<\/ul>\n<p>#include &lt;bcm2835.h&gt;<\/p>\n<p>#define PIN RPI_GPIO_P1_12<\/p>\n<p>int main(int argc, char **argv) {<\/p>\n<p>if (!bcm2835_init())<\/p>\n<p>return 1;<\/p>\n<p>&nbsp;<\/p>\n<p>bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);<\/p>\n<p>&nbsp;<\/p>\n<p>while (1) {<\/p>\n<p>bcm2835_gpio_write(PIN, HIGH);<\/p>\n<p>bcm2835_delay(500);<\/p>\n<p>bcm2835_gpio_write(PIN, LOW);<\/p>\n<p>bcm2835_delay(500);<\/p>\n<p>}<\/p>\n<p>bcm2835_close();<\/p>\n<p>return 0;<\/p>\n<p>}<\/p>\n<p>\u8bf4\u660e\uff1aGPIO\u7684\u7f16\u53f7\u65b9\u5f0f\u4e0d\u540c\uff0c\u91c7\u7528PCB\u677f\u7684\u7269\u7406\u63a5\u53e3\u7f16\u53f7\uff0cled\u8fde\u5728\u6811\u8393\u6d3eZero W\u677f\u5b50\u768412\u5f15\u811a\u4e0a\u3002<\/p>\n<h3>4.3 \u7f16\u8bd1\u8fd0\u884c<\/h3>\n<ul>\n<li>\u7f16\u8bd1<\/li>\n<\/ul>\n<p>pi@raspberrypi:~ $ gcc blink_led.c -o blink_led -l bcm2835<\/p>\n<p>-l bcm2835\u8868\u793a\u52a8\u6001\u52a0\u8f7dbcm2835\u5171\u4eab\u5e93<\/p>\n<ul>\n<li>\u8fd0\u884c<\/li>\n<\/ul>\n<p>sudo .\/blink_led<\/p>\n<p>\u7528 Ctrl+C \u6765\u4e2d\u65ad\u5faa\u73af\u3002<\/p>\n<h2>\u00a0\u53c2\u8003\u6587\u6863<\/h2>\n<ol>\n<li>\u6811\u8393\u6d3e\u4ecb\u7ecd<\/li>\n<li>\u7535\u8111\u8fde\u63a5\u6811\u8393\u6d3ePiZeroW<\/li>\n<li>\u6811\u8393\u6d3e+\u6e29\u5ea6\u4f20\u611f\u5668DS18B20<\/li>\n<li>\u6811\u8393\u6d3eGPIO\u63a7\u5236--C\u8bed\u8a00\u7bc7<a href=\"https:\/\/blog.csdn.net\/hu7850\/article\/details\/51785560\">https:\/\/blog.csdn.net\/hu7850\/article\/details\/51785560<\/a><\/li>\n<li>\u8fdc\u7a0b\u63a7\u5236\u901a\u8baf\u2014\u2014\u57fa\u4e8e\u6811\u8393\u6d3e Python gpiozero \u8fdc\u7a0b\u63a7\u5236LED\u706f\u5e76\u8fd4\u56de\u63a7\u5236\u7ed3\u679chttps:\/\/blog.csdn.net\/NCTU_to_prove_safety\/article\/details\/65446454<\/li>\n<li>RPi Low-level peripherals<br \/>\nhttps:\/\/elinux.org\/RPi_Low-level_peripherals<\/li>\n<li>\u6a39\u8393\u6d3e+\u6eab\u5ea6\u611f\u6e2c\u5668\u5be6\u73fe\u5ba4\u5167\u6eab\u5ea6\u76e3\u63a7\uff1ahttp:\/\/shumeipai.nxez.com\/2013\/10\/03\/raspberry-pi-temperature-sensor-monitors.html<\/li>\n<li><a href=\"http:\/\/www.cl.cam.ac.uk\/projects\/raspberrypi\/tutorials\/temperature\/\">Raspberry Pi Temperature Sensor<\/a><br \/>\nhttp:\/\/www.cl.cam.ac.uk\/projects\/raspberrypi\/tutorials\/temperature\/<\/li>\n<li>https:\/\/www.ccarea.cn\/archives\/215<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"0.\u00a0 \u6982\u8ff0 \u672c\u6587\u4ecb\u7ecd\u6811\u8393\u6d3e Zero W\u7684GPIO\u63a7\u5236\uff0c\u5e76\u7528LED\u770b\u6548\u679c\u3002 0.1 \u6811\u8393\u6d3eGPIO\u7f16\u53f7\u65b9\u5f0f 1.\u00a0 \u51c6\u5907 1.1 \u786c\u4ef6 \u6811\u8393\u6d3ePi Zero W LED\uff083mm\u62165mm\uff09 1K\u03a9\u7535\u963b \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[32],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-raspberry","tag-zero-w"],"views":1454,"_links":{"self":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/comments?post=283"}],"version-history":[{"count":13,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":949,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/283\/revisions\/949"}],"wp:attachment":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}