{"id":214901,"date":"2014-03-07T07:33:03","date_gmt":"2014-03-07T03:33:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=214901"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=214901","title":{"rendered":"<span class=\"post_title\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 SPI \u0438\u0437 Python \u043d\u0430 Raspberry Pi<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u043d\u0441\u0438\u0432\u0435\u0440\u0430 <a href=\"http:\/\/www.nordicsemi.com\/eng\/Products\/2.4GHz-RF\/nRF24L01P\">nRF24L01+<\/a> \u043a RPi. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 SPI \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 SPI \u043d\u0443\u0436\u043d\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 <i>\/etc\/modprobe.d\/raspi-blacklist.conf<\/i> \u0437\u0430\u043a\u043e\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 &quot;<i>blacklist spi-bcm2708<\/i>&quot; \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c Pi. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e SPI \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <i>\/dev<\/i>:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/22f\/c35\/4d6\/22fc354d6020f2c75001d9d9648a288d.jpg\" alt=\"image\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0420\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 SPI \u043d\u0430 \u0440\u0430\u0437\u044a\u0435\u043c\u0435 GPIO:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/cb2\/2d0\/1a5\/cb22d01a5de84cbaaad999919a8a04bf.jpg\" alt=\"image\"\/><\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b SPI \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043c\u043a\u043d\u0443\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 MOSI \u0438 MISO \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"bash\">$ wget https:\/\/raw2.github.com\/torvalds\/linux\/master\/Documentation\/spi\/spidev_test.c  $ gcc spidev_test.c  $ sudo .\/a.out -D \/dev\/spidev0.0 <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/4e2\/46a\/e0c\/4e246ae0cfd8472cef1cc6ab44f173c2.jpg\" alt=\"image\"\/><\/p>\n<p>  Python \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 SPI \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c <a href=\"https:\/\/github.com\/doceme\/py-spidev\/\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u043e\u0434\u0443\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"bash\">$ git clone https:\/\/github.com\/doceme\/py-spidev  $ cd py-spidev\/  $ sudo python setup.py install <\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f <i>py-spidev<\/i>.<\/p>\n<ul>\n<li><b>SpiDev([bus],[client])<\/b>. Return a new SPI object that is (optionally) connected to the specified SPI device interface.<\/li>\n<li><b>open(bus, device)<\/b>. Connects the object to the specified SPI device. open(X,Y) will open \/dev\/spidev-X.Y<\/li>\n<li><b>xfer2([values])<\/b>. Perform SPI transaction. CS will be held active between blocks.<\/li>\n<li><b>close()<\/b>. Disconnects the object from the interface.<\/li>\n<\/ul>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 SPI \u0438\u0437 Python:<\/p>\n<pre><code class=\"python\">nrf = spidev.SpiDev(0, 0) nrf.xfer2([0x1, 0x8]) nrf.close() <\/code><\/pre>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/214901\/\"> http:\/\/habrahabr.ru\/post\/214901\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u043d\u0441\u0438\u0432\u0435\u0440\u0430 <a href=\"http:\/\/www.nordicsemi.com\/eng\/Products\/2.4GHz-RF\/nRF24L01P\">nRF24L01+<\/a> \u043a RPi. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 SPI \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 SPI \u043d\u0443\u0436\u043d\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 <i>\/etc\/modprobe.d\/raspi-blacklist.conf<\/i> \u0437\u0430\u043a\u043e\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 &quot;<i>blacklist spi-bcm2708<\/i>&quot; \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c Pi. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e SPI \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <i>\/dev<\/i>:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/22f\/c35\/4d6\/22fc354d6020f2c75001d9d9648a288d.jpg\" alt=\"image\"\/>  <\/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-214901","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/214901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=214901"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/214901\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=214901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=214901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=214901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}