{"id":36815,"date":"2018-06-19T00:27:52","date_gmt":"2018-06-18T15:27:52","guid":{"rendered":"http:\/\/kako.com\/blog\/?p=36815"},"modified":"2018-06-20T12:32:33","modified_gmt":"2018-06-20T03:32:33","slug":"microbit%e3%81%aeuart%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%80%81pc%e3%81%a8%e3%82%b7%e3%83%aa%e3%82%a2%e3%83%ab%e9%80%9a%e4%bf%a1%e3%82%92%e8%a9%a6%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"http:\/\/kako.com\/blog\/?p=36815","title":{"rendered":"micro:bit\u306eUART\u3092\u4f7f\u3063\u3066\u3001PC\u3068\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\u3001PC\u3068\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3059\u308b\u306e\u3092\u8a66\u3057\u3066\u307f\u305f\u3002<\/p>\n<p><a href=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1459.jpg\"><img loading=\"lazy\" src=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1459.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-36817\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1459.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1459-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2018\/06\/Img_1459-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, uart\r\n\r\ndisplay.show(Image.HAPPY)\r\nuart.init(baudrate=9600, bits=8, parity=None, stop=1)\r\nuart.write(&quot;\\r\\n*** UART test ***\\r\\n&quot;)\r\nwhile True:\r\n    if uart.any():\r\n        s=uart.read() # read 1 byte\r\n        uart.write(s) # echo back\r\n        display.show(chr(s[0])) # show to led\r\n<\/pre>\n<p><!--more--><\/p>\n<p>\u3053\u306e\u3042\u305f\u308a\u306euart\u306b\u3064\u3044\u3066\u306e\u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u53c2\u8003\u306b\u3057\u305f\u3002<br \/>\n\u2192 <a href=\"https:\/\/microbit-micropython.readthedocs.io\/ja\/latest\/uart.html\">UART \u2014 BBC microbit MicroPython 0.5.0 \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a><\/p>\n<p>uart.init\u3067\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u3092\u521d\u671f\u5316\u3059\u308b\u306e\u3060\u304c\u3001\u3053\u306e\u3068\u304d\u306b\u4f7f\u3046pin\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3002<br \/>\n\u9006\u306b\u3001pin\u3092\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306b\u306fmicro:bit\u306eUSB-UART\u6a5f\u80fd\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001PC\u3068USB\u30b1\u30fc\u30d6\u30eb\u3067\u7e4b\u3052\u305f\u72b6\u614b\u3067PC\u3068\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/>\n\u305f\u3060\u3057\u3001microPython\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u6a5f\u80fd\u3068\u3057\u3066\u666e\u6bb5\u306f\u4f7f\u308f\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u30c7\u30d0\u30c3\u30b0\u7528\u306a\u3069\u306bmicroPython\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u306a\u304f\u306a\u308b\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3060\u3002<\/p>\n<p>\u6a5f\u80fd\u3068\u3057\u3066\u306f\u3001s=uart.read()\u30671\u30d0\u30a4\u30c8\u3092\u53d7\u4fe1\u3057\u3001uart.write(s)\u3067\u305d\u308c\u3092\u30a8\u30b3\u30fc\u30d0\u30c3\u30af\u3068\u3057\u3066\u9001\u4fe1\u3057\u3001\u540c\u6642\u306bLED\u8868\u793a\u90e8\u306bdisplay\u3067\u8868\u793a\u3092\u3057\u3066\u3044\u308b\u3002<br \/>\ndisplay.show(s)\u3068\u306f\u3067\u304d\u306a\u3044\u3002(s\u304cbytes\u578b\u3068\u3044\u3046byte\u306e\u914d\u5217\u306a\u306e\u3067\u3001\u6587\u5b57\u5217\u3068\u3057\u3066\u306f\u4f7f\u3048\u306a\u3044\u305f\u3081)<\/p>\n<p>PC\u5074\u306f\u3001TeraTerm\u306a\u3069\u3067micro:bit\u306b\u5bfe\u5fdc\u3057\u305fCOM\u30dd\u30fc\u30c8\u3092\u30019600bps,8\u30d3\u30c3\u30c8,\u30d1\u30ea\u30c6\u30a3\u306a\u3057,\u30b9\u30c8\u30c3\u30d7\u30d3\u30c3\u30c8\u306a\u3057\u3068\u3044\u3046\u8a2d\u5b9a\u306b\u3059\u308c\u3070\u3001\u901a\u4fe1\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/>\nPC\u3068micro:bit\u306e\u901a\u4fe1\u304c\u3064\u306a\u304c\u3063\u305f\u72b6\u614b\u3067\u3001\u4e00\u5ea6micro:bit\u306e\u30ea\u30bb\u30c3\u30c8\u30dc\u30bf\u30f3\u3092\u62bc\u305b\u3070\u3001\u6700\u521d\u306b\u300c*** UART tesst ***\u300d\u3068\u3044\u3046\u901a\u4fe1\u304cPC\u306b\u9001\u3089\u308c\u3066\u304d\u3066\u8868\u793a\u3055\u308c\u308b\u3002<br \/>\n\u305d\u306e\u3042\u3068\u3001PC\u5074\u3067\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u4f8b\u3048\u3070\u300ca\u300d\u30681\u6587\u5b57\u5165\u529b\u3059\u308b\u3068\u3001micro:bit\u5074\u304b\u3089\u30a8\u30b3\u30fc\u30d0\u30c3\u30af\u3067\u300ca\u300d\u304c\u5e30\u3063\u3066\u304d\u3066\u8868\u793a\u3055\u308c\u308b\u3002<br \/>\n\u305d\u308c\u3068\u540c\u6642\u306b\u3001micro:bit\u306eLED\u8868\u793a\u90e8\u306b\u3082\u300ca\u300d\u3068\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<p>\u3046\u307e\u304f\u52d5\u4f5c\u3059\u308b\u3082\u306e\u304c\u66f8\u3051\u305f\u3088\u3046\u3060\u3002\u3061\u3087\u3063\u3068\u5909\u66f4\u3059\u308c\u3070\u3001<a href=\"http:\/\/kako.com\/blog\/?p=36822\">micro:bit\u3069\u3046\u3057\u306e\u901a\u4fe1<\/a>\u3092\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3002<\/p>\n<p>&#8212;<br \/>\n\u6b21\u306f\u3001<a href=\"http:\/\/kako.com\/blog\/?p=36777\">radio\u306b\u3088\u308b\u7121\u7dda\u901a\u4fe1<\/a>\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u3001uart\u304b\u3089radio\u3092\u4f7f\u3063\u305f\u901a\u4fe1\u306e\u30d6\u30ea\u30c3\u30b8\u307f\u305f\u3044\u306a\u3082\u306e\u3092\u4f5c\u3063\u3066\u307f\u305f\u3044\u3002<\/p>\n<p><a href=\"http:\/\/kako.com\/blog\/?p=36822\">\u3064\u3065\u304f<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>micro:bit\u306eUART\u3092\u4f7f\u3063\u3066\u3001PC\u3068\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3059\u308b\u306e\u3092\u8a66\u3057\u3066\u307f\u305f\u3002 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\/36815"}],"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=36815"}],"version-history":[{"count":8,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36815\/revisions"}],"predecessor-version":[{"id":36827,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36815\/revisions\/36827"}],"wp:attachment":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36815"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}