Arduino Forum

Using Arduino => Interfacing w/ Software on the Computer => Topic started by: srijis94 on Jun 08, 2018, 02:12 pm

Title: how to send 10 digit from matlab to arduino.
Post by: srijis94 on Jun 08, 2018, 02:12 pm
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

Title: Re: how to send 10 digit from matlab to arduino.
Post by: Robin2 on Jun 08, 2018, 02:27 pm
Have a look at the examples in Serial Input Basics (http://forum.arduino.cc/index.php?topic=396450.0) - simple reliable ways to receive data.

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

...R
Title: Re: how to send 10 digit from matlab to arduino.
Post by: ieee488 on Jun 08, 2018, 03:13 pm
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.



.
Title: Re: how to send 10 digit from matlab to arduino.
Post by: PaulS on Jun 11, 2018, 11:49 am
Code: [Select]
            arduino = serial('COM4','BaudRate',9600);                    % Start Serial communication with arduino at port 12 with baudrate 57600

That comment is complete nonsense.
Title: Re: how to send 10 digit from matlab to arduino.
Post by: srijis94 on Jun 12, 2018, 07:18 am
Ive changed  the com port when running, but forgot to change it int he command.