First App: BMM150/BMI270 IMU/AHRS Test

To me the best way to learn it to try things on an actual example. So decided to try interfacing the sensors to the MCU and sending/receiving data from the MPU. So this is from the readme I put together for my app.

A few things that I tried to accomplish with the app:

  1. Installing libraries. Local libraries on the pc are not available to the linux side. Have to redown load libraries.

  2. How to install packages that you might want to use

  3. How to transfer data back and forth

  4. And any gotchas

The app reads in data from the BMI270 and the BMM150 on the arduino side and transfers the accl/gyro/mag data to the linux side for process through a Madgwick filter using a AHRS package. Once processed Roll/Pitch/Yaw are transferred back to the Arduino.

Installing libraries

On the left side of AppLab Click on the Add libraries icon. When the pop up appears I had to actually type in the name of the whole name of the library

  • SparkFun BMI270 Arduino Library

  • DFRobot_BMM150

Modify platform.txt so libs can use things like M_PI

  1. cd ~/.arduino15/packages/arduino/hardware/zephyr/0.51.0

  2. nano platform.txt

  3. change compiler.cpp.flags to

Copy

compiler.cpp.flags=-g -Os -std=gnu++17 -c -D_XOPEN_SOURCE=700 {compiler.warning_flags} {compiler.zephyr.macros} "@{compiler.zephyr.cxxflags_file}" {compiler.zephyr.common_ldflags} {compiler.zephyr.extra_ldflags} {compiler.zephyr.common_cxxflags} {compiler.zephyr.extra_cxxflags} -MMD -mcpu={build.mcu} {build.float-abi} {build.fpu}

  1. save and exit from nano

Add AHRS package to install list

Under Python Files create a requirements.txt file and enter ahrs into the file save and run. This will install the python package

To add Python packages to your application, select the main.py file and click on the “Add file“ icon. Create a requirements.txt file and list the Python packages you need. See Requirements File Format - pip documentation v25.2 for more information.

For more info on the package

  1. AHRS · PyPI

  2. AHRS: Attitude and Heading Reference Systems — AHRS 0.4.0 documentation

Now with that out of the way I then had the MCU (arduino) send data to a telemetry app once I received it from the MCU - Roll/pitch/yaw - and it worked.

To get data back and forth pretty much stuck to the basic bridge function, i.e., Bridge.provide and Bridge.notify. Not sure if this is the best approach so am going to attach the python and arduino sketches. NOTE: Not hooked up with SSD and scp doesnt seem to work without it. Alot of prints are commented out. Guess next thing is maybe try sending things to the web :slight_smile:

Cheers.

python_sketch.txt (2.2 KB)

telemetry.txt (1.3 KB)

arduino_sketch.txt (3.7 KB)

1 Like

Thanks for sharing @Merlin513!

This approach is completely valid, but I would suggest injecting the -D_XOPEN_SOURCE=700 flag via the platform.local.txt file. This will isolate your modifications to a dedicated file, leaving platform.txt completely stock.

  1. Type the following command in the terminal:
    STORAGE_FOLDER="<some storage location>"
    
  2. Replace the <some storage location> placeholder in the command with the path of a folder that can be used to persistently store files.
    :warning: Do not use the platform installation path, as this will be erased at every update of the "UNO Q Board" platform.
  3. Press the Enter key.
  4. Type the following command in the terminal:
    echo "compiler.cpp.extra_flags=-D_XOPEN_SOURCE=700" > "$STORAGE_FOLDER/platform.local.txt"
    
  5. Press the Enter key.
  6. Type the following command in the terminal:
    cp "$STORAGE_FOLDER/platform.local.txt" ~/.arduino15/packages/arduino/hardware/zephyr/<version>
    
  7. Replace the <version> placeholder in the command with the version number of the installed "UNO Q Board" platform.
  8. Press the Enter key.

After each update of the platform, you can restore your modifications by repeating steps 6 - 8.

1 Like

Thanks @ptillisch that is absolutely the better way to go. Hopefully they update it in the core so dont have to keep doing this.

Just an note: noticed that functions like dtostrf is not supported so copied a local version into the sketch
char* dtostrf(float val, int width, unsigned int precision, char* buffer) {
snprintf(buffer, width + 1, "%*.*f", width, precision, val);
return buffer;
}

@ptillisch Just to close the loop on your suggestion did as you suggested and it works like a charm :slight_smile:

1 Like