working with 2 MetaWear boards simultaneously using python, Linux and Bluetooth
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
This discussion has been closed.
Comments
# -*- 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)