Skip to content

examples(lis2mdl): Replace test scripts with practical examples.#251

Merged
nedseb merged 14 commits intomainfrom
feat/lis2mdl-expand-example
Mar 26, 2026
Merged

examples(lis2mdl): Replace test scripts with practical examples.#251
nedseb merged 14 commits intomainfrom
feat/lis2mdl-expand-example

Conversation

@Charly-sketch
Copy link
Copy Markdown
Contributor

@Charly-sketch Charly-sketch commented Mar 26, 2026

Summary

Replace the monolithic magnet_test.py with 8 practical, user-facing examples for the LIS2MDL magnetometer.

Closes #185

Changes

Removed

File Reason
magnet_test.py PASS/FAIL test suite, not a user-facing example. Test coverage handled by tests/scenarios/lis2mdl.yaml

Added — 8 practical examples

Example Description
basic_read.py Simple magnetic field (X, Y, Z) + temperature read in a loop
calibrate_2d.py Interactive 2D hard-iron calibration with quality check
tilt_compensated_heading.py Magnetometer + accelerometer fusion for tilt-compensated heading. Requires: ism330dl
metal_detector.py Detect metal objects via magnitude changes, with hardware PWM buzzer (Timer 1 CH4)
door_sensor.py Door open/close detection using a magnet baseline
field_logger.py CSV logging to DAPLink flash (60 seconds at 1 Hz). Requires: daplink_flash
field_map.py Real-time spatial field mapping with min/max tracking
low_power_one_shot.py Low-power sampling with power_off() between reads

Kept

Example Description
magnet_compass.py Flat compass with heading and cardinal direction
magnet_fieldForce.py Total field strength magnitude display

Updated

File Change
README.md Replaced example section with table listing all 10 examples

Test commands

make run SCRIPT=lib/lis2mdl/examples/basic_read.py
make run SCRIPT=lib/lis2mdl/examples/calibrate_2d.py
make run SCRIPT=lib/lis2mdl/examples/door_sensor.py
make run SCRIPT=lib/lis2mdl/examples/field_logger.py
make run SCRIPT=lib/lis2mdl/examples/field_map.py
make run SCRIPT=lib/lis2mdl/examples/low_power_one_shot.py
make run SCRIPT=lib/lis2mdl/examples/magnet_compass.py
make run SCRIPT=lib/lis2mdl/examples/magnet_fieldForce.py
make run SCRIPT=lib/lis2mdl/examples/metal_detector.py
make run SCRIPT=lib/lis2mdl/examples/tilt_compensated_heading.py

Notes

Checklist

  • magnet_test.py removed
  • 8 new practical examples added
  • Test coverage verified in tests/scenarios/lis2mdl.yaml
  • ruff check passes
  • README updated with examples table
  • Hardware validation pending (@Charly-sketch)

@Charly-sketch Charly-sketch requested a review from nedseb March 26, 2026 10:50
@nedseb nedseb requested a review from Copilot March 26, 2026 11:42
@nedseb nedseb added the documentation Improvements or additions to documentation label Mar 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refreshes the lis2mdl driver’s examples by removing a test-style script and adding practical, real-world usage examples, and then documents those examples in the driver README (closes #185).

Changes:

  • Removed magnet_test.py from lib/lis2mdl/examples/ (test-like content no longer shipped as an “example”).
  • Added multiple new usage-focused examples (calibration, tilt-compensated heading, detection, logging, mapping, low-power).
  • Updated lib/lis2mdl/README.md to list and describe the available examples.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/lis2mdl/examples/basic_read.py New “getting started” loop reading field + temperature.
lib/lis2mdl/examples/calibrate_2d.py New interactive 2D hard-iron calibration workflow.
lib/lis2mdl/examples/tilt_compensated_heading.py New LIS2MDL + ISM330DL fused heading demo.
lib/lis2mdl/examples/metal_detector.py New magnitude-change detector with buzzer feedback.
lib/lis2mdl/examples/door_sensor.py New baseline + hysteresis door open/close detector.
lib/lis2mdl/examples/field_logger.py New CSV logger to DAPLink flash.
lib/lis2mdl/examples/field_map.py New “field mapping” loop with axis min/max tracking.
lib/lis2mdl/examples/low_power_one_shot.py New low-power one-shot sampling loop.
lib/lis2mdl/examples/magnet_test.py Removed test suite from examples directory.
lib/lis2mdl/README.md Replaced embedded compass snippet with an examples list table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/lis2mdl/examples/metal_detector.py Outdated
Comment thread lib/lis2mdl/examples/tilt_compensated_heading.py Outdated
Comment thread lib/lis2mdl/README.md
Copy link
Copy Markdown
Contributor

@nedseb nedseb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les corrections sont acceptees. La reponse sur le README avec la capture d'ecran est bien meilleure, c'est ce que j'attend. Pour le tone() je ferai la correction avant le merge.

@nedseb
Copy link
Copy Markdown
Contributor

nedseb commented Mar 26, 2026

Note: the hardware PWM tone() introduced here for metal_detector.py should also be applied to dpad_piano.py (PR #247) once validated on hardware. Tracked in #254.

@nedseb nedseb changed the title Feat/lis2mdl expand example examples(lis2mdl): Replace test scripts with practical examples. Mar 26, 2026
@nedseb nedseb merged commit 8212fad into main Mar 26, 2026
1 of 2 checks passed
@nedseb nedseb deleted the feat/lis2mdl-expand-example branch March 26, 2026 15:44
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.1.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples: Add practical examples for lis2mdl driver.

3 participants