Skip to content

Commit 95aa8fa

Browse files
Charly-sketchnedseb
authored andcommitted
lis2mdl: Resolve reviewer correction.
1 parent a58651b commit 95aa8fa

5 files changed

Lines changed: 7 additions & 45 deletions

File tree

lib/lis2mdl/README.md

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,9 @@ Example setup:
5050

5151
```python
5252
from machine import I2C, Pin
53-
from device import LIS2MDL
53+
from lis2mdl import LIS2MDL
5454

55-
i2c = I2C(1, scl=Pin(22), sda=Pin(21))
56-
mag = LIS2MDL(i2c)
57-
```
58-
59-
---
60-
61-
## 🧩 Installation
62-
63-
### 1. Copy files to your board
64-
65-
Upload both files using Thonny, mpremote, or ampy:
66-
67-
```
68-
device.py
69-
lis2mdl/const.py
70-
```
71-
72-
### 2. Import and initialize
73-
74-
```python
75-
from machine import I2C, Pin
76-
from device import LIS2MDL
77-
78-
i2c = I2C(1, scl=Pin(22), sda=Pin(21))
55+
i2c = I2C(1)
7956
mag = LIS2MDL(i2c)
8057
```
8158

@@ -242,7 +219,7 @@ print("Register dump:", regs)
242219

243220
```python
244221
from machine import I2C, Pin
245-
from device import LIS2MDL
222+
from lis2mdl import LIS2MDL
246223
import time
247224

248225
i2c = I2C(1, scl=Pin(22), sda=Pin(21))
@@ -257,15 +234,6 @@ while True:
257234

258235
---
259236

260-
## 🧾 Notes
261-
262-
* The LIS2MDL outputs magnetic data in **LSB**, with a conversion factor of **0.15 µT/LSB**.
263-
* Temperature readings are **relative only** (not absolute).
264-
* Calibration should be repeated if the sensor environment changes (metal nearby, relocation, etc.).
265-
* Tilt compensation requires an external **accelerometer** or IMU (e.g., LIS3DH, MPU6050, BNO055).
266-
267-
---
268-
269237
## 📚 References
270238

271239
* [STMicroelectronics LIS2MDL Datasheet](https://www.st.com/resource/en/datasheet/lis2mdl.pdf)

lib/lis2mdl/examples/magnet_compass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# exemple of heading reading with direction label
1+
# Example of heading reading with direction label
22
from time import sleep_ms
33
from machine import I2C
44
from lis2mdl.device import LIS2MDL

lib/lis2mdl/examples/magnet_fieldForce.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# exemple of heading reading with direction label
1+
# Example of heading reading with direction label
22
from time import sleep_ms
33
from machine import I2C
44
from lis2mdl.device import LIS2MDL

lib/lis2mdl/examples/magnet_test.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,6 @@ def run_heading_tests(dev):
513513
all_ok &= test_heading_filter_wrap(dev)
514514
print("\n=== HEADING summary:", "OK ✅" if all_ok else "Partial ⚠️ (see details)")
515515

516-
517-
def _bits(v, hi, lo):
518-
m = (1 << (hi - lo + 1)) - 1
519-
return (v >> lo) & m
520-
521-
522516
def test_power_modes(dev):
523517
print("\n=== TEST POWER MODES ===")
524518
ok = True

lib/lis2mdl/lis2mdl/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(
3636
self.setReg(0x20, LIS2MDL_CFG_REG_A) # SOFT_RST=1 (not 0x10)
3737
try:
3838
sleep_ms(10) # Small delay for reset to complete
39-
except:
39+
except Exception:
4040
pass
4141

4242
# Configure the sensor's operating mode, output data rate, and other settings.
@@ -569,7 +569,7 @@ def reboot(self, wait_ms: int = 10):
569569
self.setReg(r, LIS2MDL_CFG_REG_A)
570570
try:
571571
sleep_ms(wait_ms)
572-
except:
572+
except Exception:
573573
pass
574574

575575
def is_idle(self) -> bool:

0 commit comments

Comments
 (0)