farhan in MATLAB Answers
最後のアクティビティ: 2022 年 11 月 19 日

function varargout = Program_Gui_Project(varargin) % PROGRAM_GUI_PROJECT MATLAB code for Program_Gui_Project.fig % PROGRAM_GUI_PROJECT, by itself, creates a new PROGRAM_GUI_PROJECT or raises the existing % singleton*. % % H = PROGRAM_GUI_PROJECT returns the handle to a new PROGRAM_GUI_PROJECT or the handle to % the existing singleton*. % % PROGRAM_GUI_PROJECT('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PROGRAM_GUI_PROJECT.M with the given input arguments. % % PROGRAM_GUI_PROJECT('Property','Value',...) creates a new PROGRAM_GUI_PROJECT or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Program_Gui_Project_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Program_Gui_Project_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help Program_Gui_Project % Last Modified by GUIDE v2.5 18-Oct-2022 11:00:27 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Program_Gui_Project_OpeningFcn, ... 'gui_OutputFcn', @Program_Gui_Project_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 % End initialization code - DO NOT EDIT % --- Executes just before Program_Gui_Project is made visible. function Program_Gui_Project_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Program_Gui_Project (see VARARGIN) % Choose default command line output for Program_Gui_Project handles.output = hObject; % Update handles structure guidata(hObject, handles); movegui(hObject,'center'); % UIWAIT makes Program_Gui_Project wait for user response (see UIRESUME) % uiwait(handles.figure1); clear all; global a; a = arduino('COM4','Uno'); configurePin(a,'D7','DigitalOutput'); configurePin(a,'D8','DigitalOutput'); % --- Outputs from this function are returned to the command line. function varargout = Program_Gui_Project_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil menu "browse file" [nama_file, nama_folder] = uigetfile('*.jpg'); %jika ada nama file yang dipilih maka akan mengeksekusi perintah di bawah %ini if ~isequal(nama_file,0) % membaca file citra rgb Img = imread(fullfile(nama_folder,nama_file)); % menampilkan citra rgb pada axes axes(handles.axes1) imshow(Img) title('Citra RGB') %menampilkan nama file pada edit text set(handles.edit1,'String',nama_file) %menyimpan variabel Img pada lokasi handles agar dapat dipanggil oleh %pushbutton yang lain handles.Img = Img; guidata(hObject, handles) else % jika tidak ada nama file yang dipilih maka akan kembali return end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil variabel Img yg ada dilokasi handles Img = handles.Img; % melakukan konversi citra rgb menjadi citra grayscale Img_gray = rgb2gray(Img); %figure, imshow(Img_gray) % melakukan konversi citra grayscale menjadi citra biner bw = imbinarize(Img_gray); % figure, imshow(bw) % melakukan operasi komplemen bw = imcomplement(bw); % figure, imshow(bw) % melakukan operasi morfologi filling holes bw = imfill(bw,'holes'); %menampilkan citra biner pada axes axes(handles.axes2) imshow(bw) title('Citra Biner') %menyimpan variabel bw pada lokasi handles agar dapat dipanggil oleh %pushbutton yang lain handles.bw = bw; guidata(hObject, handles) % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil variabel Img dan bw yang ada di lokasi handles Img = handles.Img; bw = handles.bw; % ekstraksi ciri % melakukan konversi citra rgb menjadi citra hsv HSV = rgb2hsv(Img); % figure, imshow(HSV) % mengekstrak komponen h, s, dan v pada citra hsv H = HSV(:,:,1); %hue S = HSV(:,:,2); % Saturation V = HSV(:,:,3); % Value % menambah nilai pixel background menjadi nol H(~bw) = 0; S(~bw) = 0; % menghitung nilai rat2 h,s, danv Hue = sum(sum(H))/sum(sum(bw)); Saturation = sum(sum(S))/sum(sum(bw)); Value = sum(sum(V))/sum(sum(bw)); % menghitung luas objek Luas = sum(sum(bw)); % mengisi variabel ciri_latih dengan ciri hasil ekstraksi ciri_uji(1,1) = Hue; ciri_uji(1,2) = Saturation; ciri_uji(1,3) = Value; ciri_uji(1,4) = Luas; % menampilkan ciri hasil ekstraksi pada tabel ciri_tabel = cell(4,2); ciri_tabel{1,1} = 'Hue'; ciri_tabel{2,1} = 'Saturation'; ciri_tabel{3,1} = 'Value'; ciri_tabel{4,1} = 'Luas'; ciri_tabel{1,2} = num2str(Hue); ciri_tabel{2,2} = num2str(Saturation); ciri_tabel{3,2} = num2str(Value); ciri_tabel{4,2} = num2str(Luas); set(handles.uitable1,'Data',ciri_tabel,'RowName',1:4) %menyimpan variabel ciri_uji pada lokasi handles agar dapat dipanggil oleh %pushbutton yang lain handles.ciri_uji = ciri_uji; guidata(hObject, handles) % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil ciri_uji yang ada di lokasi handles ciri_uji = handles.ciri_uji; % memanggil model naive bayes hasil pelatihan load Mdl % membaca kelas keluaran hasil pengujian hasil_uji = predict(Mdl,ciri_uji); % menampilkan kelas keluaran pengujian set(handles.edit2,'String',hasil_uji{1}) function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % mereset tampilan GUI set(handles.edit1,'String',[]) set(handles.edit2,'String',[]) axes(handles.axes1) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) axes(handles.axes2) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) set(handles.uitable1,'Data',[],'RowName',{'' '' ''}) % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) global a; writeDigitalPin(a, 'D7', 1); writeDigitalPin(a, 'D8', 1); % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) global a; writeDigitalPin(a, 'D7', 0); writeDigitalPin(a, 'D8', 0); % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
Azad Sheikh in MATLAB Answers
最後のアクティビティ: 2022 年 10 月 20 日

Just tried testing esp32 with sim800L on ThingSpeak free channel. Not sure why getting the "http error code 0" because the channel values are getting inserted with new values. It is functioning, but, would be helpful if someone could point out why the http error code 0 is returned ? int i = ThingSpeak.writeField(myBlowerChannel, 1, temp, myBlowerKey); value of 'i' is coming '0' but the temp data is getting inserted
tasya thifali in MATLAB Answers
最後のアクティビティ: 2022 年 6 月 1 日

I'm using sim800l and arduino uno for monitoring battery. The code has no error, but data not show in thingspeak. this is the code: #include <SoftwareSerial.h> #include <String.h> SoftwareSerial SIM800L(6,7); //Serial SIM800L pin String Write_API_key = "xxxxxxxxxxxxxxxx"; //Thingspeak Write API Key String apn = "internet"; int analogPin = A0; // pin arduino yang terhubung dengan pin S modul sensor tegangan float Vmodul = 0.0; float hasil = 0.0; float R1 = 10000.0; //10k float R2 = 220.0; //220 ohm resistor, float value = 0.0; int persen = 0; void setup(){ Serial.begin(115200); SIM800L.begin(9600); pinMode(analogPin,INPUT); Serial.println("SIM800L GPRS Test"); delay(2000); } void loop(){ SetupModule(); SIM800L.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\""); delay(3000); ShowSerialData(); SIM800L.println("AT+CIPSEND"); delay(2000); Serial.println(); ShowSerialData(); ReadSensor(); String str="GET https://api.thingspeak.com/update?api_key="+Write_API_key+"&field1=" + String(hasil) +"&field2="+String(persen); Serial.println(str); delay(2000); SIM800L.println(str); delay(4000); ShowSerialData(); SIM800L.println((char)26); delay(4000); SIM800L.println(); ShowSerialData(); SIM800L.println("AT+CIPSHUT");//close the connection delay(500); ShowSerialData(); str=""; //total delay looping 50s delay(10000); //add 10s for 60s total delay looping } void ReadSensor(){ value = analogRead(analogPin); Vmodul = (value * 5) / 1024.0; hasil = Vmodul / (R2/(R1+R2)); persen = (hasil/60)*100; Serial.print("\t Tegangan Pembagi = "); Serial.print(Vmodul,2); Serial.print("volt"); Serial.print("\t Hasil pengukuran asli = "); Serial.print(hasil,1); Serial.println("volt"); Serial.print("\t Persentase baterai = "); Serial.print(persen); Serial.println("%"); } void SetupModule(){ if (SIM800L.available())Serial.write(SIM800L.read()); SIM800L.println("AT"); delay(1000); SIM800L.println("AT+CPIN?"); delay(1000); SIM800L.println("AT+CREG?"); delay(1000); SIM800L.println("AT+CGATT?"); delay(1000); SIM800L.println("AT+CIPSHUT");delay(1000); SIM800L.println("AT+CIPSTATUS"); delay(2000); SIM800L.println("AT+CIPMUX=0"); delay(2000); //setting the APN, SIM800L.println("AT+CSTT=\""+apn+"\"");delay(1000); ShowSerialData(); SIM800L.println("AT+CIICR"); delay(2000); ShowSerialData(); //get local IP adress SIM800L.println("AT+CIFSR"); delay(2000); ShowSerialData(); SIM800L.println("AT+CIPSPRT=0");delay(2000); ShowSerialData(); } void ShowSerialData(){ while(SIM800L.available()!=0) Serial.write(SIM800L.read()); delay(2000); }
Johnson Isaac in MATLAB Answers
最後のアクティビティ: 2020 年 4 月 26 日

Pls I need help to read my channel field last value (1 or 0) and in turn switch on a relay connected to my arduino pin using sim800l. I don't know how to go about the code for it. Anyone with a link to an example or a guide pls. My channel field is been updated with a "1" or "0" from my mit app inventor mobile app. In return I want to turn on a relay on/off when this field is updated by using sim800l to be checking the field last value

ThingSpeak について

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.

モデレーター