stepcounter issue in MMS+(BMI270)

edited October 30 in Python

Hi Guys,

I was trying to stream steps with following code, the code runs but it failed to detect any steps. Did I miss anything? Thank you!

class State:
def init(self, device):
self.device = device
self.samples = 0

    self.OrientationCallback = FnVoid_VoidP_DataP(self.Orientation_data_handler)
    self.stepCounterCallback = FnVoid_VoidP_DataP(self.step_counter_data_handler)

def Orientation_data_handler(self, ctx, data):
    print("QUAT: %s -> %s" % (self.device.address, parse_value(data)))
    self.samples+= 1

def step_counter_data_handler(self, ctx, data):
    print("Detected!")
    print("Steps= %d" % (parse_value(data)))
    self.samples+= 1

states = []
for i in range(len(sys.argv) - 1):
d = MetaWear(sys.argv[i + 1])
d.connect()
print("Connected to " + d.address + " over " + ("USB" if d.usb.is_connected else "BLE"))
states.append(State(d))

for s in states:
print("Configuring device")
libmetawear.mbl_mw_settings_set_connection_parameters(s.device.board, 7.5, 7.5, 0, 6000)
sleep(1.5)

if (1):
    print("Setting up Acc") 
    libmetawear.mbl_mw_acc_start(s.device.board)    
    libmetawear.mbl_mw_acc_bmi270_set_odr(s.device.board, AccBmi270Odr._100Hz)
    libmetawear.mbl_mw_acc_set_range(s.device.board, 8.0)
    libmetawear.mbl_mw_acc_write_acceleration_config(s.device.board)

    print("Get any motion signal")
    libmetawear.mbl_mw_gyro_bmi270_start(s.device.board)  
    libmetawear.mbl_mw_acc_bmi270_enable_step_detector(s.device.board)

    step_counter_signal = libmetawear.mbl_mw_acc_bmi270_get_step_detector_data_signal(s.device.board)
    libmetawear.mbl_mw_datasignal_subscribe(step_counter_signal, None, s.stepCounterCallback)

    print("Read step counter")
    libmetawear.mbl_mw_acc_bmi270_enable_step_detector(s.device.board)
    #libmetawear.mbl_mw_acc_bmi270_read_step_counter(s.device.board, None, None, s.stepCounterCallback)
    libmetawear.mbl_mw_datasignal_read(step_counter_signal)

print("Logging data for 20s")
sleep(20.0)

for s in states:

if (1):
    libmetawear.mbl_mw_sensor_fusion_stop(s.device.board)
    libmetawear.mbl_mw_acc_bmi270_disable_step_detector(s.device.board)


    step_counter_signal= libmetawear.mbl_mw_acc_bmi270_get_step_detector_data_signal(s.device.board)
    signal = libmetawear.mbl_mw_sensor_fusion_get_data_signal(s.device.board, SensorFusionData.QUATERNION)
    libmetawear.mbl_mw_datasignal_unsubscribe(signal)
    libmetawear.mbl_mw_datasignal_unsubscribe(step_counter_signal)

    libmetawear.mbl_mw_debug_disconnect(s.device.board)
Sign In or Register to comment.