working with 2 MetaWear boards simultaneously using python, Linux and Bluetooth

edited April 2017 in General
as the title says i am using the provided Python code and the C++ APIs to communicate with 2 MetaWear CPro at the same time

i was able to comunicate with the two boards and get the ACC data in different CSV files my problem now is with the data rate it self

i have set both boards to work with datarate of 100 but what is strange is that when i receive the data of both boards

the first sensor data are received with data rate of 14 Hz
while the second sensor data are received with data rate of 100

i tried this with different combinations of data rate and the same results always happen where the first sensor works with data rate of 14 Hz and the second sensor works with the data rate i set both to work with

Comments

  • Can you post the full python code you are currently running along with the firmware revision the boards are currently running?
  • edited April 2017
    i am using metawear CPro boards with firmware 1.2.2
    i use the example code for handling the ACC sensor but with multithreading to communicate with different metawear boards

    here is the code i am using

  • # -*- coding: utf-8 -*-
    """
    Created by hbldh
    Created on 2016-04-02
    """

    from __future__ import division
    from __future__ import print_function
    from __future__ import absolute_import
    import time, datetime, csv, pygatt, signal, threading
    from datetime import datetime
    from pymetawear.client import MetaWearClient

    address_1 = 'EF:D3:4F:FF:C8:D4'
    address_2 = 'DE:0B:16:99:D6:8A'

    print("Connect to {0}...".format(address_1))
    c_1 = MetaWearClient(str(address_1), timeout=10.0, debug=False)
    print("New client created: {0}".format(c_1))
    print("Connect to {0}...".format(address_2))
    c_2 = MetaWearClient(str(address_2), timeout=10.0, debug=False)
    print("New client created: {0}".format(c_2))

    def handler(signum, frame):
    print ("force disconnect")
    c_1.accelerometer.notifications(None)
    c_2.accelerometer.notifications(None)
    time.sleep(5.0)
    c_1.disconnect()
    c_2.disconnect()

    signal.signal(signal.SIGTSTP, handler)

    def acc_callback1(data):

    now = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')
    print("Client_1, X: {1}, Y: {2}, Z: {3}".format(data[0], *data[1]))

    datastr = ("{1},{2},{3}".format(data[0], *data[1]))
    data="".join(datastr)
    datarow=now+","+data

    with open('accthread1.csv', 'a') as csvfile:
    writer = csv.writer(csvfile, delimiter=' ',
    escapechar=' ', quoting=csv.QUOTE_NONE)
    writer.writerow([datarow])

    def acc_callback2(data):

    now = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')
    print("Client_2, X: {1}, Y: {2}, Z: {3}".format(data[0], *data[1]))

    datastr = ("{1},{2},{3}".format(data[0], *data[1]))
    data="".join(datastr)
    datarow=now+","+data

    with open('accthread2.csv', 'a') as csvfile:
    writer = csv.writer(csvfile, delimiter=' ',
    escapechar=' ', quoting=csv.QUOTE_NONE)
    writer.writerow([datarow])

    class BleThread (threading.Thread):
    def __init__(self, threadID, name, client):
    threading.Thread.__init__(self)
    self.threadID = threadID
    self.name = name
    self.client = client
    def run(self):
    if self.client == 1 :
    print("Write sensor 1 settings...")
    c_1.accelerometer.set_settings(data_rate=100, data_range=16.0)
    print("getting sensor 1 data")
    c_1.accelerometer.high_frequency_stream = False
    c_1.accelerometer.notifications(acc_callback1)
    if self.client == 2 :
    print("Write sensor 2 settings...")
    c_2.accelerometer.set_settings(data_rate=100, data_range=16.0)
    print("getting sensor 2 data")
    c_2.accelerometer.high_frequency_stream = False
    c_2.accelerometer.notifications(acc_callback2)

    thread1 = BleThread(1, "sensor_1", 1)
    thread2 = BleThread(2, "Sensor_2", 2)

    thread1.start()
    thread2.start()

    while 1:
    time.sleep(20.0)
  • You need to enable high frequency streaming to stream from multiple devices.  See my post from your other thread.
  • thanks for your reply
    i have updated the firm ware on my 3 MetaWear Boards and enabled high frequency stream

    there was improvement of the data rate of the first 2 boards but the same problem exists 

    what is mean is that i set the data rate to 100 Hz in all boards and start having data from the 3 MetaWear boards but the first 2 boards i receive with data rate 40 and 42 Hz while the third board i receive data rate of 100 Hz
    even when i decrease the data rate to 50 Hz 2 boards have data rate of 40 Hz and the 3rd board have a 50 Hz data rate
    and what i need is to receive data from the three boards with rate of 100 Hz

    any help will be appreciated thanks again.
  • Reduce the max connection interval to 7.5ms.  You might have to reconnect to the boards to have the connection intervals renegotiated, not sure if the Linux ble stack supports live changes.

  • edited April 2017
    thanks alot @Eric it worked for me finally and with out the need to reconnect

    this is the command i use as mentioned in the post you added

    libmetawear.mbl_mw_settings_set_connection_parameters(c_1.board, 7.5, 7.5, 0, 6000)
This discussion has been closed.