This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eec42af
commit b6e76e8
Showing
6 changed files
with
64 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
{ | ||
"urls": [ | ||
["micropython_lis3mdl/examples/lis3mdl_data_rate.py", "github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_data_rate.py"], | ||
["micropython_lis3mdl/examples/lis3mdl_scale_range.py", "github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_scale_range.py"], | ||
["micropython_lis3mdl/examples/lis3mdl_simpletest.py", "github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_simpletest.py"], | ||
["micropython_lis3mdl/examples/lis3mdl_low_power_mode.py", "github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_low_power_mode.py"], | ||
["micropython_lis3mdl/examples/lis3mdl_operation_mode.py", "github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_operation_mode.py"] | ||
[ | ||
"micropython_lis3mdl/examples/lis3mdl_data_rate.py", | ||
"github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_data_rate.py" | ||
], | ||
[ | ||
"micropython_lis3mdl/examples/lis3mdl_scale_range.py", | ||
"github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_scale_range.py" | ||
], | ||
[ | ||
"micropython_lis3mdl/examples/lis3mdl_simpletest.py", | ||
"github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_simpletest.py" | ||
], | ||
[ | ||
"micropython_lis3mdl/examples/lis3mdl_low_power_mode.py", | ||
"github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_low_power_mode.py" | ||
], | ||
[ | ||
"micropython_lis3mdl/examples/lis3mdl_operation_mode.py", | ||
"github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_operation_mode.py" | ||
], | ||
[ | ||
"micropython_lis3mdl/examples/lis3mdl_compass.py", | ||
"github:jposada202020/MicroPython_LIS3MDL/examples/lis3mdl_compass.py" | ||
] | ||
], | ||
"version": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import time | ||
from math import atan2, degrees | ||
from machine import Pin, I2C | ||
from micropython_lis3mdl import lis3mdl | ||
|
||
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040 | ||
lis = lis3mdl.LIS3MDL(i2c) | ||
|
||
|
||
def vector_2_degrees(x, y): | ||
angle = degrees(atan2(y, x)) | ||
if angle < 0: | ||
angle += 360 | ||
return angle | ||
|
||
|
||
def get_heading(_sensor): | ||
magnet_x, magnet_y, _ = _sensor.magnetic | ||
return vector_2_degrees(magnet_x, magnet_y) | ||
|
||
|
||
while True: | ||
print(f"heading: {get_heading(lis):.2f} degrees") | ||
time.sleep(0.2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters