Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

MatLab GUI accelerometer reading DATA

Asked by Amed on 8 Feb 2013

Hello, as of right now i'm trying to read in accelerometer data to my MatLab gui thru a pushbutton.. So far here is my code

function pushbutton6_Callback(hObject, eventdata, handles)
%mapping between analog inputs and X,Y,Z axes.
        %     Xch = 1;
        %     Ych = 3;
        %     Zch = 2;
            fprintf(out.s,'R');
            %read voltages from accelerometer and reorder
            reordered(1)= fscanf(out.s,'%u');
            reordered(2)= fscanf(out.s,'%u');
            reordered(3)= fscanf(out.s,'%u');
            %determine what offset and gain values to use
            offset = calCo.offset;
            gain = calCo.g;
            accel = (reordered - offset) ./ gain;
            %map analog inputs to axes
            handles.gx = accel(1);
            handles.gy = accel(2);
            handles.gz = accel(3);
            guidata(hObject, handles)

This code was partially written for me. I'm trying to understand it since i've only been using matlab for 3 weeks. Can anybody help me what i'm doing wrong? I have a button for calibrating and a button for reading in the serial, but as of right now i'm trying to read actual data and later graph.

THANKS

FIrst problem fixed... scroll down below for the new problem I cannot seem to fix.. THANKS

8 Comments

Amed on 8 Feb 2013

OK so I got my accelerometer data to read out, but for some reason my Pushbutton7 won't close serial AS SEEN ABOVE in the code. It worked perfectly before, but now it won't.

I had to manually close it by ctrl+c and then some random graph popped up? How do I delete this graph?

Here is my code to run the data thru pushbutton6 % START DATA - PUSHBUTTON6 function pushbutton6_Callback(hObject, eventdata, handles)

%COMPORT
comPort = '/dev/tty.usbmodemfd121';
%READS SERIAL
if (~exist('serialFlag','var'))
 [accelerometer.s,serialFlag] = setupSerial(comPort);
end
%CALIBRATES
if(~exist('calCo', 'var'))
    calCo = calibrate(accelerometer.s);
end
%DEFINEING H AND BUTTON VARIABLES
if(~exist('h', 'var') || ~ishandle(h))
    h = figure(1);
end
if(~exist('button','var'))
    button = uicontrol('Style','pushbutton','String','Stop',...
                    'pos',[0 0 50 25],'parent',h,...
                    'Callback','stop_call_vector','UserData',1);
end
%READS DATA
while(get(button, 'UserData'))
      [gx gy gz] = readAcc(accelerometer,calCo);
  cla;
      r = sqrt((gx^2)+(gy^2)+(gy^2));
      gx
      gy
      gz
      r
end
Amed on 8 Feb 2013

any takers on the problem above

Walter Roberson on 8 Feb 2013

Note: the lines

guidata(hObject, handles);
handles.gx= 0;
handles.gy= 0;

should have the assignments before the guidata() call.

Amed

Products

No products are associated with this question.

0 Answers

Contact us