Skip to content

Commit b617264

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

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

micropython/drivers/imu/lsm6dsox/lsm6dsox_pedometer.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,25 @@
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)
31-
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.
3232

3333
def on_step_detected(pin):
34-
print("Steps detected!")
35-
34+
global interrupt_fired
35+
interrupt_fired = True
3636

3737
# Configure the interrupt pin to trigger on falling edge (active low) when a step is detected.
3838
interrupt_pin.irq(trigger=Pin.IRQ_FALLING, handler=on_step_detected)
3939

4040
last_steps = None # Keep track of the last step count to detect changes.
4141

4242
while True:
43+
if interrupt_fired:
44+
print("Step detected!")
45+
interrupt_fired = False # Reset the flag after handling the interrupt.
46+
4347
steps = lsm.steps()
4448

4549
if steps != last_steps:

0 commit comments

Comments
 (0)