<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to configurate MPU6886 for over 8G?  (Change MAX +&#x2F;-8G to +&#x2F;-16G)]]></title><description><![CDATA[<p dir="auto">Hi M5 community,<br />
I'm using the M5StickC PLUS2 as an accelerometer in my project. It seems that the M5 detected accelerations over 8G, so I need to configure the MPU6886 to measure accelerations above 8G. However, I couldn't find an option to increase the max acceleration range in the IMU. I'm not very familiar with M5 or C++ programming, so if my explanation is unclear, please feel free to point it out.</p>
<p dir="auto">Below is the actual measurement data, which is capped at +/-8G.<br />
<img src="/assets/uploads/files/1726575041214-761600f2-f947-479f-bf53-4da33ed1ac5a-image.png" alt="761600f2-f947-479f-bf53-4da33ed1ac5a-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">below is my project code, just in case.</p>
<pre><code>#include "M5StickCPlus2.h"

#define SAMPLE_PERIOD 10  // サンプリング間隔（ミリ秒）
#define BUFFER_SIZE 100     // 1秒間に10回データを保持する（100ms * 10 = 1秒）
#define THRESHOLD 3      // 加速度の閾値 (例: 1.5G)
#define STOP_DELAY 1000    // 閾値を超えてから1秒で記録停止（1000ミリ秒）

// 状態管理のためのenum定義
enum State { INITIAL_SCREEN, MEASURING, STOPPED, RESULT_SCREEN };
State currentState = INITIAL_SCREEN;  // 現在の状態を初期画面に設定

float accelX[BUFFER_SIZE];  // X軸加速度のバッファ
float accelY[BUFFER_SIZE];  // Y軸加速度のバッファ
float accelZ[BUFFER_SIZE];  // Z軸加速度のバッファ
int bufferIndex = 0;        // バッファの現在のインデックス
bool thresholdExceeded = false; // 閾値が超えたかどうかを管理
unsigned long thresholdExceededTime = 0;  // 閾値を超えた時刻を記録
float maxTotalAccel = 0;  // 最大合成加速度を記録する変数

void setup() {
    auto cfg = M5.config();
    StickCP2.begin(cfg);
    StickCP2.Display.setRotation(1);
    StickCP2.Display.setTextColor(GREEN);
    StickCP2.Display.setTextDatum(middle_center);
    StickCP2.Display.setFont(&amp;fonts::FreeSansBold9pt7b);
    StickCP2.Display.setTextSize(2);
    Serial.begin(115200);

    showInitialScreen();  // 初期画面を表示
}

void loop(void) {
    M5.update();  // ボタンの状態を更新

    if (M5.BtnA.wasPressed()) {  // G83ボタンが押されたら
        handleButtonPress();      // ボタン押下に応じた処理を行う
    }

    // 測定中の処理
    if (currentState == MEASURING) {
        measureShock();  // 加速度を測定
    }

    delay(SAMPLE_PERIOD);  // サンプリング間隔
}

// G83ボタンが押されたときの処理
void handleButtonPress() {
    switch (currentState) {
        case INITIAL_SCREEN:
            currentState = MEASURING;
            thresholdExceeded = false;
            maxTotalAccel = 0;  // 最大加速度をリセット
            showMeasuringScreen();
            break;
        case MEASURING:
            currentState = STOPPED;
            showStoppedScreen();
            break;
        case STOPPED:
            currentState = RESULT_SCREEN;
            sendBufferData();  // シリアル送信を開始
            showResultScreen();
            break;
        case RESULT_SCREEN:
            currentState = INITIAL_SCREEN;
            showInitialScreen();
            break;
    }
}

// 加速度測定を行う
void measureShock() {
    auto imu_update = StickCP2.Imu.update();
    if (imu_update) {
        auto data = StickCP2.Imu.getImuData();

        // リングバッファに加速度データを保存
        accelX[bufferIndex] = data.accel.x;
        accelY[bufferIndex] = data.accel.y;
        accelZ[bufferIndex] = data.accel.z;

        // バッファインデックスを更新（0～BUFFER_SIZE-1を循環）
        bufferIndex = (bufferIndex + 1) % BUFFER_SIZE;

        // 合成加速度を計算
        float totalAccel = sqrt(data.accel.x * data.accel.x +
                                data.accel.y * data.accel.y +
                                data.accel.z * data.accel.z);

        // 画面に加速度データを表示
        StickCP2.Display.setCursor(0, 40);
        StickCP2.Display.clear();  // 画面をクリア
        StickCP2.Display.printf("Accel: %.2f G\n", totalAccel);

        // 最大合成加速度を更新
        if (totalAccel &gt; maxTotalAccel) {
            maxTotalAccel = totalAccel;
        }

        // 閾値を超えたかどうかを確認
        if (totalAccel &gt; THRESHOLD &amp;&amp; !thresholdExceeded) {
            thresholdExceeded = true;
            thresholdExceededTime = millis();  // 閾値を超えた時刻を記録
            Serial.println("Threshold exceeded! Starting countdown...");
        }

        // 閾値を超えてから1秒が経過したら測定を停止
        if (thresholdExceeded &amp;&amp; (millis() - thresholdExceededTime &gt;= STOP_DELAY)) {
            currentState = STOPPED;
            showStoppedScreen();  // 測定終了画面を表示
        }
    }
}

// 初期画面を表示
void showInitialScreen() {
    StickCP2.Display.clear();
    StickCP2.Display.setCursor(0, 20);
    StickCP2.Display.printf("Press G83 to Start\n");
    int bat = StickCP2.Power.getBatteryLevel();
    StickCP2.Display.printf("BAT:%d%" , bat);

}

// 測定中画面を表示
void showMeasuringScreen() {
    StickCP2.Display.clear();
    StickCP2.Display.setCursor(0, 20);
    StickCP2.Display.printf("Measuring...");
}

// 測定停止画面を表示し、最大合成Gを表示する
void showStoppedScreen() {
    StickCP2.Display.clear();
    StickCP2.Display.setCursor(0, 20);
    StickCP2.Display.printf("Measurement Stopped\n");
    StickCP2.Display.printf("Max G: %.2f G\n", maxTotalAccel);
}

// 結果画面を表示
void showResultScreen() {
    StickCP2.Display.clear();
    StickCP2.Display.setCursor(0, 20);
    StickCP2.Display.printf("Results Sent via Serial");
}

// バッファ内のデータをすべてシリアル通信で送信
void sendBufferData() {
    int time = 10;  // 開始時間（ミリ秒単位）
    
    // CSV形式のヘッダーを送信
    Serial.println("TIME,ACCEL_X,ACCEL_Y,ACCEL_Z");
    
    // バッファ内のデータを送信
    for (int i = 0; i &lt; BUFFER_SIZE; i++) {
        // データのインデックスがリングバッファの先頭から始まるように調整
        int index = (bufferIndex + i) % BUFFER_SIZE;
        //Serial.printf("%d,%0.2f,%0.2f,%0.2f\r\n", time, accelX[index], accelY[index], accelZ[index]);
        Serial.printf("%0.2f,%0.2f,%0.2f\r\n", accelX[index], accelY[index], accelZ[index]);
        
        // 10ミリ秒ごとに時間を更新
        time += 10;
    }

    // データの送信終了を示すメッセージ
    Serial.println("---- END_OF_DATA ----");
}

</code></pre>
]]></description><link>https://community.m5stack.com/topic/6809/how-to-configurate-mpu6886-for-over-8g-change-max-8g-to-16g</link><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 07:51:33 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6809.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Sep 2024 12:13:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to configurate MPU6886 for over 8G?  (Change MAX +&#x2F;-8G to +&#x2F;-16G) on Tue, 01 Oct 2024 09:38:43 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a></p>
<p dir="auto">Thank you for your advice!<br />
It seems that I needed, I will try.</p>
]]></description><link>https://community.m5stack.com/post/26558</link><guid isPermaLink="true">https://community.m5stack.com/post/26558</guid><dc:creator><![CDATA[AKPK6271]]></dc:creator><pubDate>Tue, 01 Oct 2024 09:38:43 GMT</pubDate></item><item><title><![CDATA[Reply to How to configurate MPU6886 for over 8G?  (Change MAX +&#x2F;-8G to +&#x2F;-16G) on Wed, 25 Sep 2024 04:52:02 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/akpk6271" aria-label="Profile: AKPK6271">@<bdi>AKPK6271</bdi></a></p>
<p dir="auto">from what I can tell there is no public function to change the range from +/- 8 G to +/- 16 G.</p>
<p dir="auto">There is a non public function called <code>setAccelFsr(Ascale::AFS_8G)</code>.</p>
<p dir="auto">You could try to modify it <a href="https://github.com/m5stack/M5Unified/blob/master/src/utility/imu/MPU6886_Class.cpp#L61" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> to <code>setAccelFsr(Ascale::AFS_16G)</code>.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/26502</link><guid isPermaLink="true">https://community.m5stack.com/post/26502</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Wed, 25 Sep 2024 04:52:02 GMT</pubDate></item></channel></rss>