{"id":701,"date":"2019-09-01T10:59:20","date_gmt":"2019-09-01T01:59:20","guid":{"rendered":"https:\/\/dalomo.net\/blog\/?p=701"},"modified":"2019-09-01T10:59:20","modified_gmt":"2019-09-01T01:59:20","slug":"pigpio-error-no-handle-available%e3%81%a3%e3%81%a6%e3%82%a8%e3%83%a9%e3%83%bc%e3%81%8c%e5%87%ba%e3%81%9f","status":"publish","type":"post","link":"https:\/\/dalomo.net\/blog\/2019\/09\/01\/701\/","title":{"rendered":"pigpio.error: &#8216;no handle available&#8217;\u3063\u3066\u30a8\u30e9\u30fc\u304c\u51fa\u305f"},"content":{"rendered":"<h1>\u306a\u3093\u3067\u3060<\/h1>\n<p><a href=\"https:\/\/dalomo.net\/blog\/2019\/08\/27\/692\/\">\u524d\u56de<\/a>\u3067\u304d\u305f\u30fc\u3068\u601d\u3044\u3001\u610f\u6c17\u63da\u3005\u3068\u8c46\u82d7\u8cb7\u3063\u3066\u304d\u3066\u80b2\u3066\u3066\u305f\u3089\u3001\u3044\u3064\u306e\u9593\u306b\u304b\u5199\u771f\u304c\u4fdd\u5b58\u3055\u308c\u306a\u304f\u306a\u3063\u3066\u305f\u3002<\/p>\n<h2>\u3084\u3063\u3066\u307f\u305f\u3053\u3068<\/h2>\n<p>cron\u3067\u81ea\u52d5\u5b9f\u884c\u3057\u3066\u308b\u306e\u3067\u3001\u306a\u3093\u306e\u30a8\u30e9\u30fc\u304b\u5206\u304b\u3089\u306a\u3044\u3002\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4e0a\u3067\u5b9f\u884c\u3057\u3066\u307f\u305f\u3089\u3001\u51fa\u308b\u304b\u306a\u30fc\u3068\u601d\u3063\u3066\u3084\u3063\u3066\u307f\u305f\u3089\u51fa\u3066\u304f\u308c\u305f\u3002<\/p>\n<pre class=\"shell\">Traceback (most recent call last):\r\n  File \"\/home\/pi\/nas\/shutter.py\", line 10, in &lt;module&gt;\r\n    h = pi.spi_open(0, 50000, 0)\r\n  File \"\/usr\/lib\/python2.7\/dist-packages\/pigpio.py\", line 3787, in spi_open\r\n    self.sl, _PI_CMD_SPIO, spi_channel, baud, 4, extents))\r\n  File \"\/usr\/lib\/python2.7\/dist-packages\/pigpio.py\", line 970, in _u2i\r\n    raise error(error_text(v))\r\npigpio.error: 'no handle available'<\/pre>\n<p>SPI\u901a\u4fe1\u3092\u958b\u304f\u3068\u3053\u308d\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u308b\u307f\u305f\u3044\u3002pigpio.error: &#8216;no handle available&#8217;\u3067\u30b0\u30b0\u308b\u3068\u30e9\u30ba\u30d1\u30a4\u306e\u30d5\u30a9\u30fc\u30e9\u30e0\u304c\u51fa\u3066\u304f\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?t=88545\">https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?t=88545<\/a><\/p>\n<p>\u305d\u3053\u306epigpio\u306e\u4f5c\u8005\u3055\u3093\u3063\u307d\u3044joan\u3055\u3093\u306b\u3088\u308b\u3068<\/p>\n<blockquote><p>No handle available means that all 32 handles are in use. Assuming you aren&#8217;t using 32 devices it means you have opened an I2C device without closing it at the end of the script.<\/p>\n<p>\u4f7f\u7528\u53ef\u80fd\u306a\u30cf\u30f3\u30c9\u30eb\u304c\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u306f\u300132\u500b\u306e\u30cf\u30f3\u30c9\u30eb\u304c\u3059\u3079\u3066\u4f7f\u7528\u4e2d\u3067\u3042\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002 32\u500b\u306e\u30c7\u30d0\u30a4\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u6700\u5f8c\u3067I2C\u30c7\u30d0\u30a4\u30b9\u3092\u9589\u3058\u305a\u306b\u958b\u3044\u305f\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002(\u6a5f\u68b0\u7ffb\u8a33)<\/p><\/blockquote>\n<p>\u4f7f\u3063\u305f\u3042\u3068\u306b\u9589\u3058\u308d\u3084\u3001\u3068\u3044\u3046\u3053\u3068\u3089\u3057\u3044\u3093\u3060\u3051\u3069\u3001pi.spi_close(h)\u3067\u9589\u3058\u3066\u308b\u3088\u306d\u2026?\u30d5\u30a9\u30fc\u30e9\u30e0\u3067\u306f\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4e0a\u3067<\/p>\n<pre class=\"shell\">for ((i=0; i&lt;32; i++)); do pigs spic $i; done<\/pre>\n<p>\u3063\u3066\u3084\u308c\u3070\u30cf\u30f3\u30c9\u30e9\u304c\u9589\u3058\u308c\u308b\u3088\u3068\u30a2\u30c9\u30d0\u30a4\u30b9\u304c\u3042\u3063\u305f\u304c\u3001\u305d\u3082\u305d\u3082\u306a\u3093\u3067\u30cf\u30f3\u30c9\u30e9\u304c\u958b\u3044\u305f\u307e\u307e\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3093\u3060\u308d\u3046\u304b\u3002<\/p>\n<p>\u753b\u50cf\u306f80\u679a\u307b\u3069\u4fdd\u5b58\u3055\u308c\u3066\u3044\u305f\u3002\u9014\u4e2d\u307e\u3067\u306f\u4fdd\u5b58\u3067\u304d\u3066\u305f\u306e\u306b\u306a\u305c\u7a81\u7136?\u3068\u7591\u554f\u306b\u601d\u3063\u3066\u753b\u50cf\u3092\u8abf\u3079\u3066\u307f\u308b\u3068\u3001\u591c\u4e2d\u64ae\u3063\u3066\u308b\u3082\u306e\u306f\u5927\u4e08\u592b\u3067\u3001\u65e5\u4e2d\u64ae\u3063\u305f\u3082\u306e\u304c\u30c0\u30e1\u306a\u3088\u3046\u3060\u3063\u305f\u3002\u304a\u305d\u3089\u304f\u30b3\u30fc\u30c9\u306b\u554f\u984c\u304c\u3042\u308a\u305d\u3046\u3002\u3067\u3082\u898b\u3066\u3082\u3088\u304f\u5206\u304b\u3093\u306a\u3044\u3002\u3068\u3044\u3046\u3053\u3068\u3067\u4ee5\u524d\u3084\u3063\u305f\u3088\u3046\u306bcron\u3092<\/p>\n<pre>0-59\/1 * * * * python \/home\/pi\/nas\/shutter.py &gt;&gt; \/tmp\/shutter.log 2&gt;&amp;1<\/pre>\n<p>\u3066\u611f\u3058\u3067\u30ed\u30b0\u3092\u51fa\u529b\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3002\u518d\u8d77\u52d5\u3057\u3066\u753b\u50cf\u3068\u304b\u3082\u524a\u9664\u3057\u3066\u307e\u3063\u3055\u3089\u306a\u72b6\u614b\u3067\u5f85\u3064\u3002\u3067\u3001\u30ed\u30b0\u3092\u898b\u3066\u307f\u308b\u3068<\/p>\n<pre class=\"python\">Traceback (most recent call last):\r\n  File \"\/home\/pi\/nas\/shutter.py\", line 50, in &lt;module&gt;\r\n    if islighted:\r\nNameError: name 'islighted' is not defined<\/pre>\n<p>\u3068\u51fa\u529b\u3055\u308c\u3066\u3044\u305f\u3002islighted\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u306a\u3044?\u3042\u3063!<\/p>\n<pre class=\"python\">if bi &lt; 1700:\r\n    pi.set_mode(17, pg.OUTPUT)\r\n    pi.write(17, pg.HIGH)\r\n    islighted = True\r\n    sleep(0.5)<\/pre>\n<p>\u3042\u3001\u305d\u3046\u3044\u3048\u3070\u95be\u5024\u30921700\u306b\u5909\u3048\u305f\u3002\u3053\u3053\u306e\u90e8\u5206\u3067\u3001if\u5185\u3067\u3057\u304b\u5ba3\u8a00?\u4ee3\u5165?\u3057\u3066\u306a\u3044\u306e\u3067\u3001\u660e\u308b\u3044\u3068\u304d\u306b\u306fislighted\u306b\u5024\u304c\u4ee3\u5165\u3055\u308c\u305a<\/p>\n<pre class=\"python\">if islighted:\r\n    pi.write(17, pg.LOW)<\/pre>\n<p>\u3053\u3053\u3067\u4f7f\u3046\u6642\u306b\u7a7a\u306e\u307e\u307e\u3067\u4f7f\u304a\u3046\u3068\u3057\u3066\u308b\u304b\u3089\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3093\u3060!\u3067\u3001\u3053\u3053\u3067\u51e6\u7406\u304c\u6b62\u307e\u3063\u3061\u3083\u3046\u304b\u3089spi_close\u304c\u3067\u304d\u305a\u306b\u30cf\u30f3\u30c9\u30e9\u304c\u6b8b\u3063\u3061\u3083\u3046\u3068\u3002\u3066\u3053\u3068\u306f\u660e\u308b\u3055\u53d6\u5f97\u3059\u308b\u524d\u306b<\/p>\n<pre class=\"python\">islighted = False\r\n\r\nif bi &lt; 1700:\r\n    pi.set_mode(17, pg.OUTPUT)\r\n#\u7565<\/pre>\n<p>\u3066\u521d\u671f\u5316\u3057\u3066\u3042\u3052\u308c\u3070\u3044\u3044\u306d\u3002\u89e3\u6c7a\u3057\u305f\u3002<\/p>\n<h3>\u305d\u306e\u4ed6<\/h3>\n<ul>\n<li>\u30cf\u30f3\u30c9\u30e9\u306e\u578b\u306flong\n<ul>\n<li>\u4fee\u6b63\u524d\u306f\u3053\u306e\u5024\u304c\u5897\u3048\u3066\u3044\u3063\u3066\u300131\u3088\u308a\u5927\u304d\u304f\u306a\u308b\u3068no handle\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u305f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>pigpiod\u306e\u518d\u8d77\u52d5\u3067\u3082\u3044\u3051\u308b\u306e\u304b\u3082\u3002\n<ul>\n<li>\u691c\u8a3c\u3057\u3088\u3046\u3068.sh\u4f5c\u3063\u305f\u3089\u6a29\u9650\u8a2d\u5b9a\u30df\u30b9\u3067\u8d77\u52d5\u3057\u3066\u306a\u304b\u3063\u305f\u3002\u30cf\u30f3\u30c9\u30eb\u304c\u6e9c\u307e\u3063\u3066\u308b\u72b6\u614b\u3067\u66f4\u306b\u958b\u3053\u3046\u3068\u3059\u308b\u3068\u3001\u7121\u3044\u3088\u30fc\u3063\u3066\u306a\u308b\u306f\u305a\u306a\u306e\u3067\u30c7\u30fc\u30e2\u30f3\u3092\u518d\u8d77\u52d5\u3057\u3066\u958b\u653e\u3057\u3066\u3042\u3052\u308c\u3070\u3044\u3044\u3093\u3058\u3083\u306a\u3044\u3060\u308d\u304b\u3002\u305f\u3060\u6839\u672c\u89e3\u6c7a\u3058\u3083\u306a\u3044\u306e\u3067\u3084\u3063\u3071\u308a\u4e0a\u8a18\u306e\u3067\u3044\u3044\u3068\u601d\u3046\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u30ed\u30b0\u306f\u3061\u3083\u3093\u3068\u53d6\u308b\u3002<\/li>\n<li>IDE\u307b\u3057\u3044\u3002<\/li>\n<li>\u3050\u306c\u306c<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u306a\u3093\u3067\u3060 \u524d\u56de\u3067\u304d\u305f\u30fc\u3068\u601d\u3044\u3001\u610f\u6c17\u63da\u3005\u3068\u8c46\u82d7\u8cb7\u3063\u3066\u304d\u3066\u80b2\u3066\u3066\u305f\u3089\u3001\u3044\u3064\u306e\u9593\u306b\u304b\u5199\u771f\u304c\u4fdd\u5b58\u3055\u308c\u306a\u304f\u306a\u3063\u3066\u305f\u3002 \u3084\u3063\u3066\u307f\u305f\u3053\u3068 cron\u3067\u81ea\u52d5\u5b9f\u884c\u3057\u3066\u308b\u306e\u3067\u3001\u306a\u3093\u306e\u30a8\u30e9\u30fc\u304b\u5206\u304b\u3089\u306a\u3044\u3002\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4e0a\u3067\u5b9f\u884c\u3057\u3066\u307f\u305f\u3089\u3001\u51fa\u308b\u304b &hellip; <a href=\"https:\/\/dalomo.net\/blog\/2019\/09\/01\/701\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[9],"tags":[50,49,47],"class_list":["post-701","post","type-post","status-publish","format-standard","hentry","category-9","tag-python","tag-raspberry-pi-zero-wh","tag-47"],"_links":{"self":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/comments?post=701"}],"version-history":[{"count":2,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/701\/revisions"}],"predecessor-version":[{"id":703,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/701\/revisions\/703"}],"wp:attachment":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/media?parent=701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/categories?post=701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/tags?post=701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}