lbuque / bma_binding_micropython

BMA423 Sensor API binding for MicroPython
MIT License
0 stars 0 forks source link

bma423 as wakeup ESP32 : OK at first time then KO , how to clear IRQ #2

Closed picpic020960 closed 2 years ago

picpic020960 commented 2 years ago

Bonjour , I wish use bma423 as twatch 2020 V1 wakeup from lightsleep The bma wake the watch up only first time seems that the IRQ is always ON and the watch wake up after machine.lighsleep(10000). No display from bma423.c ... How to clear the IRQ or debug ? Thanks for help

...
b.wrist_wear(double_tap_cb)

def bma_interrupt(pin):
    print("bma interrupt" + str(pin))
    print("Got BMA Accellorator Interrupt on pin:", pin)

bmaint = Pin(39, Pin.IN)
bmaint.irq(trigger=Pin.IRQ_RISING, handler=None,wake=machine.sleep)
#esp32.wake_on_ext0(bmaint, esp32.WAKEUP_ALL_LOW)
#esp32.wake_on_ext0(bmaint, esp32.WAKEUP_ANY_HIGH)

while True:
    print('5 s')
    utime.sleep(5)
    print('sleep 10s')
    machine.lightsleep(10000)
    print(str(machine.wake_reason()))
lbuque commented 2 years ago

The following line of code will cause bma423 to fail to enter irq_handler.

bmaint.irq(trigger=Pin.IRQ_RISING, handler=None,wake=machine.sleep)

I execute the following code and it seems to wake up normally.

from machine import Pin, I2C
import bma
i2c = I2C(0, scl=Pin(22), sda=Pin(21),freq=400000)

bmaint = Pin(39)
b = bma.BMA423(i2c, address=25, int1=bmaint)

# 配置使能三轴加速度
b.accel_config(True, direction=b.LOWER_LEFT, layer=b.BOTTOM_LAYER)
b.accel()

# 使能步数统计
b.step_config(True)
# 读取步数
b.step_counter()

# 活动检测中断
def activity_cb(event):
    if event == 0:
        print('User is stationary')
    elif event == 1:
        print('User is walking')
    elif event == 2:
        print('User is running')
    elif event == 3:
        print('Invalid activity recognized')

b.activity(activity_cb)

# 单击事件中断
def single_tap_cb(event):
    print('Single tap received')

b.single_tap(single_tap_cb)

# 双击击事件中断
def double_tap_cb(event):
    print('Double tap received')

b.double_tap(double_tap_cb)

# 抬腕事件中断
def wrist_wear_cb(event):
    print('Wrist wear received')

b.wrist_wear(wrist_wear_cb)

def bma_interrupt(pin):
    print("bma interrupt" + str(pin))
    print("Got BMA Accellorator Interrupt on pin:", pin)

import machine
import utime
import esp32

#esp32.wake_on_ext0(bmaint, esp32.WAKEUP_ALL_LOW)
esp32.wake_on_ext0(bmaint, esp32.WAKEUP_ANY_HIGH)

while True:
    print('5 s')
    utime.sleep(5)
    print('sleep 10s')
    machine.lightsleep(10000)
    print(str(machine.wake_reason()))

The log is as follows:

image

You can run the above code to experience whether bma423 wakes up esp32 normally.

picpic020960 commented 2 years ago

Thanks for help