{"id":46574,"date":"2019-12-20T14:05:39","date_gmt":"2019-12-20T05:05:39","guid":{"rendered":"http:\/\/kako.com\/blog\/?p=46574"},"modified":"2019-12-20T15:23:36","modified_gmt":"2019-12-20T06:23:36","slug":"m5stickc%e3%81%a8env-hat%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%80%81%e3%82%b8%e3%83%a3%e3%82%a4%e3%83%ad%e3%82%bb%e3%83%b3%e3%82%b5%e3%83%bc%e5%8a%a0%e9%80%9f%e5%ba%a6%e3%82%bb%e3%83%b3%e3%82%b5","status":"publish","type":"post","link":"http:\/\/kako.com\/blog\/?p=46574","title":{"rendered":"M5StickC\u3068ENV HAT\u3092\u4f7f\u3063\u3066\u3001\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc+\u52a0\u901f\u5ea6\u30bb\u30f3\u30b5\u30fc+\u5730\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306e9DoF\u3092\u8a66\u3057\u3066\u307f\u308b &#8211; \u305d\u306e1"},"content":{"rendered":"\n<p><a href=\"http:\/\/kako.com\/blog\/?p=46476\"> M5StickC\u306b\u53d6\u308a\u4ed8\u3051\u308bENV HAT\u3068\u3044\u3046\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u624b\u306b\u5165\u308c\u305f<\/a>\u3001\u3068\u3044\u3046\u8a71\u306e\u7d9a\u304d\u3060\u3002<\/p>\n\n\n\n<p>M5StickC\u3068ENV HAT\u3092\u4f7f\u3063\u3066\u3001\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc+\u52a0\u901f\u5ea6\u30bb\u30f3\u30b5\u30fc+\u5730\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306e9DoF\u3092\u8a66\u3057\u3066\u307f\u308b\u3002<\/p>\n\n\n\n<p>Arduino IDE\u3067<a href=\"http:\/\/kako.com\/blog\/?p=46476\">\u524d\u56de\u8a66\u3057\u3066\u307f\u305fENV-HAT\u7528\u306eENV\u3068\u3044\u3046example\u306e\u30b9\u30b1\u30c3\u30c1<\/a>\u306b\u624b\u3092\u5165\u308c\u3066\u4f5c\u3063\u3066\u307f\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"640\" height=\"480\" src=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244.jpg\" alt=\"\" class=\"wp-image-46575\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc+\u52a0\u901f\u5ea6\u30bb\u30f3\u30b5\u30fc+\u5730\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306e9\u3064\u306e\u5024\u306e\u8a08\u6e2c\u3092\u884c\u3044\u3001\u8a08\u6e2c\u5024\u3092\u6db2\u6676\u306b\u8868\u793a\u3057\u3001UART\u306b\u8a08\u6e2c\u5024\u306e9\u3064\u306e\u5024\u3092\u51fa\u529b\u3057\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u6b21\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u305f\u3002(bmm150.cpp\u3001bmm150.h\u3001bmm150_defs.h\u304c\u30d3\u30eb\u30c9\u306b\u306f\u5fc5\u8981\u306a\u306e\u3067\u6ce8\u610f\u3002)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &lt;M5StickC.h&gt;\n#include &lt;Wire.h&gt;\n#include &quot;bmm150.h&quot;\n#include &quot;bmm150_defs.h&quot;\n\nBMM150 bmm = BMM150();\n\nfloat gyroX,gyroY,gyroZ;\nfloat accX,accY,accZ;\nfloat magX,magY,magZ;\nfloat t,t0;\nfloat magXofs,magYofs,magZofs;\nfloat magXmax,magYmax,magZmax;\nfloat magXmin,magYmin,magZmin;\nint calibration_mode;\n\nvoid setup() {\n  \/\/ put your setup code here, to run once:\n  M5.begin();\n  Serial.begin(115200);\n  Wire.begin(0,26);\n  M5.IMU.Init();\n  pinMode(M5_BUTTON_HOME, INPUT);\n  M5.Lcd.setRotation(3);\n  M5.Lcd.fillScreen(BLACK);\n  M5.Lcd.setTextSize(1);\n  M5.Lcd.setCursor(20, 0);\n  M5.Lcd.println(&quot;9DoF TEST (w\/ENV-HAT)&quot;);\n  M5.Lcd.setCursor(0, 10);\n  M5.Lcd.println(&quot;  X       Y       Z&quot;);\n  if(bmm.initialize() == BMM150_E_ID_NOT_CONFORM) {\n    M5.Lcd.setCursor(0, 10);\n    M5.Lcd.println(&quot;BMM150(ENV-HAT) not found!&quot;);\n    while(1);\n  }\n  t=0; t0=0;\n  calibration_mode=0;\n  magXofs=0;\n  magYofs=0;\n  magZofs=0;\n}\n\nvoid loop() {\n  \/\/ put your main code here, to run repeatedly:\n  M5.IMU.getGyroData(&amp;gyroX,&amp;gyroY,&amp;gyroZ);\n  M5.IMU.getAccelData(&amp;accX,&amp;accY,&amp;accZ);\n  bmm.read_mag_data();\n  magX = bmm.raw_mag_data.raw_datax;\n  magY = bmm.raw_mag_data.raw_datay;\n  magZ = bmm.raw_mag_data.raw_dataz;\n\n  if (calibration_mode==1) {\n    if (magX&gt;magXmax) { magXmax=magX; }\n    if (magX&lt;magXmin) { magXmin=magX; }\n    if (magY&gt;magYmax) { magYmax=magY; }\n    if (magY&lt;magYmin) { magYmin=magY; }\n    if (magZ&gt;magZmax) { magZmax=magZ; }\n    if (magZ&lt;magZmin) { magZmin=magZ; }\n  }\n  if (digitalRead(M5_BUTTON_HOME) == LOW) {\n    if (calibration_mode==0) {\n      calibration_mode=1;\n      magXmax=magX; magXmin=magX;\n      magYmax=magY; magYmin=magY;\n      magZmax=magZ; magZmin=magZ;\n    } else {\n      calibration_mode=0;\n      magXofs=(magXmax+magXmin)\/2;\n      magYofs=(magYmax+magYmin)\/2;\n      magZofs=(magZmax+magZmin)\/2;\n    }\n    delay(500);\n  }\n\n  magX = magX - magXofs;\n  magY = magY - magYofs;\n  magZ = magZ - magZofs;\n\n  t0=t; t=millis();\n\n  M5.Lcd.setCursor(0, 20);\n  M5.Lcd.printf(&quot;%6.2f  %6.2f  %6.2f      &quot;, gyroX, gyroY, gyroZ);\n  M5.Lcd.setCursor(140, 20);\n  M5.Lcd.print(&quot;o\/s&quot;);\n  M5.Lcd.setCursor(0, 30);\n  M5.Lcd.printf(&quot; %5.2f   %5.2f   %5.2f   &quot;, accX, accY, accZ);\n  M5.Lcd.setCursor(140, 30);\n  M5.Lcd.print(&quot;G&quot;);\n  M5.Lcd.setCursor(0, 40);\n  M5.Lcd.printf(&quot; %5.0f   %5.0f   %5.0f   &quot;, magX, magY, magZ);\n  M5.Lcd.setCursor(140, 40);\n  M5.Lcd.print(&quot;uT&quot;);\n  M5.Lcd.setCursor(0, 70);\n  M5.Lcd.printf(&quot;  dt=%.0f    &quot;, t-t0);\n  M5.Lcd.setCursor(140, 70);\n  if (calibration_mode==1) {\n    M5.Lcd.printf(&quot;CAL&quot;);\n  } else {\n    M5.Lcd.printf(&quot;   &quot;);\n  }\n\n  Serial.print(gyroX); Serial.print(&quot;,&quot;);\n  Serial.print(gyroY); Serial.print(&quot;,&quot;);\n  Serial.print(gyroZ); Serial.print(&quot;,&quot;);\n  Serial.print(accX); Serial.print(&quot;,&quot;);\n  Serial.print(accY); Serial.print(&quot;,&quot;);\n  Serial.print(accZ); Serial.print(&quot;,&quot;);\n  Serial.print(magX); Serial.print(&quot;,&quot;);\n  Serial.print(magY); Serial.print(&quot;,&quot;);\n  Serial.print(magZ); Serial.println(&quot;&quot;);\n}\n<\/pre><\/div>\n\n\n<p>\u5b9f\u884c\u3059\u308b\u3068\u3001\u3053\u306e\u3088\u3046\u306a\u6db2\u6676\u753b\u9762\u306e\u8868\u793a\u3068\u306a\u308b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"640\" height=\"480\" src=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244.jpg\" alt=\"\" class=\"wp-image-46575\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2019\/12\/Img_0244-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc\u306eX,Y,Z\u8ef8\u306e\u8a08\u6e2c\u5024\u3068\u3001<br>\u52a0\u901f\u5ea6\u30bb\u30f3\u30b5\u30fc\u306eX,Y,Z\u8ef8\u306e\u8a08\u6e2c\u5024\u3068\u3001<br>\u5730\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306eX,Y,Z\u8ef8\u306e\u8a08\u6e2c\u5024\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<p>\u3042\u3068\u3001\u6e2c\u5b9a\u5468\u671f\u304cdt\u3068\u3057\u3066\u30df\u30ea\u79d2\u5358\u4f4d\u3067\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3002\u4eca\u56de\u306e\u5834\u54089\u30df\u30ea\u79d2\u304c\u6e2c\u5b9a\u5468\u671f\u3068\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5730\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306e\u30ad\u30e3\u30ea\u30d6\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30bd\u30d5\u30c8\u3092\u81ea\u524d\u3067\u4f5c\u308a\u76f4\u3057\u3066\u3044\u308b\u3002<br> \u672c\u5f53\u306f\u3082\u3063\u3068\u3061\u3083\u3093\u3068\u3057\u305f\u30ad\u30e3\u30ea\u30d6\u30ec\u30fc\u30b7\u30e7\u30f3\u30bd\u30d5\u30c8\u3082\u4f5c\u308c\u308b\u306e\u3060\u304c\u3001\u3068\u308a\u3042\u3048\u305a\u5143\u306eENV\u306eexample\u30b9\u30b1\u30c3\u30c1\u3068\u540c\u69d8\u306a\u7c21\u6613\u7248\u3092\u66f8\u3044\u305f\u3002(\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306e\u30ad\u30e3\u30ea\u30d6\u30ec\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u611f\u5ea6\u307e\u3067\u5408\u308f\u305b\u3088\u3046\u3068\u3059\u308b\u3068\u3061\u3087\u3063\u3068\u8a08\u7b97\u304c\u5927\u5909\u3067\u3001\u6614\u305d\u3046\u3044\u3046\u306e\u3092\u958b\u767a\u3059\u308b\u4ed5\u4e8b\u3092\u3057\u3066\u305f\u3002)<br> \u3068\u308a\u3042\u3048\u305a\u4eca\u56de\u5b9f\u88c5\u3057\u305f\u306e\u306f\u3001\u66ab\u304f\u6e2c\u5b9a\u3057\u3066\u6700\u5927\u6700\u5c0f\u306e\u4e2d\u9593\u3092\u539f\u70b9\u30aa\u30d5\u30bb\u30c3\u30c8\u306b\u3059\u308b\u3068\u3044\u3046\u7c21\u6613\u306a\u30ad\u30e3\u30ea\u30d6\u30ec\u30fc\u30b7\u30e7\u30f3\u65b9\u6cd5\u306e\u3082\u306e\u3060\u3002<\/p>\n\n\n\n<p>\u4f7f\u3044\u65b9\u3068\u3057\u3066\u306f\u3001<br> (1)HOME\u30dc\u30bf\u30f3(M5\u306e\u30ed\u30b4\u306e\u30dc\u30bf\u30f3)\u30921\u5ea6\u62bc\u3059\u3068\u3001\u753b\u9762\u306b\u300cCAL\u300d\u3068\u8868\u793a\u3055\u308c\u308b\u3002\u30ad\u30e3\u30ea\u30d6\u30ec\u30fc\u30b7\u30e7\u30f3(Calibration)\u4e2d\u3067\u3042\u308b\u3068\u3044\u3046\u8868\u793a\u3060\u3002<br> (2)CAL\u8868\u793a\u4e2d\u306b\u3001M5StickC+ENV HAT\u3092\u3001\u6c34\u5e73\u306b\u00b1180\u5ea6\u56de\u3059\u3088\u3046\u306bYaw\u65b9\u5411\u306b\u52d5\u304b\u3057\u3001\u6b21\u306b\u3001Roll\u65b9\u5411\u306b\u3082\u00b1180\u5ea6\u56de\u3059\u3088\u3046\u306b\u52d5\u304b\u3057\u3001Pitch\u65b9\u5411\u306b\u3082\u00b1180\u5ea6\u56de\u3059\u3088\u3046\u306b\u52d5\u304b\u3059\u3002<br> (3)\u52d5\u304b\u3057\u7d42\u308f\u3063\u305f\u3089\u3001HOME\u30dc\u30bf\u30f3(M5\u306e\u30ed\u30b4\u306e\u30dc\u30bf\u30f3)\u30921\u5ea6\u62bc\u3059\u3068\u3001\u30ad\u30e3\u30ea\u30d6\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u7d42\u4e86\u3057\u3001\u52d5\u304b\u3057\u3066\u3044\u305f\u9593\u306e\u78c1\u6c17\u30bb\u30f3\u30b5\u30fcX,Y,Z\u8ef8\u305d\u308c\u305e\u308c\u306e\u8a08\u6e2c\u5024\u306e\u6700\u5927\u5024\u3068\u6700\u5c0f\u5024\u306e\u4e2d\u9593\u3092\u539f\u70b9\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u5024\u3068\u3057\u3066\u63a1\u7528\u3059\u308b\u3002\u753b\u9762\u306eCAL\u8868\u793a\u306f\u6d88\u3048\u308b\u3002<br> \u3068\u3044\u3046\u4f7f\u3044\u65b9\u3068\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001\u8a08\u6e2c\u5024\u306fUART\u306b\u51fa\u529b\u3055\u308c\u308b\u3002<br> Arduino IDE\u306e\u30b7\u30ea\u30a2\u30eb\u30b3\u30f3\u30bd\u30fc\u30eb\u3067115200bps\u3067\u8868\u793a\u3055\u305b\u308b\u3068\u3001\u78ba\u8a8d\u3067\u304d\u308b\u3002\u3042\u308b\u3044\u306fWindows PC\u3067TeraTerm\u306a\u3069\u3092\u4f7f\u3063\u3066\u53d7\u4fe1\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3060\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>&#8212;<br>9DoF\u306eMadgwick\u30d5\u30a3\u30eb\u30bf\u30fc\u3068\u3044\u3046\u306e\u3092\u4f7f\u3063\u3066\u3001M5StickC\u306e\u59ff\u52e2(Roll,Pitch,Yaw)\u3092\u8a08\u7b97\u3055\u305b\u308b\u3068\u3044\u3046\u306e\u3092\u3053\u308c\u304b\u3089\u8a66\u3057\u3066\u307f\u308b\u3002(\u524d\u63d0\u3068\u3057\u3066\u3001\u305d\u308c\u305e\u308c\u306e\u30bb\u30f3\u30b5\u30fc\u306eX,Y,Z\u8ef8\u3068\u304b\u6975\u6027\u3068\u304b\u5408\u308f\u305b\u3066\u304a\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u304b?)<\/p>\n\n\n\n<p>\u3042\u3068\u3001\u6709\u7dda\u306eUART\u3067\u306a\u304f\u3066\u3001\u4ee3\u308f\u308a\u306bBluetooth SPP\u3067\u7121\u7ddaUART\u306b\u51fa\u529b\u3059\u308b\u306e\u3082\u8a66\u3057\u3066\u307f\u308b\u4e88\u5b9a\u3060\u3002<\/p>\n\n\n\n<p>\u8155\u6642\u8a08\u30bf\u30a4\u30d7\u306e\u30d0\u30f3\u30c9\u3092\u4f7f\u3063\u3066\u8155\u306b\u53d6\u308a\u4ed8\u3051\u3066\u3001\u30e2\u30fc\u30b7\u30e7\u30f3\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u7684\u306b\u4f7f\u3063\u3066\u307f\u3088\u3046\u3068\u8003\u3048\u3066\u3044\u308b\u3002 1\u500b\u3060\u3051\u3060\u3068\u672c\u7269\u306e\u30e2\u30fc\u30b7\u30e7\u30f3\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u307f\u305f\u3044\u306a\u4f7f\u3044\u65b9\u306f\u3067\u304d\u306a\u3044\u3051\u3069\u3001\u304b\u3068\u3044\u3063\u3066\u8907\u6570\u3092\u540c\u6642\u306bPC\u306b\u3064\u306a\u3050\u30bd\u30d5\u30c8\u3092\u4f5c\u308d\u3046\u3068\u3059\u308b\u3068\u9762\u5012\u305d\u3046\u3060\u3002 <\/p>\n\n\n\n<p>\u3064\u3065\u304f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>M5StickC\u306b\u53d6\u308a\u4ed8\u3051\u308bENV HAT\u3068\u3044\u3046\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u624b\u306b\u5165\u308c\u305f\u3001\u3068\u3044\u3046\u8a71\u306e\u7d9a\u304d\u3060\u3002 M5StickC\u3068ENV HAT\u3092\u4f7f\u3063\u3066\u3001\u30b8\u30e3\u30a4\u30ed\u30bb\u30f3\u30b5\u30fc+\u52a0\u901f\u5ea6\u30bb\u30f3\u30b5\u30fc+\u5730\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306e9DoF\u3092\u8a66\u3057\u3066\u307f\u308b\u3002 Ardu [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,16],"tags":[],"_links":{"self":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/46574"}],"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=46574"}],"version-history":[{"count":7,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/46574\/revisions"}],"predecessor-version":[{"id":46582,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/46574\/revisions\/46582"}],"wp:attachment":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=46574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=46574"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=46574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}