Go Down

Topic: how to send 10 digit from matlab to arduino. (Read 226 times) previous topic - next topic

srijis94

we have to send the 10 digit phone number from matlab to arduino and then to gsm for sending a message. but the arduino is not getting the phone number from matlab. the program of matlab and arduino is attached herewith.



matlab code for the given purpose is:


function varargout = sms(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @sms_OpeningFcn, ...
                   'gui_OutputFcn',  @sms_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end



% --- Executes just before sms is made visible.
function sms_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);




function varargout = sms_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
global arduino;    % initiating  arduino as variable
 try
            arduino = serial('COM4','BaudRate',9600);                    % Start Serial communication with arduino at port 12 with baudrate 57600
            fopen(arduino);
           
        catch e
            obj = instrfind;                                               % execute when there is an error
            fclose(obj);
            delete(obj);                                                   % delete object
            i=0;
            arduino = serial('COM4','BaudRate',9600);                    % recreate arduino variable
            fopen(arduino);
 end





function num_Callback(hObject, eventdata, handles)
A =  str2double(get(hObject,'String'));



% --- Executes on button press in sms.
function sms_Callback(hObject, eventdata, handles)
global arduino
fprintf(arduino,'@');
fprintf(arduino,A);






gui of matlab and arduino code is given in the attachments


Robin2

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

The technique in the 3rd example will be the most reliable.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

ieee488

Useless to show Matlab code as we don't program in Matlab here.

If you want help with Matlab code post your question on the Mathworks forums.



.

PaulS

Code: [Select]
            arduino = serial('COM4','BaudRate',9600);                    % Start Serial communication with arduino at port 12 with baudrate 57600

That comment is complete nonsense.
The art of getting good answers lies in asking good questions.

srijis94

Ive changed  the com port when running, but forgot to change it int he command.

Go Up