f



Display ez430 acc data in my Matlab GUI

Hello, I am in need of help on how to display real time accelerometer data coming in from the ez430 in my own GUI using MATLAB.

Using this code I have been able to get the data coming in to MATLAB and numerical values can be displayed in the command window, but I am having difficulty in displaying the data into a static text box.

Can someone please suggest how to do this?

I have the values coming in as X, Y and Z.
I was hoping that using set(handles.b_x,'String', X); would display the X value into text box b_x but it doesn't.

Here is the code:

% --- Executes on button press in ez_button.
function ez_button_Callback(hObject, eventdata, handles)
% hObject    handle to ez_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


global x_count;

clear
% SETUP of USB AccessPoint
  
port_number='COM10';

s = serial(port_number);
    s.BaudRate=115200;
    s.InputBufferSize = 1024;
    s.FlowControl='none';
    s.Timeout=3;
    s.ReadAsyncMode='continuous'; % !!!!!!! important
        if s.Status(1:4)=='open' disp('Closing formerly opened port');fclose(s);end;

    s.ErrorFcn=@mycallback; % not important - you can specify your own error callback


%  Port open
fopen(s);   % you can use exceptions, but better soluton is break on error
            % when there is still problem after first run - try RESTART MATLAB!!!
    instrfind
   
    %get(s)  % display port status and settings

% record(s,'on');

% Header of FRAMEs settings

    StartAccessPoint=[255, 7,3];    % numbers taken from ez430 source code

    StopAccessPoint=[255,9,3];

    AccDataRequest=[255,8,7,0,0,0,0];


% Start AccessPoint
fwrite(s,StartAccessPoint); 

% Main read cycle
stop_flag=0;
i=0;
while stop_flag<100
    i=i+1;
    try
        fwrite(s,AccDataRequest);
        a=fread(s,7,'int8');
   
        X=a(1);
        Y=a(2);
        Z=a(3);
       
        x_value = X;
       
        %these are the acc values
        data(i,1)=X; 
        data(i,2)=Y; 
        data(i,3)=Z;
       
        % i was hoping this would display the X value in text box b_x but it does not
        %set(handles.b_x,'String', X);
        % using disp(X); i can display in command window, but i want in my own GUI.

       

        % stop on idle    
        if ((X==0) & (Y==0) & (Z==0)) stop_flag=stop_flag+1;end;
        if ((X~=0) | (Y~=0) | (Z~=0)) stop_flag=0;end;

       
    catch
%         disp('RS232 dropout');
    end;
       
end;
disp(['Sync mode off / communications lost.']);


fwrite(s,StopAccessPoint);
fclose(s);
delete(s);
clear s;
0
oleg
2/2/2011 7:32:04 PM
comp.soft-sys.matlab 211266 articles. 14 followers. lunamoonmoon (258) is leader. Post Follow

2 Replies
965 Views

Similar Articles

[PageSpeed] 3

Hi Oleg,

This is an old thread, but I'm replying in hopes that other people are still working on similar projects. 

I think you just need a num2str(X) in your set(...) call. 

I too am trying to get the accelerometer data in. I used the same code to read in the data from the serial port, however I am noticing a lot of zeros. 

It's almost as is if Matlab is sampling the serial port faster than it is receiving data from the watch. 

Have you encountered this problem as well.

Best,
Matt
0
4/1/2011 2:11:04 AM
i was wondering if you could tell me the unit of accelerometer input that you are getting in MATLAB its not volts, right??
0
5/3/2011 12:48:02 PM
Reply: