{"id":2669,"date":"2023-09-11T21:46:38","date_gmt":"2023-09-11T12:46:38","guid":{"rendered":"https:\/\/mattyan.net\/blog\/?p=2669"},"modified":"2023-09-11T21:46:38","modified_gmt":"2023-09-11T12:46:38","slug":"esp32%e3%81%a7bme680%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/mattyan.net\/blog\/?p=2669","title":{"rendered":"ESP32\u3067BME680\u3092\u4f7f\u3063\u3066\u307f\u305f"},"content":{"rendered":"\n<p><a href=\"https:\/\/mattyan.net\/blog\/?p=2657\" data-type=\"link\" data-id=\"https:\/\/mattyan.net\/blog\/?p=2657\">\u6628\u65e5\u306e\u4fee\u6b63<\/a>\u3067BME680\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u6e29\u5ea6\u3068\u6e7f\u5ea6\u3068\u6c17\u5727\u3092\u6e2c\u3063\u3066\u96fb\u5727\u3068\u4e00\u7dd2\u306bWeb\u30b5\u30fc\u30d0\u30fc\u306bPOST\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u653e\u7f6e\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001\u7a81\u7136\u30c7\u30fc\u30bf\u304c\u9001\u4fe1\u3055\u308c\u306a\u3044\u30d0\u30b0\u306b\u906d\u9047\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u8abf\u67fb\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001BME680\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u30d0\u30b0\u3063\u3066\u305f\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">\u75c7\u72b6<\/h2>\n\n\n\n<p>\u7a81\u7136\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u4e00\u5207\u306e\u30ed\u30b0\u3082\u5410\u304b\u305a\u306b\u52d5\u304b\u306a\u304f\u306a\u3063\u305f\u3002\u30ab\u30fc\u30cd\u30eb\u30d1\u30cb\u30c3\u30af\u3068\u304b\u306e\u30ed\u30b0\u3082\u306a\u304f\u3002\u4e00\u5207\u52d5\u304b\u306a\u304f\u306a\u308b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u539f\u56e0\u8abf\u67fb<\/h2>\n\n\n\n<p>\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u305f\u3081\u306e\u6a5f\u5668\u3092\u3082\u3063\u3066\u306a\u3044\u306e\u3067\u3001\u6614\u306a\u304c\u3089\u306eprintf\u30c7\u30d0\u30c3\u30b0\u3002\u7247\u3063\u7aef\u304b\u3089\u30ed\u30b0\u4ed5\u8fbc\u3093\u3067\u3001\u3069\u3053\u307e\u3067\u52d5\u3044\u3066\u308b\u306e\u304b\u3001\u3069\u3053\u3067\u6b62\u307e\u3063\u3066\u308b\u306e\u304b\u3092\u78ba\u8a8d\u3002<\/p>\n\n\n\n<p>\u6700\u7d42\u7684\u306b\u305f\u3069\u308a\u7740\u3044\u305f\u306e\u304c<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-c\" data-line=\"\">static void bme680_delay_ms(uint32_t period)\n{\n    uint32_t start_time = sdk_system_get_time () \/ 1000;\n\n    vTaskDelay((period + portTICK_PERIOD_MS-1) \/ portTICK_PERIOD_MS);\n\n    while (sdk_system_get_time()\/1000 - start_time &lt; period)\n        vTaskDelay (1);\n}<\/code><\/pre>\n\n\n\n<p>bmc680.c\u306b\u3042\u3063\u305f\u3053\u306e\u95a2\u6570\u3002\u6307\u5b9a\u6642\u9593\u3088\u308a\u82e5\u5e72\u77ed\u3081\u306bdelay\u3057\u305f\u3042\u3068\u3001\u6642\u523b\u78ba\u8a8d\u3057\u306a\u304c\u3089delay\u3092\u5fae\u8abf\u6574\u3057\u3066\u308b\u3063\u307d\u3044\u3002<\/p>\n\n\n\n<p>\u3053\u3053\u306ewhile\u306b\u30ed\u30b0\u4ed5\u8fbc\u3093\u3067start_time\u3068sdk_system_get_time()\/1000\u306e\u5024\u3092\u51fa\u3057\u3066\u307f\u305f\u3068\u3053\u308d<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/mattyan.net\/blog\/wp-content\/uploads\/2023\/09\/stop-1024x612.png\" alt=\"\" class=\"wp-image-2670\"\/><figcaption class=\"wp-element-caption\">\u6642\u9593\u304c\u9032\u307e\u306a\u3044<\/figcaption><\/figure>\n<\/div>\n\n\n<p>sdk_system_get_time()\/1000\u306e\u5024\u304c4294967\u3067\u56fa\u307e\u3063\u305f\u307e\u307e\u52d5\u304b\u305a\u3001\u3053\u3053\u3067\u7121\u9650\u30eb\u30fc\u30d7\u306b\u306a\u3063\u3066\u305f\u3002(Exception\u4e91\u3005\u306f\u3001idf.py monitor\u3092\u6b62\u3081\u305f\u3068\u304d\u306e\u3082\u306e)<\/p>\n\n\n\n<p>\u7d9a\u3044\u3066sdk_system_get_time()\u3092\u78ba\u8a8d<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-c\" data-line=\"\">uint32_t sdk_system_get_time ()\n{\n    struct timeval time;\n    gettimeofday(&amp;time,0);\n    return time.tv_sec*1e6 + time.tv_usec;\n}<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u306fesp8266_wrapper.c\u306b\u3042\u3063\u305f\u3002gettimeofday\u3067\u79d2\u3068\u30de\u30a4\u30af\u30ed\u79d2\u3092\u53d6\u5f97\u3057\u3001\u79d2\u309210<sup>6<\/sup>\u500d\u3057\u3066\u305d\u308c\u3068\u30de\u30a4\u30af\u30ed\u79d2\u3092\u8db3\u3057\u7b97\u3057\u305fuint32_t\u3092\u8fd4\u3057\u3066\u308b\u3002<\/p>\n\n\n\n<p>\u3067\u3001\u305d\u308c\u30921000\u3067\u5272\u3063\u3066\u30df\u30ea\u79d2\u306b\u5909\u63db\u3057\u3066\u5f85\u3061\u6642\u9593\u6bd4\u8f03\u306b\u4f7f\u3063\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p>\u3053\u3053\u3067\u3061\u3087\u3063\u3068\u6c17\u306b\u306a\u3063\u3066<a href=\"https:\/\/cpprefjp.github.io\/reference\/cstdint\/uint32_max.html\" data-type=\"link\" data-id=\"https:\/\/cpprefjp.github.io\/reference\/cstdint\/uint32_max.html\">uint32_t\u306e\u6700\u5927\u5024<\/a>\u3092\u898b\u3066\u307f\u305f\u3089\u300c4294967295\u300d\u30021000\u3067\u5272\u3063\u305f\u3089\u300c4294967\u300d\u3067\u56fa\u307e\u3063\u305f\u3068\u304d\u306e\u5024\u3068\u4e00\u81f4\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u300c\u591a\u5206\u3053\u308c\u3001\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3057\u3066\u8a08\u7b97\u3067\u304d\u306a\u304f\u306a\u3063\u305f\u3093\u304b\u306a?\u300d\u3068\u601d\u3044\u3001\u4fee\u6b63<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4fee\u6b63<\/h2>\n\n\n\n<p>\u30de\u30a4\u30af\u30ed\u79d2\u3092\u8db3\u3057\u305f\u5024\u3092\u4f7f\u304a\u3046\u306b\u3082\u4f7f\u3044\u7269\u306b\u306a\u3089\u306a\u3044\u306e\u3067\u3001\u65b9\u91dd\u5909\u66f4\u3002<\/p>\n\n\n\n<p>gettimeofday()\u3067\u53d6\u5f97\u3067\u304d\u308btimeval\u69cb\u9020\u4f53\u306b\u306f\u305d\u308c\u3092\u8a08\u7b97\u3092\u3059\u308b\u95a2\u6570\u304c\u3042\u308b\u306e\u3067\u3001\u300ctimeval\u540c\u58eb\u3067\u8a08\u7b97\u3057\u3066\u7d4c\u904e\u6642\u9593\u3092\u53d6\u5f97\u3057\u3066\u304b\u3089\u5909\u63db\u3057\u3066\u6bd4\u8f03\u300d\u3059\u308b\u65b9\u91dd\u3067\u4fee\u6b63\u3002<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-c\" data-line=\"\">static void bme680_delay_ms(uint32_t period)\n{\n    struct timeval start_timeval, now_timeval, difference_timeval;\n    gettimeofday(&amp;start_timeval, NULL);\n\n    vTaskDelay((period + portTICK_PERIOD_MS-1) \/ portTICK_PERIOD_MS);\n\n    gettimeofday(&amp;now_timeval, NULL);\n    timersub(&amp;now_timeval, &amp;start_timeval, &amp;difference_timeval);\n    uint32_t difference_time = (difference_timeval.tv_sec * 1e6 + difference_timeval.tv_usec) \/ 1000;\n    while (difference_time &lt; period)\n    {\n        vTaskDelay (1);\n\n        gettimeofday(&amp;now_timeval, NULL);\n        timersub(&amp;now_timeval, &amp;start_timeval, &amp;difference_timeval);\n        difference_time = (difference_timeval.tv_sec * 1e6 + difference_timeval.tv_usec) \/ 1000;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u3044\u307e\u306e\u3068\u3053\u308d\u3053\u308c\u30672\u6642\u9593\u306f\u52d5\u3044\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f59\u8ac7<\/h2>\n\n\n\n<p>\u79d2\u309210<sup>6<\/sup>\u500d\u3057\u3066uint32_t\u306e\u6700\u5927\u5024\u306b\u5c4a\u304f\u3063\u3066\u3053\u3068\u306f\u3001\u6700\u5927\u30674294\u79d2\u307e\u3067\u3067\u7d041\u6642\u959311\u5206\u3061\u3087\u3063\u3068\u3002\u6700\u521d\u306b\u53cb\u4eba\u306b\u611a\u75f4\u3063\u305f\u3068\u304d\u306f\u300c1\u6642\u9593\u3061\u3087\u3063\u3068\u3067\u6b62\u307e\u308b\u300d\u3060\u3063\u305f\u306e\u3067\u3001\u3061\u3083\u3093\u3068\u6e2c\u3063\u3066\u305f\u308f\u3051\u3067\u3082\u306a\u3044\u306e\u306b\u610f\u5916\u3068\u3042\u3063\u3066\u305f\u3002<\/p>\n\n\n\n<p>gettimeofday()\u306f\u9014\u4e2d\u3067\u6642\u8a08\u304c\u5909\u308f\u308b\u3068\u5f71\u97ff\u3092\u53d7\u3051\u305f\u308a\u3001\u305d\u3082\u305d\u3082POSIX\u3067\u975e\u63a8\u5968\u306b\u306a\u3063\u305f\u3089\u3057\u3044\u3002\u3064\u307e\u308a\u3053\u308c\u3001NTP\u5b9f\u88c5\u3059\u308b\u3068\u304b\u3057\u3066\u52d5\u4f5c\u4e2d\u306bESP32\u306e\u6642\u8a08\u3092\u4fee\u6b63\u3059\u308b\u3068\u3001\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u3088\u3063\u3066\u306f\u307e\u305f\u30d0\u30b0\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002gettimeofday\u304c\u975e\u63a8\u5968\u306e\u4ef6\u306f\u3001clock_gettime()\u3067\u53d6\u5f97\u3059\u308b\u306e\u304c\u63a8\u5968\u3055\u308c\u3066\u308b\u3089\u3057\u3044\u3002<\/p>\n\n\n\n<p>\u300c\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3057\u3066\u8a08\u7b97\u3067\u304d\u306a\u304f\u306a\u3063\u305f\u300d\u3068\u601d\u3063\u3066\u3044\u308b\u3051\u3069\u3001\u672c\u5f53\u306b\u305d\u3046\u304b\u306f\u308f\u304b\u3089\u306a\u3044\u3002\u30a2\u30bb\u30f3\u30d6\u30e9\u8aad\u3081\u306a\u3044\u3057\u3001CPU\u306e\u4ed5\u69d8\u3082\u77e5\u3089\u306a\u3044\u3057\u3002\u305f\u3060\u3001\u5024\u304c\u9032\u307e\u306a\u304f\u3066\u7121\u9650\u30eb\u30fc\u30d7\u3057\u3066\u308b\u306e\u306f\u78ba\u304b\u306a\u3088\u3046\u3060\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Diff<\/h2>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-diff\" data-line=\"\">diff -cr a\/bme680\/bme680.c b\/bme680\/bme680.c\n*** a\/bme680\/bme680.c\t2023-09-10 17:24:28.864249600 +0900\n--- b\/bme680\/bme680.c\t2023-09-11 19:04:30.342671456 +0900\n***************\n*** 50,55 ****\n--- 50,56 ----\n\n  #include &lt;string.h&gt;\n  #include &lt;stdlib.h&gt;\n+ #include &lt;sys\/time.h&gt;\n\n  #include &quot;bme680_platform.h&quot;\n  #include &quot;bme680.h&quot;\n***************\n*** 1214,1225 ****\n\n  static void bme680_delay_ms(uint32_t period)\n  {\n!     uint32_t start_time = sdk_system_get_time () \/ 1000;\n\n      vTaskDelay((period + portTICK_PERIOD_MS-1) \/ portTICK_PERIOD_MS);\n\n!     while (sdk_system_get_time()\/1000 - start_time &lt; period)\n          vTaskDelay (1);\n  }\n\n\n--- 1215,1236 ----\n\n  static void bme680_delay_ms(uint32_t period)\n  {\n!     struct timeval start_timeval, now_timeval, difference_timeval;\n!     gettimeofday(&amp;start_timeval, NULL);\n\n      vTaskDelay((period + portTICK_PERIOD_MS-1) \/ portTICK_PERIOD_MS);\n\n!     gettimeofday(&amp;now_timeval, NULL);\n!     timersub(&amp;now_timeval, &amp;start_timeval, &amp;difference_timeval);\n!     uint32_t difference_time = (difference_timeval.tv_sec * 1e6 + difference_timeval.tv_usec) \/ 1000;\n!     while (difference_time &lt; period)\n!     {\n          vTaskDelay (1);\n+\n+         gettimeofday(&amp;now_timeval, NULL);\n+         timersub(&amp;now_timeval, &amp;start_timeval, &amp;difference_timeval);\n+         difference_time = (difference_timeval.tv_sec * 1e6 + difference_timeval.tv_usec) \/ 1000;\n+     }\n  }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u65e5\u306e\u4fee\u6b63\u3067BME680\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u6e29\u5ea6\u3068\u6e7f\u5ea6\u3068\u6c17\u5727\u3092\u6e2c\u3063\u3066\u96fb\u5727\u3068\u4e00\u7dd2\u306bWeb\u30b5\u30fc\u30d0\u30fc\u306bPOST\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u653e\u7f6e\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001\u7a81\u7136\u30c7\u30fc\u30bf\u304c\u9001\u4fe1\u3055\u308c\u306a\u3044\u30d0\u30b0\u306b\u906d\u9047\u3057\u305f\u3002 \u8abf\u67fb\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001BME &hellip; <a href=\"https:\/\/mattyan.net\/blog\/?p=2669\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">ESP32\u3067BME680\u3092\u4f7f\u3063\u3066\u307f\u305f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2669","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2669"}],"version-history":[{"count":0,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2669\/revisions"}],"wp:attachment":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}