{"id":36822,"date":"2018-06-20T05:54:45","date_gmt":"2018-06-19T20:54:45","guid":{"rendered":"http:\/\/kako.com\/blog\/?p=36822"},"modified":"2018-06-22T07:56:38","modified_gmt":"2018-06-21T22:56:38","slug":"microbit%e3%81%aeuart%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%80%81microbit%e3%81%a9%e3%81%86%e3%81%97%e3%81%a7%e3%82%b7%e3%83%aa%e3%82%a2%e3%83%ab%e9%80%9a%e4%bf%a1%e3%81%99%e3%82%8b%e3%81%ae","status":"publish","type":"post","link":"http:\/\/kako.com\/blog\/?p=36822","title":{"rendered":"micro:bit\u306eUART\u3092\u4f7f\u3063\u3066\u3001micro:bit\u3069\u3046\u3057\u3067\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3059\u308b\u306e\u3092\u8a66\u3057\u3066\u307f\u305f"},"content":{"rendered":"<p>micro:bit\u306eUART\u3092\u4f7f\u3063\u3066\u3001micro:bit\u3069\u3046\u3057\u3067\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3059\u308b\u306e\u3092\u8a66\u3057\u3066\u307f\u305f\u3002(<a href=\"http:\/\/kako.com\/blog\/?p=36815\">\u6628\u65e5\u306e\u7d9a\u304d<\/a>)<\/p>\n<p><a href=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1461.jpg\"><img loading=\"lazy\" src=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1461.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-36823\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1461.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1461-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1461-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>microPython\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u305f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfrom microbit import display, Image, button_a, button_b, uart, pin0, pin1\r\n\r\ndisplay.show(Image.HAPPY)\r\nuart.init(baudrate=9600, bits=8, parity=None, stop=1,tx=pin0,rx=pin1)\r\nwhile True:\r\n    if button_a.was_pressed():\r\n        uart.write(&quot;A&quot;)\r\n    if button_b.was_pressed():\r\n        uart.write(&quot;B&quot;)\r\n    if uart.any():\r\n        s=uart.read() # read 1 byte\r\n        display.show(chr(s[0])) #show to led\r\n<\/pre>\n<p><!--more--><\/p>\n<p><a href=\"http:\/\/kako.com\/blog\/?p=36815\">\u6628\u65e5\u306eUART\u901a\u4fe1\u306e\u30d7\u30ed\u30b0\u30e9\u30e0<\/a>\u3092\u5c11\u3057\u5909\u66f4\u3057\u3066\u66f8\u3044\u305f\u3002<br \/>\nUART\u306e\u521d\u671f\u5316\u306e\u51e6\u7406\u304c\u3001uart.init(baudrate=9600, bits=8, parity=None, stop=1,tx=pin0,rx=pin1)\u3068\u5909\u308f\u3063\u3066\u3044\u308b\u3002<br \/>\ntx=pin0,rx=pin1\u3068\u3044\u3046\u306e\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001UART\u306e\u9001\u4fe1\u7528\u306bP0\u3068\u3044\u3046\u7aef\u5b50\u3092\u4f7f\u7528\u3057\u3001UART\u306e\u53d7\u4fe1\u7528\u306bP1\u3068\u3044\u3046\u7aef\u5b50\u3092\u4f7f\u7528\u3059\u308b\u3068\u3044\u3046\u8a2d\u5b9a\u3060\u3002(\u305d\u308c\u4ee5\u5916\u306e\u7aef\u5b50\u3092\u4f7f\u3046\u5834\u5408\u3001<a href=\"http:\/\/kako.com\/blog\/?p=36841\">\u3053\u3061\u3089\u3092\u53c2\u7167<\/a>)<\/p>\n<p>\u305d\u306e\u3042\u3068\u306e\u51e6\u7406\u306f\u3001<br \/>\n(1) \u30dc\u30bf\u30f3A\u304c\u62bc\u3055\u308c\u305f\u3089\u3001uart.write(&#8220;A&#8221;)\u3067\u300cA\u300d\u3092UART\u306b\u9001\u4fe1\u3059\u308b<br \/>\n(2) \u30dc\u30bf\u30f3B\u304c\u62bc\u3055\u308c\u305f\u3089\u3001uart.write(&#8220;B&#8221;)\u3067\u300cB\u300d\u3092UART\u306b\u9001\u4fe1\u3059\u308b<br \/>\n(3) UART\u306b\u53d7\u4fe1\u30c7\u30fc\u30bf\u304c\u3042\u308b\u5834\u5408\u3001s=uart.read()\u3067\u53d7\u4fe1\u3057\u3001display.show()\u3067\u305d\u306e\u30c7\u30fc\u30bf\u3092LED\u8868\u793a\u90e8\u306b\u8868\u793a\u3059\u308b<br \/>\n\u3068\u3044\u3046\u52d5\u4f5c\u3092\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>2\u53f0\u306emicro:bit\u306b\u540c\u3058\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304d\u8fbc\u3093\u3067\u30012\u3064\u306emicro:bit\u306e\u901a\u4fe1\u7528\u306e\u914d\u7dda\u3092\u63a5\u7d9a\u3059\u308b\u3002<br \/>\n1\u3064\u3081\u306emicro:bit\u306eP0\u7aef\u5b50\u3092\u30012\u3064\u3081\u306emicro:bit\u306eP1\u7aef\u5b50\u306b\u3064\u306a\u3050\u3002<br \/>\n1\u3064\u3081\u306emicro:bit\u306eP1\u7aef\u5b50\u3092\u30012\u3064\u3081\u306emicro:bit\u306eP2\u7aef\u5b50\u306b\u3064\u306a\u3050\u3002<br \/>\n(\u3064\u307e\u308a\u3001\u30af\u30ed\u30b9\u914d\u7dda\u3092\u3059\u308b)<br \/>\n\u305d\u3057\u3066\u30012\u3064\u306emicro:bit\u306eGND\u7aef\u5b50\u3069\u3046\u3057\u3092\u3064\u306a\u3050\u3002<\/p>\n<p>1\u3064\u3081\u306emicro:bit\u306eA\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001UART\u3067\u30c7\u30fc\u30bf\u304c\u9001\u3089\u308c\u3066\u30012\u3064\u3081\u306emciro:bit\u3067\u53d7\u4fe1\u3057\u305f\u30c7\u30fc\u30bf(\u3053\u306e\u5834\u5408A)\u304c\u8868\u793a\u3055\u308c\u308b\u3002<br \/>\n2\u3064\u3081\u306emicro:bit\u306eB\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001UART\u3067\u30c7\u30fc\u30bf\u304c\u9001\u3089\u308c\u3066\u30011\u3064\u3081\u306emciro:bit\u3067\u53d7\u4fe1\u3057\u305f\u30c7\u30fc\u30bf(\u3053\u306e\u5834\u5408B)\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<p>\u6ce8\u610f\u70b9\u3068\u3057\u3066\u306f\u3001\u81ea\u5206\u306fIC\u30af\u30ea\u30c3\u30d7\u4ed8\u304d\u306e\u96fb\u7dda\u30672\u3064\u306emicro:bit\u3092\u3064\u306a\u3044\u3060\u306e\u3060\u304c\u3001\u57fa\u677f\u306eLED\u8868\u793a\u5074\u306e\u9762\u304b\u3089IC\u30af\u30ea\u30c3\u30d7\u3092\u5f15\u3063\u304b\u3051\u308b\u3068\u3001\u88cf\u5074\u306e\u30ea\u30f3\u30b0\u72b6\u306e\u57fa\u677f\u30d1\u30bf\u30fc\u30f3\u3068\u57fa\u677f\u30a8\u30c3\u30b8\u306e\u30d1\u30bf\u30fc\u30f3\u3068\u306e\u9593\u306e\u9699\u9593\u306b\u5f53\u305f\u3063\u3066\u3057\u307e\u3044\u3001\u3046\u307e\u304f\u5c0e\u901a\u3057\u306a\u3044\u3053\u3068\u304c\u3042\u3063\u305f\u3002<br \/>\nIC\u30af\u30ea\u30c3\u30d7\u3067\u306f\u306a\u304f\u3001\u30d0\u30ca\u30ca\u7aef\u5b50\u306a\u3069\u3092\u4f7f\u3046\u3068\u3088\u3044\u3060\u308d\u3046\u3002<br \/>\n<iframe style=\"width:120px;height:240px;\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"https:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?ref=qf_sp_asin_til&#038;t=gid023014-22&#038;m=amazon&#038;o=9&#038;p=8&#038;l=as1&#038;IS2=1&#038;detail=1&#038;asins=B00FFY2M7U&#038;linkId=821e58c4dbfa08b8cb0d50e6f6b6578a&#038;bc1=000000&#038;lt1=_blank&#038;fc1=333333&#038;lc1=0066c0&#038;bg1=ffffff&#038;f=ifr\"><br \/>\n    <\/iframe><\/p>\n<p>&#8212;<br \/>\n\u6b21\u306f\u3001\u3053\u306eUART\u901a\u4fe1\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u3001<a href=\"http:\/\/kako.com\/blog\/?p=36777\">\u7121\u7dda\u7248\u306emicro:bit\u9593\u306e\u901a\u4fe1\u30d7\u30ed\u30b0\u30e9\u30e0<\/a>\u3068\u5408\u4f53\u3055\u305b\u3066\u307f\u308b\u3002<\/p>\n<p><a href=\"http:\/\/kako.com\/blog\/?p=36828\">\u3064\u3065\u304f<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>micro:bit\u306eUART\u3092\u4f7f\u3063\u3066\u3001micro:bit\u3069\u3046\u3057\u3067\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3059\u308b\u306e\u3092\u8a66\u3057\u3066\u307f\u305f\u3002(\u6628\u65e5\u306e\u7d9a\u304d) microPython\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u305f\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,14],"tags":[],"_links":{"self":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36822"}],"collection":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36822"}],"version-history":[{"count":3,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36822\/revisions"}],"predecessor-version":[{"id":36850,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36822\/revisions\/36850"}],"wp:attachment":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36822"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}