{"id":171,"date":"2015-08-13T12:21:11","date_gmt":"2015-08-13T03:21:11","guid":{"rendered":"http:\/\/curry.azen.co.kr\/?p=171"},"modified":"2015-08-13T12:21:11","modified_gmt":"2015-08-13T03:21:11","slug":"%eb%9d%bc%ec%a6%88%eb%b2%a0%eb%a6%ac%ed%8c%8c%ec%9d%b4-%ec%9b%b9%ec%9d%84-%ed%86%b5%ed%95%9c-gpio-%ec%a0%9c%ec%96%b4","status":"publish","type":"post","link":"http:\/\/curry.azen.co.kr\/?p=171","title":{"rendered":"[\ub77c\uc988\ubca0\ub9ac\ud30c\uc774] \uc6f9\uc744 \ud1b5\ud55c GPIO \uc81c\uc5b4"},"content":{"rendered":"<p>\ubaa9\ud45c : \ub77c\uc988\ubca0\ub9ac\ud30c\uc774\ub97c \uc774\uc6a9\ud55c \uc6f9\uc744 \ud1b5\ud55c GPIO\uc81c\uc5b4\ub97c \ud558\ub824\ud55c\ub2e4.<\/p>\n<p>1. \ub77c\uc988\ubca0\ub9ac\ud30c\uc774\uc758 \uc6f9\uc11c\ube44\uc2a4 \uc81c\uacf5.<\/p>\n<p><code class=\"plain plain\">$sudo apt-get install lighttpd<\/code><\/p>\n<p>lighttpd \uc11c\ube44\uc2a4 \uc124\uce58.<\/p>\n<p><code class=\"plain plain\">$sudo lighttpd start<br \/>\n<\/code><\/p>\n<p>\ud558\uace0\uc11c \ub77c\uc988\ubca0\ub9ac\ud30c\uc774\uc758 IP\ub97c \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \ubcf4\uba74<\/p>\n<p><a href=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/\u1109\u1173\u110f\u1173\u1105\u1175\u11ab\u1109\u1163\u11ba-2015-08-13-\u110b\u1169\u1112\u116e-12.03.40.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-172\" src=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/\u1109\u1173\u110f\u1173\u1105\u1175\u11ab\u1109\u1163\u11ba-2015-08-13-\u110b\u1169\u1112\u116e-12.03.40-600x371.png\" alt=\"\u1109\u1173\u110f\u1173\u1105\u1175\u11ab\u1109\u1163\u11ba 2015-08-13 \u110b\u1169\u1112\u116e 12.03.40\" width=\"600\" height=\"371\" \/><\/a><\/p>\n<p>lighttpd \ud654\uba74\uc744 \ubcfc \uc218 \uc788\ub2e4.<\/p>\n<p>&nbsp;<\/p>\n<p>2. \uc124\uc815\ubcc0\uacbd.<\/p>\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">pi@raspberrypi \/var\/www $ ls -l \/usr\/bin\/python<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">lrwxrwxrwx 1 root root 9 Jun 6 2012 \/usr\/bin\/python -&gt; python2.7<\/code><\/div>\n<p><code class=\"plain plain\">pi@raspberrypi \/var\/www $ sudo chmod u+s \/usr\/bin\/python<\/code><\/p>\n<div class=\"line number5 index4 alt2\"><code class=\"plain plain\">pi@raspberrypi \/var\/www $ ls -l \/usr\/bin\/python<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"plain plain\">-rwsr-xr-x 1 root root 2674528 Mar 17 18:16 \/usr\/bin\/python<\/code><\/div>\n<div class=\"line number6 index5 alt1\">python\uc758 \uc2e4\ud589\uad8c\ud55c\uc744 \ubcc0\uacbd\ud558\uace0,<\/div>\n<div class=\"line number6 index5 alt1\">$ sudo vi \/etc\/lighttpd\/lighttpd.conf<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">server.modules = (<br \/>\n&#8220;mod_access&#8221;,<br \/>\n&#8220;mod_alias&#8221;,<br \/>\n&#8220;mod_accesslog&#8221;,<br \/>\n&#8220;mod_auth&#8221;,<br \/>\n&#8220;mod_ssi&#8221;,<br \/>\n&#8220;mod_cgi&#8221;,<br \/>\n&#8220;mod_compress&#8221;,<br \/>\n&#8220;mod_fastcgi&#8221;,<br \/>\n&#8220;mod_rewrite&#8221;,<br \/>\n)<\/div>\n<div class=\"line number6 index5 alt1\">server.modules \uc5d0 \uc0c1\uae30\uc640 \uac19\uc774 \ubcc0\uacbd\ud574\uc8fc\uace0,<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">\uc81c\uc77c \ud558\ub2e8\uc5d0 python \ud654\uc77c\uc744 \ub123\uc5b4\ub458 \ub514\ub809\ud1a0\ub9ac\ub97c \uc9c0\uc815\ud574\uc900\ub2e4.<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">$HTTP[&#8220;url&#8221;] =~ &#8220;^\/py\/&#8221; {<br \/>\ncgi.assign = ( &#8220;.py&#8221; =&gt; &#8220;\/usr\/bin\/python&#8221; )<br \/>\n}<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">\uc774\ud6c4<\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"plain plain\">$ sudo service lighttpd restart<\/code><\/div>\n<div class=\"line number6 index5 alt1\">\uc7ac\uc2dc\uc791\uc744 \ud558\uace0<\/div>\n<div class=\"line number6 index5 alt1\">test.py \ub97c \/var\/www\/py \ud3f4\ub354 \ub0b4\uc5d0 \uc785\ub825\ud574\uc900\ub2e4.<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">#! \/usr\/bin\/python<br \/>\n# bring in the libraries<br \/>\nimport RPi.GPIO as G<br \/>\nfrom flup.server.fcgi import WSGIServer<br \/>\nimport sys, urlparse<\/p>\n<p># set up our GPIO pins<br \/>\nG.setmode(G.BOARD)<br \/>\nG.setup(7, G.OUT)<br \/>\nG.setup(11, G.OUT)<br \/>\nG.setup(13, G.OUT)<\/p>\n<p># all of our code now lives within the app() function which is called for each http request we receive<br \/>\ndef app(environ, start_response):<br \/>\n# start our http response<br \/>\nstart_response(&#8220;200 OK&#8221;, [(&#8220;Content-Type&#8221;, &#8220;text\/html&#8221;)])<br \/>\n# look for inputs on the URL<br \/>\ni = urlparse.parse_qs(environ[&#8220;QUERY_STRING&#8221;])<br \/>\nyield (&#8216;&amp;nbsp;&#8217;) # flup expects a string to be returned from this function<br \/>\n# if there&#8217;s a url variable named &#8216;q&#8217;<br \/>\nif &#8220;q&#8221; in i:<br \/>\nif i[&#8220;q&#8221;][0] == &#8220;a&#8221;:<br \/>\nG.output(7, True)\u00a0\u00a0 # Turn it on<br \/>\nelif i[&#8220;q&#8221;][0] == &#8220;b&#8221;:<br \/>\nG.output(7, False)\u00a0 # Turn it off<br \/>\nelif i[&#8220;q&#8221;][0] == &#8220;c&#8221;:<br \/>\nG.output(11, True)\u00a0 # Turn it off<br \/>\nelif i[&#8220;q&#8221;][0] == &#8220;d&#8221;:<br \/>\nG.output(11, False)\u00a0 # Turn it off<br \/>\nelif i[&#8220;q&#8221;][0] == &#8220;e&#8221;:<br \/>\nG.output(13, True)\u00a0 # Turn it off<br \/>\nelif i[&#8220;q&#8221;][0] == &#8220;f&#8221;:<br \/>\nG.output(13, False)\u00a0 # Turn it off<\/p>\n<p>#by default, Flup works out how to bind to the web server for us, so just call it with our app() function and let it get on with it<br \/>\nWSGIServer(app).run()<\/p><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"plain plain\">$ chmod +x test.py<\/code><\/div>\n<div class=\"line number6 index5 alt1\">python \ud30c\uc77c\uc758 \uc2e4\ud589\uad8c\ud55c \ubcc0\uacbd.<\/div>\n<div class=\"line number6 index5 alt1\">\/var\/www\/test.html \uc785\ub825 \ub0b4\uc6a9.<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;Hello from the Pi&lt;\/title&gt;<br \/>\n&lt;script src=&#8221;\/\/ajax.googleapis.com\/ajax\/libs\/prototype\/1.7.1.0\/prototype.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;h1&gt;Hello world from the Raspberry Pi&lt;\/h1&gt;<br \/>\n&lt;form&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;1On&#8221; onclick=&#8221;go(&#8216;a&#8217;)&#8221; style=&#8221;font-size:200%;&#8221;&gt;&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;1Off&#8221; onclick=&#8221;go(&#8216;b&#8217;)&#8221; style=&#8221;font-size:200%;&#8221;&gt;<br \/>\n&lt;br \/&gt;&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;2On&#8221; onclick=&#8221;go(&#8216;c&#8217;)&#8221; style=&#8221;font-size:200%;&#8221;&gt;&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;2Off&#8221; onclick=&#8221;go(&#8216;d&#8217;)&#8221; style=&#8221;font-size:200%;&#8221;&gt;<br \/>\n&lt;br \/&gt;&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;3On&#8221; onclick=&#8221;go(&#8216;e&#8217;)&#8221; style=&#8221;font-size:200%;&#8221;&gt;&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;3Off&#8221; onclick=&#8221;go(&#8216;f&#8217;)&#8221; style=&#8221;font-size:200%;&#8221;&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\nfunction go(qry) {<br \/>\nnew Ajax.Request(&#8216;.\/py\/test.py?q=&#8217; + qry,<br \/>\n{method: &#8216;GET&#8217;}<br \/>\n);<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">GPIO \uc791\uc5c5\ubd80\ubd84\uc740 \uc544\ub798\uc640 \uac19\uc774 7, 11, 13 \ubc88\uc5d0 \uac01\uac01\uc758 LED + \uc120\uc744 \uc5f0\uacb0\ud558\uace0, GND \uc120\uc744 \uc5f0\uacb0\ud574\uc900 \ud6c4&#8230;<\/div>\n<div class=\"line number6 index5 alt1\"><a href=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/photo_1439435724.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-175\" src=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/photo_1439435724-450x600.jpg\" alt=\"photo_1439435724\" width=\"450\" height=\"600\" \/><\/a><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">\ud648\ud398\uc774\uc9c0 \ub97c \uc5f4\uc5b4\ubcf4\uc2dc\uba74&#8230; \uc544\ub798\uc640 \uac19\uc740 \ud654\uba74\uc774 \ubcf4\uc778\ub2e4.<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">\u00a0<a href=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/photo_1439435723.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-174\" src=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/photo_1439435723-450x600.jpg\" alt=\"photo_1439435723\" width=\"450\" height=\"600\" \/><\/a><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">\uac01\uac01\uc758 ON \uc744 \ub204\ub974\uba74 \uc544\ub798\uc640 \uac19\uc774 3\uac1c\uc758 LED\uac00 \ub4e4\uc5b4\uc624\ub294 \uac83\uc744 \ubcfc \uc218 \uc788\ub2e4.<\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\"><a href=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/photo_1439435722.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-173\" src=\"http:\/\/curry.azen.co.kr\/wp-content\/uploads\/2015\/08\/photo_1439435722-450x600.jpg\" alt=\"photo_1439435722\" width=\"450\" height=\"600\" \/><\/a><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number6 index5 alt1\">\ucc38\uace0 : http:\/\/make.bcde.jp\/category\/16\/<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\ubaa9\ud45c : \ub77c\uc988\ubca0\ub9ac\ud30c\uc774\ub97c \uc774\uc6a9\ud55c \uc6f9\uc744 \ud1b5\ud55c GPIO\uc81c\uc5b4\ub97c \ud558\ub824\ud55c\ub2e4. 1. \ub77c\uc988\ubca0\ub9ac\ud30c\uc774\uc758 \uc6f9\uc11c\ube44\uc2a4 \uc81c\uacf5. $sudo apt-get install lighttpd lighttpd \uc11c\ube44\uc2a4 \uc124\uce58. $sudo lighttpd start \ud558\uace0\uc11c \ub77c\uc988\ubca0\ub9ac\ud30c\uc774\uc758 IP\ub97c \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \ubcf4\uba74 lighttpd \ud654\uba74\uc744 \ubcfc \uc218 \uc788\ub2e4. &nbsp; 2. \uc124\uc815\ubcc0\uacbd. pi@raspberrypi \/var\/www $ ls -l \/usr\/bin\/python lrwxrwxrwx 1 root root 9 Jun 6 2012 \/usr\/bin\/python -&gt; python2.7 pi@raspberrypi \/var\/www $ &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/curry.azen.co.kr\/?p=171\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;[\ub77c\uc988\ubca0\ub9ac\ud30c\uc774] \uc6f9\uc744 \ud1b5\ud55c GPIO \uc81c\uc5b4&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":1,"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":176,"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions\/176"}],"wp:attachment":[{"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/curry.azen.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}