This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Read the data from Movement Sensor (SensorTag CC2650) using usb cc2540 dongle with MATLAB

Other Parts Discussed in Thread: CC2650, CC2540

Hello,

I'm trying to using MATLAB to capture data from the Movement Sensor (CC2650).

As the answers from my search, it doesn't have a specific way to read the BLE from MATLAB directly. It must use cc2540 usb dongle to set the COM port, and MATLAB used serial port to capture the information from CC2650.

The only example matlab code, which can be searched, is  https://github.com/sid5291/SensorTag-Matlab. 

However, the existed sample code is for the old version (processors.wiki.ti.com/.../SensorTag_User_Guide).

The new version (processors.wiki.ti.com/.../CC2650_SensorTag_User's_Guide is different with the old one.

Gyroscope, Accelerometer and Magnetometer are intergated to only one movement sensor. 

I can connect the device by the sample matlab code.

The new version only show UUID and the existed sample code used the handle address.

As my guess, the handle address can be find by BTOOL, and I was done. AA82→0x0033, AA81→0x0036

But I still can't read the movement data.

My questions are

1. Can I still use the same sample code for CC2650 SensorTag?

2. Does my guess for transferring the UUID to handle address is correct or not ?

3. I post my matlab code below. I have a very stupid question.

GATT_AccOn = ['01'; '92'; 'FD'; '05'; '00'; '00'; '33'; '00'; '01']; 

GATT_AccRd = ['01'; '8A'; 'FD'; '04'; '00'; '00'; '2D' ;'00' ]; 

What does the number refer for? 

4. If possible, does anyone can provide a new MATLAB sample code? 

I think it would be very helpful for student research, because some students, like me, can only write the MATLAB.

Thanks,

Tommy 

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' ;'82';'F9'; 'BE' ;'84' ;'BE' ;'C4'];
CONNECT_TYPE = 2;

% Reference processors.wiki.ti.com/.../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'; '33'; '00'; '01'];
% GATT_AccOff = ['01'; '92'; 'FD'; '05'; '00'; '00'; '33'; '00'; '00'];

GATT_AccPerMin = ['01'; '92'; 'FD'; '05'; '00'; '00'; '36'; '00'; '0A'];
GATT_AccNoti = ['01'; '92'; 'FD'; '05'; '00'; '00'; '33'; '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');

  • Hello Tommy,

    I suggest searching for Matlab in the forum to see how others have accomplished this.
    Hopefully someone who has done this before can chime in as well.

    Best wishes
  • Hello JXS,

    Firstly thanks for your reply.

    I was done in searching for MATLAB. However, I can't find the any specific answer.

    As my questions, I found a sample MATLAB code from the forum, and it was announced in 2014 Nov. ( github.com/sid5291/SensorTag-Matlab )

    This code is for the past SensorTag, and I think it is a little different with CC2650.

    The sample code can't be used directly, because the descriptions in announcement documents are different.

    SensorTage: processors.wiki.ti.com/.../SensorTag_User_Guide

    CC2650: processors.wiki.ti.com/.../CC2650_SensorTag_User's_Guide 

    The other question is 

    GATT_AccOn = ['01'; '92'; 'FD'; '05'; '00'; '00'; '33'; '00'; '01'];  % open accelerometer

    GATT_AccRd = ['01'; '8A'; 'FD'; '04'; '00'; '00'; '2D' ;'00' ];  % read

    What does the number refer for? 

    Many thanks,

    Tommy

  • Hi !

    If you stil have the question, Those numbers refer to the GaTT number of each sensor, especifically those refer to enable the accelerometer and to read data  from him.

    As you said thats for the sensortag former version, you must change them, and you'll  find the new values in the BTOOL app. Right now im working on reading accelerometer data via MATLAB, but I got stuck in the array where i get the result of the data, because the lenght of the array, I think is no more than 24 caracters, Any idea of how to change it to 36 that is tha lenght of the movement data?

    Thanks in advance

    RH

  • Hi RH,

    I also try to get accelerometer data in MATLAB using the CC2650 sensortag and I haven't found the way to do it so far. The problem actually starts from BTOOL, where I try to write a value to a handle (e.g. to the 0x3C handle to set the accelerometer axis) and I keep getting the message 'ATT Command Failed the attribute cannot be written' and WRITE_NOT_PERMITTED, so I cannot enable the accelerometer and get data in BTOOL.

    Have you also encountered the same problem in BTOOL?

    What could I do for that?

    Moreover, to which handle do you have to write in order to enable the accelerometer? Is it the 0x3A handle?

    Thank you in advance.

    Kostis
  • Hi Konstantinos

    Well I used Btool to get the HCI comand to each handle, for example you need for Configuration, Notification On, and Read if you want also Period. The value Handle you need are :

    **************Configuration***************

    Characteristic value handle
    0x003C
    Hex
    3F:00 (2G)
    /* 3F:01  (4G);  3F:02  (8G);  3F:03  (16G)
    ***************Period:*********************
    Characteristic value handle
    0x003E
    Hex
    0A (100 ms); FF (2.55 s); 64 (1 s)
    **************Notifications:***************
    Characteristic value handle
    0x003A
    Hex
    01:00
    The HCI commands you get from them are expressed in color Green, and those frames put them on matlab to establish connection with the sensorTag.
    Get success !
    RH
  • Hi RH,

    Thank you so much for your quick response.

    The steps you sent me are really useful. However, when I write 3F:00 to the handle 0x003C I get the following error:

    ATT Command Failed

    Cpmmand = ATT_WriteReq

    Handle  = 0x003C

    Error = The Attribute Cannot Be Written.

    I also attach a photo with the error.

    It seems that I don't have permission to write commands to any handle, so I cannot enable the sensors and receive data (in BTOOL and as a result in MATLAB as well).

    Am I doing something wrong?

    I would really appreciate it if you could help me on that.

    Thank you again,

    Kostis

  • Hi Konstantinos

    Oh ya! I kind figured out whats the problem. Try these steps:

    1)After you established connection, right click on Handle, then press Read value.

    2 After that, just look for each handle in the table that is below the HCI commands.

    3)When you have changed each handle check out the Green message that appears and in the Dump (Tx) that is the HCI command you need to write on Matlab.

    I guess you are using as a base program from this page https://github.com/sid5291/SensorTag-Matlab  If so, I suppose you know that you must modify it for CC2650.

    Get success ! Hope this could help you and if not maybe, I think could be the core program try to update the firmware and then follow the steps above.

    RH

  • Hello, sorry for my interference, but I am using also the same sensortag (cc2650) with the same matlab code. I want to read all the movement data (accelerometer, gyroscope and magnetometer). I follow your steps about the use of Btool; now I have opened the table after clicking on "read values" on handle. Now, what should I do? I would to read the gatt to put in the matlab code to read the data from accelerometer, gyroscope and magnetometer.