Kode Program Untuk Perangkat Arduino
Lampiran 1
Kode Program Untuk Perangkat Arduino
#include <Wire.h> #include <Adafruit_BMP085.h> Adafruit_BMP085 tinggi; // create a BMP085 object char input; void setup() { Serial.begin(9600); Wire.begin(); tinggi.begin(); } void loop() { input = Serial.read(); switch(input) {
case 'R': // R is sent from Scilab to ask whether Radio is ready or not
Serial.println("Ready"); break;case 'P': // P is sent from Scilab to command Radio start sending data
Serial.println(tinggi.readAltitude()); break; } }Lampiran 2
Kode Program Untuk Scilab /////////////////////////////////////////////////////////////////////////////// // CREATE A WINDOW AND ITS COMPONENTS /////////////////////////////////////////////////////////////////////////////// clear ; gui = createWindow () ; gui . axes_size = [ 770 480 ] ; gui . figure_name = "Skripsi" ; gui . backgroundcolor = [
1
1 1 ] ;
gui . figure_position = [ 320
80 ] ;
gui . resize = "off" ; handles . gui =
1 ;
/////////////////////////////////////////////////////////////////////////////// // Connect Button pbConnect = uicontrol ( gui, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
'position' , [ 20 280
70 20 ] , 'String' , 'Connect' , ... 'HorizontalAlignment' , 'center' , 'Callback' , 'connect' ) ;
// Disconnect Button pbDisconnect = uicontrol ( gui, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
'position' , [ 20 240
70 20 ] , 'String' , 'Disconnect' , ... 'HorizontalAlignment' , 'center' , 'Callback' , 'disconnect' ) ;
// Plotting Button pbPlot = uicontrol ( gui, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
'position' , [ 20 200
70 20 ] , 'String' , 'Plot' , ... 'HorizontalAlignment' , 'center' , 'Callback' , 'dataPlot' ) ;
// Stop the Plotting Button pbStop = uicontrol ( gui, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
'position' , [ 20 160
70 20 ] , 'String' , 'Stop Plotting' , ... 'HorizontalAlignment' , 'center' , 'Callback' , 'stop' ) ;
// Load Data Button pbCallLoad = uicontrol ( gui, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
'position' , [ 20 120
70 20 ] , 'String' , 'Load' , ... 'HorizontalAlignment' , 'center' , 'Callback' , 'callDataLoad' ) ;
// Save and Exit Button pbCallSaveandExit = uicontrol ( gui, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
'position' , [ 348
70 20 ] , 'String' , 'Save & Exit' , ... 'HorizontalAlignment' , 'center' , ... 'Callback' , 'callSaveExit' ) ;
/////////////////////////////////////////////////////////////////////////////// // A place for Axes
handles . frame4axes = uicontrol ( gui, 'Style' , 'frame' , 'Position' , [ 150 120 450 360 ] , ...
'HorizontalAlignment' , 'center' , ... 'Background' , [
1
1 1 ]) ;
// A place for Status Text handles . frame4status = uicontrol ( gui, 'Relief' , 'solid' , ...
'Style' , 'frame' , 'Position' , [
40 30 695 80 ] , ... 'HorizontalAlignment' , 'center' , ... 'Background' , [
1
1 1 ]) ;
// Title for the place of Status Text handles . frame4statusTitle = uicontrol ( gui, 'Style' , 'text' , 'String' , 'Status' , ...
'Position' , [ 60 100
50 20 ] , ... 'HorizontalAlignment' , 'center' , ... 'Background' , [
1
1 1 ]) ;
// Status Text handles . txtStatus = uicontrol ( gui, 'Style' , 'text' , 'Position' , [
50 40 675 60 ] , ... 'FontSize' , [ 16 ] , 'FontWeight' , 'bold' , ... 'HorizontalAlignment' , 'left' , ... 'Background' , [
1
1 1 ]) ;
set ( handles . txtStatus , "String" , "Welcome" ) ; /////////////////////////////////////////////////////////////////////////////// // A place for Height Variable each second parameter = [ " " "Height" ] ; awalTabel1 = [ "detik 1" "detik 2" "detik 3" "detik 4" "detik 5" "detik 6" , ...
"detik 7" "detik 8" "detik 9" "detik 10" ] ' ;
awalTabel2 = [ " " " " " " " " " " " " " " " " " " " " ] ' ; table = [ parameter; [ awalTabel1 awalTabel2 ]] ; handles . tableTinggi = uicontrol ( gui, 'Style' , 'table' , 'String' , table, ...
'Position' , [ 600 163 150 187 ]) ;
/////////////////////////////////////////////////////////////////////////////// // What is the height now? handles . txtHeight = uicontrol ( gui, 'Style' , 'text' , 'Position' , [ 600 420
60 20 ] , ... 'FontSize' , [ 12 ] , 'FontWeight' , 'bold' , ... 'HorizontalAlignment' , 'left' , ... 'Background' , [
1
1 1 ]) ;
set ( handles . txtHeight , "String" , "Height :" ) ; handles . txtHeightVar = uicontrol ( gui, 'Style' , 'text' , 'Position' , [ 660 420
50 20 ] , ... 'FontSize' , [ 12 ] , 'FontWeight' , 'bold' , ... 'HorizontalAlignment' , 'center' , ... 'Background' , [
1
1 1 ]) ;
handles . txtMeter = uicontrol ( gui, 'Style' , 'text' , 'Position' , [ 710 420
40 20 ] , ... 'FontSize' , [ 12 ] , 'FontWeight' , 'bold' , ... 'HorizontalAlignment' , 'right' , ... 'Background' , [
1
1 1 ]) ;
set ( handles . txtMeter , "String" , "Meter" ) ; /////////////////////////////////////////////////////////////////////////////// // Creating an Axes handles . axes1 = newaxes ( handles . frame4axes ) ; // Axes1 title and axis handles . axes1 . title . text = "Height" ; handles . axes1 . title . font_size =
4 ;
handles . axes1 . data_bounds = [ , ;
10 , 150 ] ;
handles . axes1 . axes_visible = "on" ;
// Axes1 X label handles . axes1 . x_label . text = "Time (Second)" ; handles . axes1 . x_label . font_size =
2 ;
// Axes1 Y label handles . axes1 . y_label . text = "Height (Meter)" ; handles . axes1 . y_label . font_size =
2 ;
// Initialization global b t h panjang tinggi GUIstatus PLOTstatus SAVEstatus FilePath k GUIstatus = ; PLOTstatus = ; SAVEstatus = ; k = ; panjang =
41 ; // terdapat 41 sampel data ketinggian
b = zeros (
1 ,panjang ) ; // membuat tempat 1 x 41 untuk data ketinggian
tinggi = zeros (
1 , 10 ) ; // variabel untuk data ketinggian per detik
t = :
0.25 : 10 ; // banyaknya waktu sampel
h = 150 ; // tinggi pada axis Y FilePath = 'C:\Users\ASUS\Desktop\DATA\Scilab files\SOD files\' ; /////////////////////////////////////////////////////////////////////////////// // CALLBACK FOR EACH BUTTON /////////////////////////////////////////////////////////////////////////////// // Connect to Arduino through Radio function connect global radio GUIstatus // Koneksi antara penerima dan pengirim belum terhubung (GUIstatus = 0) if GUIstatus == then radio = openserial (
6 , "9600,n,8,1" ) ;
sleep ( 2000 ) ; writeserial ( radio, "R" ) ; sleep ( 1000 ) ; set ( handles . txtStatus , "String" , readserial ( radio )) ; readserial ( radio ) ;
GUIstatus =
1 ;
else messagebox ( "Laptop has connected to Arduino." , "MA Corp" , "info" ) ; end endfunction // Disconnect from Arduino function disconnect global radio GUIstatus
// Menutup koneksi jika penerima dan pengirim masih terhubung (GUIstatus = 1)
if GUIstatus ==1 then
closeserial ( radio ) ; set ( handles . txtStatus , "String" , "Disconnected." ) ;
GUIstatus = ; else messagebox ( "Arduino is not connected." , "Error" , "error" ) ; end endfunction function dataPlot
global a b t z k panjang height tinggi radio GUIstatus PLOTstatus SAVEstatus
awalTabel2 = [ " " " " " " " " " " " " " " " " " " " " ] ' ; table = [ parameter; [ awalTabel1 awalTabel2 ]] ; set ( handles . tableTinggi , "String" ,table ) ; // Menghapus tabel delete ( handles . axes1 . children ) ; // Menghapus grafik // Membuat tombol selain tombol "Stop Plotting" dalam keadaan OFF set ( pbConnect, 'Enable' , 'Off' ) ; set ( pbDisconnect, 'Enable' , 'Off' ) ; set ( pbPlot, 'Enable' , 'Off' ) ; set ( pbCallLoad, 'Enable' , 'Off' ) ; set ( pbCallSaveandExit, 'Enable' , 'Off' ) ; if GUIstatus ==1 then
PLOTstatus =
1 ;
set ( handles . txtStatus , "String" , "Processing and Plotting Data..." ) ; for z =
1 : panjang
//Terdapat 40 data sampel, sehingga untuk mengumpulkannya selama //10 detik, 1 data sampel membutuhkan 0.25 detik //0.250 - 0.041 - 0.005 = 0.204 = 203 writeserial ( radio, "P" ) ; // 0.001 second sleep ( 203 ) ; // 0.204 a = strtod ( readserial ( radio )) ; // 0.001 second, data diubah dari
//string menjadi double b ( z ) = a; // 0.001 second plot ( t (
1 : z ) ,b ( 1 : z )) ; // 0.041 second
// Interupsi jika tombol "Stop Plotting" ditekan (k = 1) if k ==
1 then // 0.001 second
k = ; break ; end set ( handles . txtHeightVar , "String" , sci2exp ( a )) ; // 0.001 second end set ( handles . txtStatus , "String" , "Done." ) ;
SAVEstatus =
1 ;
// Memuat data ketinggian setiap detik dalam tabel for z =
1 :
10
tinggi ( z ) = b ( z
- 4 ) ;
end height = tinggi ' ; awalTabel2 = string ([ height ]) ; table = [ parameter; [ awalTabel1 awalTabel2 ]] ; set ( handles . tableTinggi , "String" ,table ) ; else messagebox ( "Arduino is not connected." , "Warning" , "passwd" ) ; end
PLOTstatus = ; // Tidak ada plotting yang berjalan // Membuat tombol kembali ke keadaan ON set ( pbConnect, 'Enable' , 'On' ) ; set ( pbDisconnect, 'Enable' , 'On' ) ; set ( pbPlot, 'Enable' , 'On' ) ; set ( pbCallLoad, 'Enable' , 'On' ) ; set ( pbCallSaveandExit, 'Enable' , 'On' ) ; endfunction
// Interrupt and stop the plot function stop global k radio PLOTstatus SAVEstatus if PLOTstatus ==
1 then
k =
1 ;
else messagebox ( "Nothing Happened." , "MA Corp" , "warning" ) ; end endfunction // Load and plot the saved data function callDataLoad global FilePath FileNameH1 FileNameH0 FullPath guiLoad guiLoad = createWindow () ; guiLoad . axes_size = [ 220
80 ] ;
guiLoad . figure_name = "Load File Name" ; guiLoad . backgroundcolor = [
1
1 1 ] ;
guiLoad . figure_position = [ 620 200 ] ; guiLoad . resize = "off" ; FileNameH1 = uicontrol ( guiLoad, 'Style' , 'edit' , ...
'Position' , [
3 58 123 20 ] , ... 'FontSize' , [ 10 ] , 'HorizontalAlignment' , 'left' ) ;
set ( FileNameH1, "String" , "H1 File Name..." ) ; FileNameH0 = uicontrol ( guiLoad, 'Style' , 'edit' , ...
'Position' , [
3 16 123 20 ] , ... 'FontSize' , [ 10 ] , 'HorizontalAlignment' , 'left' ) ;
set ( FileNameH0, "String" , "H0 File Name..." ) ; pbLoad = uicontrol ( guiLoad, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
'position' , [ 101
25
70 20 ] , 'String' , 'Load' , ... 'HorizontalAlignment' , 'center' , 'Callback' , 'dataLoad' ) ;
endfunction function dataLoad
global SAVEstatus FilePath FileNameH1 FileNameH0 FullPath guiLoad
SAVEstatus = ; delete ( handles . axes1 . children ) ;
//Memuat data b, t, dan tinggi untuk H0 dengan dari file LoadFileNameH0
LoadFileNameH0 = get ( FileNameH0, "String" ) ; FullPath = strcat ([ FilePath,LoadFileNameH0 ]) ; // Memuat data b, t, dan tinggi FileName dengan path FullPath load ( FullPath, 'b' , 't' , 'tinggi' ) ;
H0Data = b; H0 = tinggi ' ;
//Memuat data b, t, dan tinggi untuk H1 dengan dari file LoadFileNameH1
LoadFileNameH1 = get ( FileNameH1, "String" ) ; FullPath = strcat ([ FilePath,LoadFileNameH1 ]) ;
load ( FullPath, 'b' , 't' , 'tinggi' ) ; H1Data = b; H1 = tinggi ' ;
guiSave . figure_position = [ 620 240 ] ; guiSave . resize = "off" ; FileName = uicontrol ( guiSave, 'Style' , 'edit' , 'Position' , [
else set ( handles . txtStatus , "String" , "Nothing to be saved." ) ; sleep ( 1000 ) ; set ( handles . txtStatus , "String" , "Closing GUI..." ) ; sleep ( 1000 ) ; close ( gui ) ; end endfunction function saveExit global b t tinggi FilePath FileName FullPath guiSave // Menyimpan variabel b, t, dan tinggi ke FullPath // Disimpan dengan nama SaveFileName
70 20 ] , 'String' , 'Save' , ... 'HorizontalAlignment' , 'center' , 'Callback' , 'saveExit' ) ;
10
'position' , [ 101
set ( FileName, "String" , "Enter File Name..." ) ;
pbSaveandExit = uicontrol ( guiSave, 'Style' , 'pushbutton' , 'Units' , 'points' , ...
3 15 123 20 ] , ... 'FontSize' , [ 10 ] , 'HorizontalAlignment' , 'left' ) ;
1 1 ] ;
// Memuat data dalam grafik plot ( t,H1Data, 'b-' ,t,H0Data, 'r-' ) ; legends ([ 'H1' ; 'H0' ] , [[
1
guiSave . figure_name = "Save File Name" ; guiSave . backgroundcolor = [
40 ] ;
guiSave = createWindow () ; guiSave . axes_size = [ 220
1 then
// Memuat data dalam tabel parameter = [ " " "H1" "H0" ] ; awalTabel2 = string ([ H1 ]) ; awalTabel3 = string ([ H0 ]) ; table = [ parameter; [ awalTabel1 awalTabel2 awalTabel3 ]] ; set ( handles . tableTinggi , "String" ,table ) ; set ( handles . txtStatus , "String" , "Loaded." ) ; close ( guiLoad ) ; endfunction // Save data and exit function callSaveExit global SAVEstatus FileName guiSave if SAVEstatus ==
2 ; 1 ] , [ 5 ; 1 ]] ,opt = "ur" ) ;
SaveFileName = get ( FileName, "String" ) ; FullPath = strcat ([ FilePath,SaveFileName ]) ; save ( FullPath, 'b' , 't' , 'tinggi' ) ; close ( guiSave ) ; set ( handles . txtStatus , "String" , "Saving..." ) ; sleep ( 1000 ) ; close ( gui ) ;
Tampilan GUI Scilab