{"id":47485,"date":"2020-02-14T13:43:02","date_gmt":"2020-02-14T04:43:02","guid":{"rendered":"http:\/\/kako.com\/blog\/?p=47485"},"modified":"2020-02-14T13:47:28","modified_gmt":"2020-02-14T04:47:28","slug":"m5stickc%e7%94%a8%e3%81%ab%e7%a3%81%e6%b0%97%e3%82%bb%e3%83%b3%e3%82%b5%e3%83%bchmc5883%e3%81%aehat%e3%82%92%e8%87%aa%e4%bd%9c%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"http:\/\/kako.com\/blog\/?p=47485","title":{"rendered":"M5StickC\u7528\u306b\u78c1\u6c17\u30bb\u30f3\u30b5\u30fcHMC5883\u306eHAT\u3092\u81ea\u4f5c\u3057\u3066\u307f\u305f"},"content":{"rendered":"\n<p>M5StickC\u7528\u306b\u78c1\u6c17\u30bb\u30f3\u30b5\u30fcHMC5883\u306eHAT\u3092\u81ea\u4f5c\u3057\u3066\u307f\u305f\u3002<br><a href=\"http:\/\/kako.com\/blog\/?p=47476\">PROTO-HAT<\/a>\u3092\u4f7f\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\/2020\/02\/Img_1894.jpg\" alt=\"\" class=\"wp-image-47486\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1894.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1894-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1894-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306eHMC5883\u306f\u96fb\u5b50\u30b3\u30f3\u30d1\u30b9\u7528\u306e\u9ad8\u7cbe\u5ea6\u306a\u3082\u306e\u3067\u3001Amazon\u3067\u58f2\u3063\u3066\u3044\u308b\u30d6\u30ec\u30fc\u30af\u30a2\u30a6\u30c8\u57fa\u677f\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u8cb7\u3063\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\/2020\/02\/Img_1872.jpg\" alt=\"\" class=\"wp-image-47487\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1872.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1872-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1872-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><a rel=\"noreferrer noopener\" target=\"_blank\" href=\"https:\/\/www.amazon.co.jp\/gp\/product\/B075N8Z4FC\/ref=as_li_tl?ie=UTF8&amp;camp=247&amp;creative=1211&amp;creativeASIN=B075N8Z4FC&amp;linkCode=as2&amp;tag=gid023014-22&amp;linkId=a06b4129884830453323546bb91f45df\">GY-271 QMC5883L 3\u8ef8\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc \u78c1\u5834\u30bb\u30f3\u30b5\u30fc \u96fb\u5b50 \u30c7\u30b8\u30bf\u30eb \u30b3\u30f3\u30d1\u30b9 \u30e2\u30b8\u30e5\u30fc\u30eb \u5730\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc<\/a> (Amazon)<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u306a\u305cHMC5883\u304b\u3068\u3044\u3046\u3068\u3001\u4ed6\u306e\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u3088\u308a\u3082\u9ad8\u7cbe\u5ea6\u306b\u5730\u78c1\u6c17\u3092\u6e2c\u5b9a\u3057\u305f\u304b\u3063\u305f\u304b\u3089\u3060\u3002<br><a href=\"http:\/\/kako.com\/blog\/?p=47466\">M5StickC\u306e\u672c\u4f53\u306b\u5185\u8535\u3055\u308c\u3066\u3044\u308b\u5f37\u529b\u306a\u78c1\u77f3\u304c\u90aa\u9b54\u306a\u306e\u3067\u3001\u524d\u3082\u3063\u3066M5StickC\u3092\u5206\u89e3\u3057\u3066\u78c1\u77f3\u3092\u53d6\u308a\u9664\u3044\u305f<\/a>\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>HMC5883\u306e\u30d6\u30ec\u30fc\u30af\u30a2\u30a6\u30c8\u57fa\u677f\u3092PROTO-HAT\u306e\u57fa\u677f\u306b\u5b9f\u88c5\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001PROTO\u306e\u4e2d\u306e\u57fa\u677f\u304c\u5c0f\u3055\u3044\u306e\u3067 \u3061\u3087\u3063\u3068\u53d6\u308a\u4ed8\u3051\u65b9\u6cd5\u3067\u60a9\u3080\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\/2020\/02\/Img_1872a.jpg\" alt=\"\" class=\"wp-image-47488\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1872a.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1872a-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1872a-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>\u3061\u3087\u3063\u3068\u8003\u3048\u3066\u3001\u3053\u306e\u3088\u3046\u306aL\u5b57\u578b\u306e\u90e8\u54c1\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\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\/2020\/02\/Img_1877.jpg\" alt=\"\" class=\"wp-image-47489\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1877.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1877-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1877-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\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\/2020\/02\/Img_1880.jpg\" alt=\"\" class=\"wp-image-47490\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1880.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1880-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1880-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>\u57fa\u677f\u306e\u53cd\u5bfe\u5074\u306e\u9762\u3067\u914d\u7dda\u3092\u7e4b\u3050\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\/2020\/02\/Img_1881.jpg\" alt=\"\" class=\"wp-image-47491\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1881.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1881-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1881-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>\u96fb\u6e90\u306e3.3V\u3068GND\u3001I2C\u306eSDA\u3068SCL\u3092IO\u30d4\u30f3\u756a\u53f70\u306826\u306b\u63a5\u7d9a\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u30b1\u30fc\u30b9\u306b\u5165\u308c\u3066\u3001\u5b8c\u6210\u3060\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"640\" height=\"494\" src=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1886.jpg\" alt=\"\" class=\"wp-image-47492\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1886.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1886-300x232.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1886-624x482.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>M5StickC\u306b\u53d6\u308a\u4ed8\u3051\u308b\u3068\u3001\u3053\u3093\u306a\u611f\u3058\u3060\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\/2020\/02\/Img_1893.jpg\" alt=\"\" class=\"wp-image-47493\" srcset=\"http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1893.jpg 640w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1893-300x225.jpg 300w, http:\/\/kako.com\/blog\/wp\/wp-content\/uploads\/2020\/02\/Img_1893-624x468.jpg 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>&#8212;<br>\u30bd\u30d5\u30c8\u306f\u3001Adafruit_HMC5883_U\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u305f\u3002\u305f\u3060\u3057\u3001I2C\u306e\u30d4\u30f3\u3092HAT\u7528\u306e\u5272\u308a\u5f53\u3066\u76f4\u3057\u3092\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u672c\u4f53\u3092\u66f8\u304d\u63db\u3048\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/adafruit\/Adafruit_HMC5883_Unified\">GitHub\u306e\u3053\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30da\u30fc\u30b8<\/a>\u304b\u3089\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3057\u3066\u3001Arduino\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30d5\u30a9\u30eb\u30c0\u30fc\u306b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30bd\u30fc\u30b9\u3092\u5165\u308c\u3066\u3001\u305d\u308c\u3092\u66f8\u304d\u63db\u3048\u308b\u3068\u3044\u3046\u3084\u308a\u65b9\u3067\u66f8\u304d\u63db\u3048\u305f\u3002<\/p>\n\n\n\n<p>\u66f8\u304d\u63db\u3048\u305f\u7b87\u6240\u306f\u3001I2C\u306e\u521d\u671f\u5316\u51e6\u7406\u306e<br>Wire.begin();<br>\u3068\u3044\u3046\u90e8\u5206\u3092\u3001<br>Wire.begin(0,26);<br>\u3068\u5909\u66f4\u3057\u305f\u3002I2C\u306b\u4f7f\u7528\u3059\u308bI\/O\u30d4\u30f3\u3092HAT\u30b3\u30cd\u30af\u30bf\u306e\u30d4\u30f3\u306b\u5909\u66f4\u3059\u308b\u3068\u3044\u3046\u5909\u66f4\u3060\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u3068\u308a\u3042\u3048\u305a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u52d5\u4f5c\u3055\u305b\u3066\u307f\u305f\u3002<br>\u524d\u306b<a href=\"http:\/\/kako.com\/blog\/?p=46574\">M5StickC\u3068ENV-HAT\u306e\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u52d5\u304b\u3059\u30bd\u30d5\u30c8\u3092\u4f5c\u3063\u3066\u3044\u305f<\/a>\u306e\u3067\u3001\u305d\u308c\u3092\u5143\u306b\u6539\u9020\u3057\u3066\u30bd\u30d5\u30c8\u3092\u66f8\u3044\u305f\u3002<br>\u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306e\u51fa\u529b\u5024\u306e\u7269\u7406\u5358\u4f4d(\u03bcT)\u3068\u304b\u306f\u5408\u3063\u3066\u306a\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u306e\u3067\u3001\u3042\u3068\u3067\u8abf\u3079\u3066\u76f4\u3057\u305f\u307b\u3046\u304c\u3088\u3055\u305d\u3046\u3060\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\n#include &lt;Adafruit_Sensor.h&gt;\n#include &quot;Adafruit_HMC5883_U.h&quot;\nAdafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);\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;\nint error=0;\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\n  \/* Initialise the sensor *\/\n  if(!mag.begin())\n  {\n    \/* There was a problem detecting the HMC5883 ... check your connections *\/\n    Serial.println(&quot;Ooops, no HMC5883 detected ... Check your wiring!&quot;);\n    while(1);\n  }\n  \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\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  \n  \/* Get a new sensor event *\/ \n  sensors_event_t event; \n  mag.getEvent(&amp;event);\n\n  magX = event.magnetic.x;\n  magY = event.magnetic.y;\n  magZ = event.magnetic.z;\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\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>M5StickC\u7528\u306b\u78c1\u6c17\u30bb\u30f3\u30b5\u30fcHMC5883\u306eHAT\u3092\u81ea\u4f5c\u3057\u3066\u307f\u305f\u3002PROTO-HAT\u3092\u4f7f\u3063\u3066\u307f\u305f\u3002 \u78c1\u6c17\u30bb\u30f3\u30b5\u30fc\u306eHMC5883\u306f\u96fb\u5b50\u30b3\u30f3\u30d1\u30b9\u7528\u306e\u9ad8\u7cbe\u5ea6\u306a\u3082\u306e\u3067\u3001Amazon\u3067\u58f2\u3063\u3066\u3044\u308b\u30d6\u30ec\u30fc\u30af\u30a2\u30a6\u30c8\u57fa\u677f\u30e2\u30b8\u30e5\u30fc\u30eb\u3092 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/47485"}],"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=47485"}],"version-history":[{"count":3,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/47485\/revisions"}],"predecessor-version":[{"id":47496,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/47485\/revisions\/47496"}],"wp:attachment":[{"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=47485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=47485"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kako.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=47485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}