% Data read from eZ430-chronos (linux version, Matlab 7.7) % 2010, Martin Dobrovolny, martin.dobrovolny@upce.cz % www.martindobrovolny.cz % Just connect eZ430 to the USB and set the ASINC mode On % After connect - new device /dev/ttyACM0 must appear (ls /dev/ttyA*) % ------------------------------------------------------- % % IMPORTANT! % there is a little problem with a Matlab and /dev/ttyACM0 - it cannot be access directly. % % Solution % 1.) simple solution % create link at first!: % % sudo ln /dev/ttyACM0 /dev/ttyS101 % you must do it every time you plug the device in USB % % 2.) complex solution % create a java.opts file in the directory you start MATLAB from % with the following line in it (To specify the ports on your system): % % -Dgnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyS1:/dev/USB0:/dev/ttyACM0 % % Then after you restart MATLAB, the port should be found: % % >> instrhwinfo('serial') % % ans = % % AvailableSerialPorts: {2x1 cell} % JarFileVersion: 'Version 2.7.0' % ObjectConstructorName: {2x1 cell} % SerialPorts: {2x1 cell} % % >> ans.AvailableSerialPorts % % ans = % % '/dev/ttyS0' % '/dev/ttyACM0' % % ------------------------------------------------------------------------- clear % SETUP of USB AccessPoint % port_number='/dev/ttyACM0'; port_number='/dev/ttyS101'; s = serial(port_number); s.BaudRate=115200; s.InputBufferSize = 1024; s.FlowControl='none'; s.Timeout=1; 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 souce code StopAccessPoint=[255,9,3]; AccDataRequest=[255,8,7,0,0,0,0]; % Start AccessPoint fwrite(s,StartAccessPoint); % after cca 1s green LED must blink disp(['Please turn your watch to sync mode (key #, then key v - LED blinking), then press enter...']); disp(['CTRL+C to stop']); pause(); % Read (and store) data % 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); % I don't now why, but sometimes the correct assignment is: % X=a(6); % Y=a(5); % Z=a(7); data(i,1)=X; data(i,2)=Y; data(i,3)=Z; pozice='X: > < Y: > < Z: > <'; Xmin=5; Ymin=42; Zmin=74; rozsah=24; pozice(floor(Xmin+rozsah/2+X/256*rozsah))='*'; pozice(floor(Ymin+rozsah/2+Y/256*rozsah))='*'; pozice(floor(Zmin+rozsah/2+Z/256*rozsah))='*'; disp(pozice); % 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, or communications lost? -> Game over']); fwrite(s,StopAccessPoint); figure; subplot(3,1,1);stairs(data(1:end-100,1),'Marker','.','LineStyle','none','color','red'); ylabel('X acceleration'); subplot(3,1,2);stairs(data(1:end-100,2),'Marker','.','LineStyle','none','color','green');ylabel('Y acceleration'); subplot(3,1,3);stairs(data(1:end-100,3),'Marker','.','LineStyle','none','color','blue'); ylabel('Z acceleration');