【问题标题】:Get accelerometer data from ti sensortag using Matlab and HCI-command使用 Matlab 和 HCI 命令从 ti sensortag 获取加速度计数据
【发布时间】:2015-08-12 09:38:23
【问题描述】:

我正在尝试使用 matlab 从 ti sensortag 获取传感器数据,我的工作基于 github 站点上发布的工作:

https://github.com/sid5291/SensorTag-Matlab

我正在尝试获取加速度计数据而不是温度和湿度数据(在原始作品中)

这是我的代码,matlab和sensortag之间的连接已经建立,

  • 当我请求温度信息时,结果是正确的,并且

  • 当我请求加速度计或陀螺仪数据时,结果错误


GAP_initialise =  ['01';'00';'FE';'26';'08';'05';'00';'00';'00';'00';'00';'00';'00'
'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00'
'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'01'
'00';'00';'00'];

GAP_DeviceDiscovery = ['01';'04';'FE';'03';'03';'01';'00'];
SCAN_TYPE   = 1;
GAP_connect = ['01'; '09'; 'FE'; '09'; '00'; '00'; '00' ;'52';'DE'; 'AB' ;'29' ;'6A' ;'BC'];  
CONNECT_TYPE = 2;

% Reference    http://processors.wiki.ti.com/images/a/a8/BLE_SensorTag_GATT_Server.pdf
GATT_AccOn  = ['01'; '92'; 'FD'; '05'; '00'; '00'; '34'; '00'; '01'];
GATT_AccOff = ['01'; '92'; 'FD'; '05'; '00'; '00'; '34'; '00'; '00'];
WRITE_TYPE  = 3;
GATT_AccRd  = ['01'; '8A'; 'FD'; '04'; '00'; '00'; '30' ;'00' ];
READ_TYPE   = 4;

disp('Going to Intialize');
HCI_TXRX(GAP_initialise);
disp('Going to Scan');
disp('Make Sure Led D1 is blinking on Sensor Tag');
disp('Wait for Scan To End');
input('Press any key to continue');
HCI_TXRX(GAP_DeviceDiscovery,SCAN_TYPE);
disp('Going to Connect to Sensor Tag');
disp('LED D1 will turn off when Connected, if doesnt there is an error');

input('Press any key to continue');
HCI_TXRX(GAP_connect,CONNECT_TYPE);
disp('Going to Turn On Acc');
input('Press any key to continue');
HCI_TXRX(GATT_IRTAccOn,WRITE_TYPE);
disp('Going to Read from Sensors');
input('Press any key to continue');

while(1)
result = HCI_TXRX(GATT_AccRd,READ_TYPE);
x = hex2dec(result(1,:))/64;
y = hex2dec(result(2,:))/64;
z = hex2dec(result(3,:))/64;

char = input('Press any key to continue (x to exit)','s');
if(char == 'x')
    break;
end
 end 

谁能帮我解决这个问题

【问题讨论】:

    标签: matlab hci tilt-sensor


    【解决方案1】:

    我发现了错误:只需要输入加速度计服务的正确值,即:'31' 用于配置,'2D' 用于读取数据

     clear all
     close all
     clf
    GAP_initialise=['01';'00';'FE';'26';'08';'05';'00';'00';'00';'00';'00';'00';'00'
    '00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00'
    '00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'00';'01'
    '00';'00';'00'];
    GAP_DeviceDiscovery = ['01';'04';'FE';'03';'03';'01';'00'];
    SCAN_TYPE = 1;
    GAP_connect = ['01'; '09'; 'FE'; '09'; '00'; '00'; '00' ;'52';'DE'; 'AB' ;'29' ;'6A' ;'BC'];  %BC:6A:29:AC:50:46 (1325 Tag)
    CONNECT_TYPE = 2;
    
    % Reference http://processors.wiki.ti.com/images/a/a8/BLE_SensorTag_GATT_Server.pdf
    
    % 0x31 is the address of the acceloremeter config in the GATT server
    
    GATT_AccOn = ['01'; '92'; 'FD'; '05'; '00'; '00'; '31'; '00'; '01'];
    GATT_AccOff = ['01'; '92'; 'FD'; '05'; '00'; '00'; '31'; '00'; '00'];
    
    % 0x31 is the address of the acceloremeter config in the GATT server
    
    
    GATT_AccPerMin = ['01'; '92'; 'FD'; '05'; '00'; '00'; '34'; '00'; '0A'];
    GATT_AccNoti = ['01'; '92'; 'FD'; '05'; '00'; '00'; '2E'; '00'; '01'];
    
    WRITE_TYPE = 3;
    
    % 0x2D is the address used to read the acceloremeter data in the GATT server
    
    GATT_AccRd = ['01'; '8A'; 'FD'; '04'; '00'; '00'; '2D' ;'00' ]; 
    READ_TYPE = 4;
    
    disp('Going to Intialize');
    HCI_TXRX(GAP_initialise);
    disp('Going to Scan');
    disp('Make Sure Led D1 is blinking on Sensor Tag');
    disp('Wait for Scan To End');
    input('Press any key to continue');
    HCI_TXRX(GAP_DeviceDiscovery,SCAN_TYPE);
    disp('Going to Connect to Sensor Tag');
    disp('LED D1 will turn off when Connected, if doesnt there is an error');
    HCI_TXRX(GAP_connect,CONNECT_TYPE);
    disp('Going to Turn On Acc');
    
    HCI_TXRX(GATT_AccOn,WRITE_TYPE);
    HCI_TXRX(GATT_AccPerMin,WRITE_TYPE);
    % HCI_TXRX(GATT_AccNoti,WRITE_TYPE);
    disp('Going to Turn On Accelerometer');
    
    i =1;
    clf
    while(1)
    result = HCI_TXRX(GATT_AccRd,READ_TYPE);
    
    % result(1,:) is not used (data from acc x:y:z  3 bytes )
    rawval = hex2dec([result(2,:); result(3,:); result(4,:)]);
    
    xval = rawval(1)/64; % calculate acc, unit g, range -2, +2
    yval = rawval(2)/64; 
    zval = rawval(3)/64; 
    
    % show data
    
    fprintf('Acc X: %f \n',xval);
    fprintf('Acc Y: %f \n',yval);
    fprintf('Acc Z: %f \n',zval);
    
    
    %char = input('Press any key to continue (x to exit)','s');
    
    
    % read 10 sample from accerometer 
    
    if(i == 100)
        break;
    end
    
    % update table of samples 
    
    graphe_x(i) = xval;
    graphe_y(i) = yval;
    graphe_z(i) = zval;
    
    % update graph with new samples
    figure(1), plot(graphe_x,'r'), hold on
    plot(graphe_y,'g'), hold on
    plot(graphe_z,'b')
    
    
    % increment counter 
    
    i = i + 1;
    
    
    end
    

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 2011-06-28
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 2015-10-27
      相关资源
      最近更新 更多