Skip to content

Commit 00021bf

Browse files
committed
lsm6dsox: Improve handling of step interrupt.
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
1 parent a48a9b6 commit 00021bf

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

micropython/drivers/imu/lsm6dsox/lsm6dsox_pedometer.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
lsm.pedometer_config(debounce=5, int1_enable=True, int2_enable=True)
2626

2727
# Register interrupt handler on a Pin. e.g. D8
28-
# The interrupt pins are open-drain, so they will be pulled low when a step is detected.
29-
# We configure the host pin with a pull-up resistor to ensure it stays high when not active.
30-
interrupt_pin = Pin("D8", Pin.IN, Pin.PULL_UP)
28+
# The interrupt pins are push-pull outputs by default that go low when a step is detected.
29+
# You can connect either INT1 or INT2 to the interrupt pin.
30+
interrupt_pin = Pin("D8", Pin.IN) # Change this to your desired interrupt pin.
31+
interrupt_fired = False # Flag to indicate if the interrupt has been fired.
3132

3233

3334
def on_step_detected(pin):
34-
print("Steps detected!")
35+
global interrupt_fired
36+
interrupt_fired = True
3537

3638

3739
# Configure the interrupt pin to trigger on falling edge (active low) when a step is detected.
@@ -40,6 +42,10 @@ def on_step_detected(pin):
4042
last_steps = None # Keep track of the last step count to detect changes.
4143

4244
while True:
45+
if interrupt_fired:
46+
print("Step detected!")
47+
interrupt_fired = False # Reset the flag after handling the interrupt.
48+
4349
steps = lsm.steps()
4450

4551
if steps != last_steps:

0 commit comments

Comments
 (0)