Cov txheej txheem:

Autostat: Lub Chaw Taws Teeb Kub Kub: 8 Kauj Ruam (nrog Duab)
Autostat: Lub Chaw Taws Teeb Kub Kub: 8 Kauj Ruam (nrog Duab)

Video: Autostat: Lub Chaw Taws Teeb Kub Kub: 8 Kauj Ruam (nrog Duab)

Video: Autostat: Lub Chaw Taws Teeb Kub Kub: 8 Kauj Ruam (nrog Duab)
Video: Mus Lawm Txhob Tig Rov. 1/13/2021 2024, Kaum ib hlis
Anonim
Autostat: Lub Chaw Taws Teeb Kub Kub
Autostat: Lub Chaw Taws Teeb Kub Kub

Cov lus nug uas koj yuav tau nug yog "vim li cas koj thiaj ua lwm qhov ntsuas cua sov nyob deb?"

Cov lus teb rau lo lus nug ntawd yog, Kuv yuav tsum, thiab kev lag luam ntsuas cua sov yog kim heev.

Kev ceeb toom ncaj ncees, qhov no yog "pov thawj-ntawm-tswvyim" tsim uas yuav xav tau ob peb qhov txiaj ntsig ntxiv los tswj koj lub ntsuas cua sov, tab sis cov tub ntxhais tseem nyob hauv qhov chaw thiab tuaj yeem hloov kho raws li koj qhov xwm txheej tshwj xeeb. Tsis tas li, qhov no tseem yog txoj haujlwm tseem tab tom ua, yog li cia siab tias yuav muaj qee qhov hloov tshiab thiab hloov pauv (tshwj xeeb tshaj yog rau Matlab code)

Txhawm rau pib kuv xav ceeb toom koj, qhov no yuav tsum muaj peb txoj haujlwm (ib ntawm lawv kim heev), ob peb lub tsev qiv ntawv thiab txhawb nqa pob rau cov haujlwm, thiab koj yuav tsum kom lawv txhua tus tham nrog ib leeg. Nws mob taub hau. Nrog qhov ceeb toom tawm ntawm txoj hauv kev cia pib nrog cov ntaub ntawv.

Kho vajtse

  • arduino nano cov
  • arduino uno (lossis lwm lub nano, Kuv tsuas yog siv uno vim tias kuv muaj ib qho tso nyob ib puag ncig)
  • assorted jumper cables, qee tus txiv neej/txiv neej thiab ob pawg ntawm peb koom nrog txiv neej/poj niam dhia
  • 433MHz xov tooj cua zaus (RF) tus txais, Kuv siv MX-05V
  • 433MHz RF transmitter, Kuv siv MX-FS-03V
  • DHT11 tus ntsuas kub thiab ntsuas qhov ntsuas qhov tseeb (qhov kuv siv tau teeb tsa ntawm peb lub ntsej muag nti nrog qhov xav tau tiv thaiv twb tau teeb tsa)
  • breadboard (yog tias koj tsis xav kom qhov no tag nrho ua ke)
  • lub xov tooj nrog GPS (iPhone 8 hauv qhov no, tab sis kuv kuj tau siv Galaxy S8)
  • 3D ntim lub thawv (tsis tsim nyog tiag tiag, ib lub thawv twg yuav ua haujlwm lossis tsis muaj hlo li)

Software

  • Matlab los ntawm MathWorks (Kuv muaj 2018a tsab, tab sis kuv tau siv 2017a-b cov ntawv ib yam nkaus)
  • Matlab mobile tau teeb tsa ntawm koj lub xov tooj
  • arduino pob txhawb nqa rau Matlab
  • iPhone sensor pob rau Matlab
  • arduino IDE
  • RadioHead txhawb pob thiab tsev qiv ntawv ntawm arduino IDE
  • DHT11 tsev qiv ntawv rau arduino IDE
  • nab hab sej 3.7 (xyuas kom lub tsev qiv ntawv pyserial lossis cov tsev qiv ntawv txuas tau teeb tsa, uas nws yuav tsum yog rau version 3.4 lossis tshiab dua)

Kauj Ruam 1: Muab tag nrho ua ke

Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke

Ua ntej tshaj plaws kuv xav qhia koj ua ob peb qhov kev qhia paub txog kev cuam tshuam nrog RF cov xa xov tsuas yog kom paub tseeb tias koj cov khoom ua haujlwm thiab cov hlua txuas raug. Muaj ntau qhov piv txwv muaj, nrog rau cov cai suav nrog (rau peb ntawm qhov uas paub me ntsis rau tsis muaj dab tsi txog C thiab C ++).

Ua raws cov kab duab kab hauv qab no kom tau txais cov arduino thiab cov khoom sib dhos ua ke. Ib yam uas yuav tsum nco ntsoov thaum txuas mus rau arduinos yog tias cov ntaub ntawv chaw nres nkoj kuv siv tsis xav tau tab sis pom zoo.

Yog tias koj txiav txim siab hloov pauv cov ntaub ntawv chaw nres nkoj koj siv, koj tsuas yog yuav tsum txhais cov pins hauv koj cov cai. Tus kheej, Kuv xav tias nws yooj yim dua nrog cov chaw nres nkoj pib uas cov tsev qiv ntawv arduino lees paub.

Thiab tsuas yog kom pom tseeb, nano thiab uno yog sib pauv tau, tab sis kuv siv nano rau lub tshuab xa xov sab ntawm txoj haujlwm kom txo qhov ntsuas ntawm qhov ntsuas kub.

Nco tseg sab: qhov ntsuab tsis zoo tuav lub nano yog lub thawv 3D luam tawm.

Kauj ruam 2: Txais

Txais
Txais

Kauj ruam 3: Transmitter

Tshaj Tawm
Tshaj Tawm

Kauj ruam 4: Txoj Cai

Thaum cov kab txuas tiav koj yuav tsum tau txais txhua cov haujlwm uas tau ua haujlwm thiab cov tsev qiv ntawv tau teeb tsa (yog tias koj tsis tau ua dua), Kuv tsuas yog xav tias koj muaj, koj yuav tsum pib ua Matlab thiab ua haujlwm pob txhawb nqa iPhone. Koj lub xov tooj thiab Matlab yuav tsum nyob rau tib lub network wifi ntawm qhov no.

Hauv qhov hais kom ua qhov rai ntawm Matlab sau:

connector rau

Qhov no yuav qhia koj kom nkag mus rau tsib tus lej lej uas koj yuav siv los txuas rau koj lub iPhone. Nco ntsoov tias koj nco qab tus password. Thaum koj tau nkag mus rau tus password Matlab yuav tso tawm qee cov ntaub ntawv, suav nrog koj tus IP chaw nyob. Siv qhov no hauv cov kauj ruam tom ntej, uas los ntawm cov lus qhia los ntawm "Pib nrog cov ntsuas" pab qhia zaub mov hauv Matlab mobile.

  • Ua raws cov theem no kom xa cov ntaub ntawv ntsuas mus rau MathWorks Cloud lossis lub khoos phis tawj:
  • Yog tias koj tab tom xa cov ntaub ntawv ntsuas mus rau lub khoos phis tawj thiab yog tias nws tseem tsis tau teeb tsa, rub tawm thiab teeb tsa MATLAB Txhawb Pob rau Apple iOS Sensors hauv MATLAB.
  • Txuas MATLAB Txawb rau MathWorks Huab lossis khoos phis tawj siv Chaw.
  • Tsim cov khoom mobiledev hauv MATLAB (ntawm koj lub computer), piv txwv li: >> m = mobiledev
  • Xaiv ib lossis ntau qhov ntsuas thiab coj mus rhaub Pib.

Ua raws li cov theem no txhawm rau txheeb xyuas cov ntaub ntawv sensor hauv zos ntawm koj lub cuab yeej:

  • Ntawm lub vijtsam Sensors, xaiv cov ntsuas uas koj xav khaws cov ntaub ntawv los ntawm.
  • Xaiv Log.
  • Coj mus rhaub khawm Pib.
  • Thaum koj ua tiav kev khaws cov ntaub ntawv, coj mus rhaub khawm Nres.
  • Hauv qhov pop-up, sau lub npe ntawm lub cav sensor.
  • Rov ua cov kauj ruam 1-5 yog xav tau.

Tshooj lus no yuav raug xa rov qab mus rau Tshooj 4, yog li tsis tas yuav pib sau cov ntaub ntawv tseem. Tsuas yog khaws koj lub xov tooj kom yooj yim thiab Matlab mobile npaj tau.

Tam sim no koj yuav tsum tsim daim nplaub tshev nyob qhov twg hauv koj lub khoos phis tawj kom nyob hauv tsev Matlab code cov ntaub ntawv. Koj yuav muaj plaub cov ntaub ntawv cais, ob qho rau cov haujlwm yav dhau los (.m cov ntaub ntawv) thiab ib qho Matlab code cov ntaub ntawv rau GUI (.mlapp),.

Ua ntej tshaj yog kev suav huab cua rau hauv koj lub tsev (qhov no cia Matlab paub ntev npaum li cas nws thiaj sov/txias koj lub tsev)

function [Pawg] = CalcMass (T_ins, P_out, Chng_dir)

runCalc = 0; Tmp_start = T_ins; time_start = moos; time_end = 0 thaum runCalc <= 1 yog T_ins == (Tmp_start+(7*Chng_dir)) time_end = moos; PwrCntr = 0; runCalc = 0; else PwrCntr = P_out; runCalc = runCalc+0.1 kawg kawg time_diag = time_end-time_start Mass = (P_out*time_diag) /7.035

Thiab qhov thib ob:

muaj nuj nqi [timestamps, pwr_usage] = dist_cntrl (Lat_in, Lon_in, P_out, r_pref, nrawm, T_pref, pawg)

AutoStat = 1; kuv = 1; thaum AutoStat == 1 time_start = moos; m = mobiledev; t = csvread ('values.csv', 0, 1); t = t (kuv); timestamps = [0, 0, 0, 0, 0, 0, 0]; pwr_usage = 0; kuv = kuv+1; format loj; %haversine mis rau xam nrug raws latitude thiab %longintude a_hav = (sind ((m. Latitude-Lat_in)./2)).^2+cosd (Lat_in).*cosd (m.latitude).*(sind ((m. Longitude -Lon_in)./ 2)).^2; c_hav = 2.*atan2d (sqrt (a_hav), sqrt (1-a_hav)); d_hav = 6371.*c_hav; Dist = d_hav.*1000; %kwv yees koj lub sijhawm kom rov qab time_rtn = (Dist-r_pref)./ nrawm; %suav qhov tsim nyog ntsuas cua sov raws li lub zog tso tawm ntawm %lub tshuab cua txias thiab cua hauv tsev. calcTmp_set = ((-1.*P_out.*time_rtn)./ (pawg.*(1.005)))+T_pref; %txiav txim siab seb qhov ntsuas cua sov tam sim no yuav tsum tau hloov yog puag ncig (calcTmp_set) ~ = puag ncig (t) timeACon = moos; PwrCntr = P_out; timeACon = timeACon + moos-sijhawm_start; tus nqi = P_out*timeACon*tus nqi; lwm tus PwrCntr = 0 kawg timestamps (kawg+1, [1: 6]) = moos; pwr_usage (kawg+1, 1) = PwrCntr; ncua (5) xaus kawg

Ob qho ntawm cov ntaub ntawv no yog Matlab ua haujlwm. Koj yuav tsis xav tau nkag mus tshwj tsis yog koj npaj yuav hloov kho lawv rau qhov xav tau tshwj xeeb, txij li koj yuav tau hu lawv los ntawm GUI. Txuag ob qho ntaub ntawv sib cais, thawj qhov yog CalcMass.m thiab thib ob li dist_cntrl.m, cov ntawd yuav yog cov npe uas GUI code siv los hu lub luag haujlwm, yog li tshwj tsis yog koj xav hloov kho cov cai hauv qab no, lo nrog convention npe.

Ua ntej koj nkag mus rau hauv GUI code, koj yuav tsum qhib lub app designer rau Matlab, uas koj tuaj yeem qhib los ntawm kev tshawb nrhiav hauv Matlab ntawv qhia zaub mov bar, lossis los ntawm kuv txoj kev nyiam uas tau nkag mus rau cov lus txib hauv qab no hauv Matlab qhov rai hais kom ua:

appdesigner

Thaum lub app designer tau qhib qhib daim ntawv thov app tshiab (.mlapp) thiab tshem tawm txhua qhov ntawm lub hauv paus chaws los ntawm lub qhov rai chaws. Tom qab ntawd hloov tag nrho nws nrog cov hauv qab no thiab ntaus khawm khiav.

classdef Control_1 <matlab.apps. AppBase % Cov khoom uas sib xws rau cov khoom sib xyaw app (Nkag mus rau = pej xeem) UIFigure matlab.ui. Figure TabGroup matlab.ui.container. TabGroup SetupTab matlab.ui.container. Tab RunDiagnosticButton matlab.ui.control. Button EnergyEfficiencyRatingEditFieldLabel matlab.ui.control. Label EnergyEfficiencyRatingEditField matlab.ui.control. NumericEditField PowerOutputRatingEditFieldLabel matlab.ui.control. Label PowerOutputRatingEditField matlab.ui.control. NumericEditField AvgLocalSpeedEditFieldLabel matlab.ui.control. Label AvgLocalSpeedEditField matlab.ui.control. NumericEditField DesiredDistancefromHouseEditFieldLabel matlab.ui.control. Label DDFH matlab.ui.control. NumericEditField TemperatureDirectionSwitchLabel matlab.ui.control. Label TemperatureDirectionSwitch matlab.ui.control. Switch TempSettingsTab matlab.ui.container.abel ui.control. Spinner Kub 2SpinnerLabel matlab.ui.cont rol. Label Temperature2Spinner matlab.ui.control. Spinner Hloov matlab.ui.control. Switch EditFieldLabel matlab.ui.control. Label tempnow matlab.ui.control. NumericEditField GaugeLabel matlab.ui.control. Labelaucau Gauge SavingsTab matlab.ui.container. Tab UIAxes matlab.ui.control. UIAxes ThisMonthCostEditFieldLabel matlab.ui.control. Label ThisMonthCostEditField matlab.ui.control. NumericEditField TotalSavingsEont. Lab. Lab.

txoj kev (Nkag mus = ntiag tug)

% Tus nqi hloov pauv muaj nuj nqi: tempnow

muaj nuj nqi tempnowValueChanged (app, xwm txheej) temp = app.tempnow. Value; temp = randi ([60, 90], 1, 50) app. Gauge. Value = 0 rau i = ntev (temp) app. Gauge. Value = temp (i) ncua (1) kawg kawg

% Tus nqi hloov pauv muaj nuj nqi: Kub Kub

muaj nuj nqi TemperatureDirectionSwitchValueChanged (app, xwm txheej) txoj kev = app. TemperatureDirectionSwitch. Value; txoj kev = uint8 (txoj kev) txoj kev = ntev (txoj kev) yog txoj kev == 4 Chng_dir = -1; lwm Chng_dir = 1; kawg Chng_dir; kawg

% Tus nqi hloov pauv: DDFH

muaj nuj nqi DDFHValueChanged (app, xwm txheej) r_pref = app. DDFH. Value; kawg

% Tus nqi hloov pauv muaj nuj nqi: AvgLocalSpeedEditField

muaj nuj nqi AvgLocalSpeedEditFieldValueChanged (app, xwm txheej) nrawm = app. AvgLocalSpeedEditField. Value; kawg

% Tus nqi hloov pauv muaj nuj nqi: PowerOutputRatingEditField

muaj nuj nqi PowerOutputRatingEditFieldValueChanged (app, xwm txheej) tus nqi = app. PowerOutputRatingEditField. Value; kawg

% Tus nqi hloov pauv kev ua haujlwm: Kev Ua Haujlwm Zoo RatingEditField

muaj nuj nqi EnergyEfficiencyRatingEditFieldValueChanged (app, xwm txheej) tus nqi = app. EnergyEfficiencyRatingEditField. Value; kawg

% Khawm thawb muaj nuj nqi: RunDiagnosticButton

muaj nuj nqi RunDiagnosticButtonPushed (app, xwm txheej) txoj kev = app. TemperatureDirectionSwitch. Value; txoj kev = uint8 (txoj kev) txoj kev = ntev (txoj kev) yog txoj kev == 4 Chng_dir = -1; lwm Chng_dir = 1; kawg T_ins = app.tempnow. Value P_out = app. PowerOutputRatingEditField. Value CalcMass1 (T_ins, P_out, Chng_dir)

kawg

% Tus nqi hloov pauv kev ua haujlwm: Kub 1Spinner

muaj nuj nqi Temperature1SpinnerValueChanged (app, event) tus nqi = app. Temperature1Spinner. Value; kawg

% Tus nqi hloov pauv muaj nuj nqi: Kub 2Spinner

muaj nuj nqi Temperature2SpinnerValueChanged (app, event) tus nqi = app. Temperature2Spinner. Value; kawg

% Tus nqi hloov pauv: Hloov

muaj nuj nqi SwitchValueChanged (app, xwm txheej) m = mobiledev; Lat_in = m. Latitude Lon_in = m. Longitude P_out = 0; r_pref = app. DDFH. Value; T_pref = app. Temperature1Spinner. Value; ceev = m. Speed; mas = 200; ceev = app. AvgLocalSpeedEditField. Value; Auto_Stat = app. Switch. Value; dist_cntrl (Lat_in, Lon_in, P_out, r_pref, T_pref, nrawm, huab hwm coj) kawg kawg

% App pib thiab tsim kho

txoj kev (Nkag mus = ntiag tug)

% Tsim UIFigure thiab cov khoom siv

muaj nuj nqi createComponents (app)

% Tsim UIFigure

app. UIFigure = uifigure; app. UIFigure. Position = [100 100 640 480]; app. UIFigure. Name = 'UI Daim Duab';

% Tsim TabGroup

app. TabGroup = uitabgroup (app. UIFigure); app. TabGroup. Position = [1 1 640 480];

% Tsim SetupTab

app. SetupTab = uitab (app. TabGroup); app. SetupTab. Title = 'Teeb';

% Tsim RunDiagnosticButton

app. RunDiagnosticButton = uibutton (app. SetupTab, 'thawb'); app. RunDiagnosticButton. ButtonPushedFcn = createCallbackFcn (app, @RunDiagnosticButtonPushed, muaj tseeb); app. RunDiagnosticButton. FontWeight = 'bold'; app. RunDiagnosticButton. Position = [465 78 103 23]; app. RunDiagnosticButton. Text = 'Khiav Diagnostic';

% Tsim Kev Siv Zog Txiaj Ntsig RatingEditFieldLabel

app. EnergyEfficiencyRatingEditFieldLabel = uilabel (app. SetupTab); app. EnergyEfficiencyRatingEditFieldLabel. HorizontalAlignment = 'yog'; app. EnergyEfficiencyRatingEditFieldLabel. Position = [8 425 135 22]; app. EnergyEfficiencyRatingEditFieldLabel. Text = 'Kev Ntsuam Xyuas Kev Txom Nyem Zog';

% Tsim Kev Siv Zog Txiaj Ntsig RatingEditField

app. EnergyEfficiencyRatingEditField = uieditfield (app. SetupTab, 'lej'); app. EnergyEfficiencyRatingEditField. Limits = [0 100]; app. EnergyEfficiencyRatingEditField. ValueChangedFcn = createCallbackFcn (app, @EnergyEfficiencyRatingEditFieldValueChanged, muaj tseeb); app. EnergyEfficiencyRatingEditField. HorizontalAlignment = 'chaw'; app. EnergyEfficiencyRatingEditField. Position = [158 425 100 22];

% Tsim PowerOutputRatingEditFieldLabel

app. PowerOutputRatingEditFieldLabel = uilabel (app. SetupTab); app. PowerOutputRatingEditFieldLabel. HorizontalAlignment = 'txoj cai'; app. PowerOutputRatingEditFieldLabel. Position = [18 328 118 22]; app. PowerOutputRatingEditFieldLabel. Text = 'Rating Output Rating';

% Tsim PowerOutputRatingEditField

app. PowerOutputRatingEditField = uieditfield (app. SetupTab, 'lej'); app. PowerOutputRatingEditField. Limits = [0 Inf]; app. PowerOutputRatingEditField. ValueChangedFcn = createCallbackFcn (app, @PowerOutputRatingEditFieldValueChanged, muaj tseeb); app. PowerOutputRatingEditField. HorizontalAlignment = 'chaw'; app. PowerOutputRatingEditField. Position = [151 328 100 22];

% Tsim AvgLocalSpeedEditFieldLabel

app. AvgLocalSpeedEditFieldLabel = uilabel (app. SetupTab); app. AvgLocalSpeedEditFieldLabel. HorizontalAlignment = 'txoj cai'; app. AvgLocalSpeedEditFieldLabel. Position = [27 231 100 22]; app. AvgLocalSpeedEditFieldLabel. Text = 'Avg. Local ceev ';

% Tsim AvgLocalSpeedEditField

app. AvgLocalSpeedEditField = uieditfield (app. SetupTab, 'lej'); app. AvgLocalSpeedEditField. Limits = [0 70]; app. AvgLocalSpeedEditField. ValueChangedFcn = createCallbackFcn (app, @AvgLocalSpeedEditFieldValueChanged, muaj tseeb); app. AvgLocalSpeedEditField. HorizontalAlignment = 'chaw'; app. AvgLocalSpeedEditField. Position = [142 231 100 22];

% Tsim DesiredDistancefromHouseEditFieldLabel

app. DesiredDistancefromHouseEditFieldLabel = uilabel (app. SetupTab); app. DesiredDistancefromHouseEditFieldLabel. HorizontalAlignment = 'txoj cai'; app. DesiredDistancefromHouseEditFieldLabel. Position = [24 129 100 28]; app. DesiredDistancefromHouseEditFieldLabel. Text = {'Xav Tau Nyob Ze'; 'los ntawm Lub Tsev'};

% Tsim DDFH

app. DDFH = uieditfield (app. SetupTab, 'lej'); app. DDFH. Limits = [0 50]; app. DDFH. ValueChangedFcn = createCallbackFcn (app, @DDFHValueChanged, muaj tseeb); app. DDFH. HorizontalAlignment = 'chaw'; app. DDFH. Position = [139 135 100 22];

% Tsim Kev Kub KubDirectionSwitchLabel

app. TemperatureDirectionSwitchLabel = uilabel (app. SetupTab); app. TemperatureDirectionSwitchLabel. HorizontalAlignment = 'chaw'; app. TemperatureDirectionSwitchLabel. Position = [410 343 124 22]; app. TemperatureDirectionSwitchLabel. Text = 'Kev Taw Qhia Kub';

% Tsim Kev Kub KubDirectionSwitch

app. TemperatureDirectionSwitch = uiswitch (app. SetupTab, 'swb'); app. TemperatureDirectionSwitch. Items = {'Up', 'Down'}; app. TemperatureDirectionSwitch. ValueChangedFcn = createCallbackFcn (app, @TemperatureDirectionSwitchValueChanged, muaj tseeb); app. TemperatureDirectionSwitch. Position = [449 380 45 20]; app. TemperatureDirectionSwitch. Value = 'nce';

% Tsim TempSettingsTab

app. TempSettingsTab = uitab (app. TabGroup); app. TempSettingsTab. Title = 'Temp. Chaw ';

% Tsim Kub Kub1SpinnerLabel

app. Temperature1SpinnerLabel = uilabel (app. TempSettingsTab); app. Temperature1SpinnerLabel. HorizontalAlignment = 'chaw'; app. Temperature1SpinnerLabel. Position = [66 363 76 28]; app. Temperature1SpinnerLabel. Text = {'Kub'; '#1'};

% Tsim Kub 1Spinner

app. Temperature1Spinner = uispinner (app. TempSettingsTab); app. Temperature1Spinner. Limits = [60 90]; app. Temperature1Spinner. ValueChangedFcn = createCallbackFcn (app, @Temperature1SpinnerValueChanged, muaj tseeb); app. Temperature1Spinner. Position = [157 346 100 68]; app. Temperature1Spinner. Value = 60;

% Tsim Kub Kub2SpinnerLabel

app. Temperature2SpinnerLabel = uilabel (app. TempSettingsTab); app. Temperature2SpinnerLabel. HorizontalAlignment = 'chaw'; app. Temperature2SpinnerLabel. Position = [66 248 76 28]; app. Temperature2SpinnerLabel. Text = {'Kub'; '#2'};

% Tsim Kub2Spinner

app. Temperature2Spinner = uispinner (app. TempSettingsTab); app. Temperature2Spinner. Limits = [60 90]; app. Temperature2Spinner. ValueChangedFcn = createCallbackFcn (app, @Temperature2SpinnerValueChanged, muaj tseeb); app. Temperature2Spinner. Position = [157 230 100 70]; app. Temperature2Spinner. Value = 60;

% Tsim Hloov

app. Switch = uiswitch (app. TempSettingsTab, 'swb'); app. Switch. Items = {'1', '0'}; app. Switch. ValueChangedFcn = createCallbackFcn (app, @SwitchValueChanged, muaj tseeb); app. Switch. FontName = 'Nyala'; app. Switch. FontSize = 28; app. Switch. Position = [522 21 74 32]; app. Switch. Value = '0';

% Tsim EditFieldLabel

app. EditFieldLabel = uilabel (app. TempSettingsTab); app. EditFieldLabel. HorizontalAlignment = 'txoj cai'; app. EditFieldLabel. Position = [374 291 25 22]; app. EditFieldLabel. Text = ``;

% Tsim tempnow

app.tempnow = uieditfield (app. TempSettingsTab, 'lej'); app.tempnow. Limits = [60 89]; app.tempnow. ValueChangedFcn = createCallbackFcn (app, @tempnowValueChanged, muaj tseeb); app.tempnow. HorizontalAlignment = 'chaw'; app.tempnow. FontSize = 26; app.tempnow. Position = [409 230 133 117]; app.tempnow. Value = 60;

% Tsim GaugeLabel

app. GaugeLabel = uilabel (app. TempSettingsTab); app. GaugeLabel. HorizontalAlignment = 'chaw'; app. GaugeLabel. Position = [225 32 42 22]; app. GaugeLabel. Text = 'Ntsuas';

% Tsim Kev Ntsuas

app. Gauge = uigauge (app. TempSettingsTab, 'ncig'); app. Gauge. Limits = [60 90]; app. Gauge. MajorTicks = [60 65 70 75 80 85 90]; app. Gauge. Position = [185 69 120 120]; app. Gauge. Value = 60;

% Tsim SavingsTab

app. SavingsTab = uitab (app. TabGroup); app. SavingsTab. Title = 'Txuag';

% Tsim UIAxes

app. UIAxes = uiaxes (app. SavingsTab); title (app. UIAxes, 'Txuag') xlabel (app. UIAxes, 'Hli thiab Xyoo') ylabel (app. UIAxes, 'Nyiaj') app. UIAxes. PlotBoxAspectRatio = [1 0.60666666666666667 0.60666666666666667]; app. UIAxes. Color = [0.9412 0.9412 0.9412]; app. UIAxes. Position = [146 219 348 237];

% Tsim ThisMonthCostEditFieldLabel

app. ThisMonthCostEditFieldLabel = uilabel (app. SavingsTab); app. ThisMonthCostEditFieldLabel. HorizontalAlignment = 'chaw'; app. ThisMonthCostEditFieldLabel. Position = [439 96 94 22]; app. ThisMonthCostEditFieldLabel. Text = 'Tus Nqi Ib Hlis';

% Tsim ThisMonthCostEditField

app. ThisMonthCostEditField = uieditfield (app. SavingsTab, 'lej'); app. ThisMonthCostEditField. Limits = [0 Inf]; app. ThisMonthCostEditField. ValueDisplayFormat = '$%7.2f'; app. ThisMonthCostEditField. HorizontalAlignment = 'chaw'; app. ThisMonthCostEditField. Position = [417 39 137 58];

% Tsim TotalSavingsEditFieldLabel

app. TotalSavingsEditFieldLabel = uilabel (app. SavingsTab); app. TotalSavingsEditFieldLabel. HorizontalAlignment = 'txoj cai'; app. TotalSavingsEditFieldLabel. Position = [111 96 77 22]; app. TotalSavingsEditFieldLabel. Text = 'Tag Nrho Cov Nyiaj Txiag';

% Tsim TotalSavingsEditField

app. TotalSavingsEditField = uieditfield (app. SavingsTab, 'lej'); app. TotalSavingsEditField. Limits = [0 Inf]; app. TotalSavingsEditField. ValueDisplayFormat = '$%9.2f'; app. TotalSavingsEditField. HorizontalAlignment = 'chaw'; app. TotalSavingsEditField. Position = [88 39 137 58]; kawg kawg

txoj kev (Nkag mus = pej xeem)

% Tsim app

muaj nuj nqi app = Control_1

% Tsim thiab teeb tsa cov khoom siv

tsim cov khoom siv (app)

% Sau npe app nrog App Designer

sau npe App (app, app. UIFigure)

yog nargout == 0

clear app kawg kawg

% Code uas ua tiav ua ntej tshem app

muaj nuj nqi rho tawm (app)

% Rho tawm UIFigure thaum app raug tshem tawm

rho tawm (app. UIFigure) kawg kawg kawg

Tej zaum koj yuav tau txais qhov yuam kev, uas tsis muaj teeb meem. Tsuas yog kaw GUI uas tau tsim tawm tom qab koj nias khiav, peb yuav sau cov seem ntawm cov haujlwm tsim nyog thiab cov ntaub ntawv nyob rau hauv ib pliag.

Txij li Matlab tau teeb tsa peb tuaj yeem txav mus rau nab hab sej. Ua ntej, khiav cov program nab nab los ntawm koj qhov kev hais kom ua tam sim no (ntawm lub qhov rais) lossis los ntawm kev siv cov ntaub ntawv.exe hauv koj cov nab npawb sej. Nco ntsoov tias txhua lub tsev qiv ntawv tsim nyog tau teeb tsa los ntawm kev siv cov lus txib ntshuam.

ntshuam ntshuam

ntshuam sijhawm ntshuam csv

Nov yog peb lub tsev qiv ntawv koj yuav tsum tau pib tawm, txawm hais tias peb yuav ua peb lub tsev qiv ntawv sai sai no. Yog tias muaj qee qhov yuam kev nrog cov lus txib no, rov qab mus thiab ua kom ntseeg tau tias cov tsev qiv ntawv tau teeb tsa thiab nyob hauv Lib nplaub tshev hauv cov nab npawb nab npawb. Tom ntej no peb yuav tsim qhov kuv tau hu ua pythonlogger library. Lub npe no tsis tsim nyog, koj tuaj yeem hu nws txhua yam koj xav tau, nws tsuas yog lub npe ntawm cov ntaub ntawv nab hab sej (.py) uas koj tsim.

Qhib tus kws kho ntawv, Kuv siv Sublime3 tab sis notepad ua haujlwm tau zoo, thiab nkag mus rau cov cai no.

def pythonprint (): cov

ntshuam pythonlogger ntshuam lub sijhawm ntshuam ntshuam csv ser = serial. Serial ('COM8') # COM8 yog qhov chaw nres nkoj arduino, qhov no yuav zoo li txawv rau txhua tus neeg siv, piv txwv li tshawb xyuas koj lub chaw nres nkoj hauv arduino IDE ser.flushInput () thaum Tseeb: sim: ser_bytes = ser.readline () luam tawm (ser_bytes) nrog qhib ("test_data.csv", "a") raws li f: kws sau ntawv = csv.writer (f, delimiter = ",") # teeb tsa cov ntaub ntawv rau nkag mus ua tus kws sau ntawv sib cais.writerow ([sijhawm.time (), ser_bytes]) #sau cov ntaub ntawv rau test_data.csv tshwj tsis yog: luam tawm ("Muaj Qhov Tsis Zoo") tawg

Txuag cov ntawv raws li "ntxig lub npe ntawm lub tsev qiv ntawv koj xav tau".py hauv Lib nplaub tshev. Tsis tas li nco ntsoov tias qhov def pythonprint () kab piav qhia lub npe ntawm txoj haujlwm koj yuav tau hu, yog li koj tuaj yeem hloov qhov ntawd los def "ntxig lub npe koj xav tau rau koj txoj haujlwm" (). Thaum lub tsev qiv ntawv tau txais kev cawmdim peb tuaj yeem txav mus rau tus lej arduino.

Qhib arduino IDE thiab qhib ob lub qhov rai tshiab. Txuag ob daim duab kos qhov chaw yooj yim, lub npe ntawm cov ntaub ntawv no tsis muaj teeb meem. Tom qab ntawd tshem tawm tag nrho cov cai ua ntej thiab hloov nws nrog cov hauv qab no.

Rau qhov tau txais arduino:

#suav nrog

#include #include #include // qhov no tsis siv tab sis xav tau los sau RH_ASK tus tsav tsheb; struct dataStruct {ntab temp; } myData; teeb tsa tsis muaj dab tsi () {Serial.begin (9600); // Debugging tsuas yog (! Driver.init ()) Serial.println ("init ua tsis tau tejyam"); } void loop () {uint8_t buf [RH_ASK_MAX_MESSAGE_LEN]; uint8_t buflen = sizeof (buf); yog (driver.recv (buf, & buflen)) // Tsis-thaiv {int i; // Cov lus uas tau txais kev txheeb xyuas zoo, pov tseg. //driver.printBuffer("Got: ", buf, buflen); memcpy (& myData, buf, sizeof (myData)); Serial.println (""); Serial.print (myData.temp); }}

PS lub //driver.printBuffer…. kab lwm yam yog xeem kab. Tsis tas yuav txhawj xeeb txog nws tshwj tsis yog koj ua tus kuaj mob thiab xav paub seb koj puas tau txais cov ntaub ntawv tiag.

Rau lub transmitter arduino

#suav nrog

#include #include #include // qhov no tsis siv tab sis xav tau los sau #suav nrog #include int tus pin = 4; DHT11 dht11 (tus pin); RH_ASK tus tsav tsheb; struct dataStruct {ntab temp; } myData; byte tx_buf [sizeof (myData)] = {0}; // Yog li cov lus sib cav yog bitrate, xa tus pin (tx), // tau txais tus pin (rx), ppt tus pin, isInverse. 2 kawg tsis tau siv.void teeb tsa () {Serial.begin (9600); // Debugging tsuas yog (! Driver.init ()) Serial.println ("init ua tsis tau tejyam"); } void loop () {int ua yuam kev; float temp, humi; uint8_t msg; yog ((yuam kev = dht11.read (humi, temp)) == 0) myData.temp = temp; memcpy (tx_buf, & myData, sizeof (myData)); byte zize = sizeof (myData); {Serial.println (myData.temp); driver.send ((uint8_t *) tx_buf, zize); driver.waitPacketSent (); // nres kev ua haujlwm kom txog thaum tag nrho cov ntaub ntawv tau xa qeeb (2000); // tos 2 vib nas this}

Kev suav nrog cov lus txib yuav tsum txaus, tab sis yog tias koj muaj teeb meem tom qab nrog kev hloov cov ntaub ntawv koj yuav xav saib hauv RadioHead lub tsev qiv ntawv ntawv tais ceev tseg thiab suav nrog cov npe ntawm cov ntaub ntawv tseem tshuav, hauv tib hom ntawv.

Kauj ruam 5: Ua Nws Ua Haujlwm

Ua Kom Nws Ua Haujlwm
Ua Kom Nws Ua Haujlwm
Ua Kom Nws Ua Haujlwm
Ua Kom Nws Ua Haujlwm
Ua Kom Nws Ua Haujlwm
Ua Kom Nws Ua Haujlwm

Tam sim no peb muaj tag nrho cov cai ua ke thiab cov arduino tau sib sau ua ke, peb tuaj yeem sib txuas cov arduino rau koj lub khoos phis tawj thiab thauj cov cai. Nco ntsoov tias koj xa cov cai raug rau qhov tau txais thiab xa cov microcontrollers. Koj tuaj yeem muaj ob qho ntawm arduinos txuas rau koj lub khoos phis tawj thaum qhov no tab tom tab sis koj yuav tsum ua kom ntseeg tau tias koj muaj qhov chaw nres nkoj raug xaiv xaiv mus rau tom ntej, lossis koj tuaj yeem txuas qhov kev xa tawm ntawm arduino thiab siv nws los ntawm qee qhov chaw ib zaug thaum tus lej code tso tawm.

Hais txog qhov twg, koj yuav tsum xaiv qhov chaw nres nkoj uas txuas nrog koj tau txais arduino los ntawm IDE cov cuab yeej ntawv qhia zaub mov tam sim no thiab khiav nab hab sej.

Tsis txhob qhib lub koos pij tawj saib thaum koj tab tom ua qhov no, nab nab tsis tuaj yeem nyeem cov ntawv thaum lub ntsuas saib qhib. Thaum nab nab qhib qhib hu ua nab nab muaj nuj nqi raws li hauv qab no.

pythonlogger.pythonprint ()

Qhov no yuav pib sau cov ntaub ntawv los ntawm arduino serial chaw nres nkoj. Yog tias koj qhib koj daim ntawv sej tam sim no, koj yuav pom tias cov ntaub ntawv tshiab.csv tau raug tsim hu ua "test_data.csv", uas tuav tag nrho cov sijhawm thiab ntsuas kub. Qhov no yuav yog cov ntaub ntawv uas Matlab nkag mus ua txhua yam ntawm nws qhov kev suav thiab kev tswj hwm.

Lwm qhov ceeb toom: tsis txhob qhib test_data.csv thaum cov ntaub ntawv tau nkag mus lossis sau. Yog tias koj ua, nab hab sej thiab/lossis Matlab code yuav tsoo thiab xa rov qab yuam kev

Yog tias koj txiav txim siab qhib lub.csv tom qab, koj yuav pom tias kab ntawv lub sijhawm tsuas yog cov lej loj heev. Tias yog vim lub sijhawm.time () hais kom sau cov vib nas this txij li Lub Ib Hlis 1st, 1970.

Txij ntawm no tus nab nab yuav tsum luam tawm cov ntaub ntawv ntsuas kub nws tau nyeem los ntawm cov chaw nres nkoj. Nws yuav tsum zoo ib yam li:

b'25.03 '/r/n

Tsis txhob txhawj xeeb txog cov cim ntxiv, Matlab tus lej cim rau nruab nrab tsib qhov tseem ceeb hauv kab ntawv thib ob ntawm.csv cov ntaub ntawv.

Tam sim no tias txhua qhov kev pabcuam txhawb nqa tau ua haujlwm thiab cov ntaub ntawv tau raug khaws cia peb tuaj yeem pib sau cov ntaub ntawv GPS los ntawm Matlab cov phiaj xwm xov tooj uas tau teeb tsa ua ntej thiab khiav Matlab GUI code. Thaum koj nyob hauv lub sensor tab ntawm Matlab mobile, xaiv GPS thiab ntaus lub pob pib.

Yog tias koj yog tus tshiab rau Matlab mobile xa rov qab mus rau kauj ruam 4 thiab saib cov duab txhaj tshuaj saum toj no. Yog tias koj tseem muaj teeb meem, nco ntsoov tias koj tau txuas nrog lub khoos phis tawj koj tau xaiv ua ntej (hauv qhov chaw teeb tsa) thiab siv qhov txuas los ntawm "txuas rau" hais kom ua los xyuas tias Matlab online.

Kauj Ruam 6: Siv Txoj Haujlwm

Siv Txoj Haujlwm
Siv Txoj Haujlwm

Muaj ntau yam tshwm sim hauv keeb kwm yav dhau los hauv qhov system no. Cov ntaub ntawv ntsuas kub tau sau thiab nkag los ntawm arduino thiab pyton, Matlab tau khaws GPS cov ntaub ntawv los ntawm koj lub xov tooj thiab khiav cov lus suav kom pom deb npaum li cas koj nyob ntawm koj lub tsev thiab teeb tsa koj lub ntsuas cua sov raws li tag nrho cov ntaub ntawv ntawd. Qhov twg koj tuaj hauv yog muab koj qhov kev nyiam.

Khiav Matlab GUI code. Qhib cov.mlapp cov ntaub ntawv thiab saib rau thawj lub tab. Koj yuav tsum tau sau cov ntaub ntawv no rau koj tus kheej, kev ua haujlwm tau zoo thiab ntsuas lub zog ntawm koj lub tshuab cua sov/cua txias feem ntau tuaj yeem pom ntawm chav tsev nws tus kheej, thiab koj qhov nruab nrab nrawm tsuas yog kwv yees tau zoo ntawm kev tsav tsheb nrawm. Thaum cov txiaj ntsig tau nkag mus, nyem "Khiav Diagnostic" khawm thiab txoj haujlwm tswj hwm koj lub ntsuas cua kom sau cov ntaub ntawv hais txog koj lub tsev.

Txav mus rau cov ntawv qhia zaub mov tom ntej.

Kauj Ruam 7: Kev Tswj Kub

Kev Tswj Kub
Kev Tswj Kub

Cov ntawv qhia zaub mov no tso cai rau koj xaiv qhov kub uas koj nyiam thaum koj nyob hauv tsev thiab nyob deb. Teeb Kub #1 rau koj qhov ntsuas sov, thiab Kub #2 kom siab lossis qis tus nqi uas nyab xeeb rau koj lub tsev (xyuas kom tseeb tias koj tsis teeb nws mus rau 100 degrees thaum koj muaj dev nyob hauv tsev, thiab lwm yam).

Kauj Ruam 8: Cov Ntaub Ntawv Keeb Kwm

Cov Ntaub Ntawv Keeb Kwm
Cov Ntaub Ntawv Keeb Kwm

Thaum kawg koj tuaj yeem saib ntau npaum li cas koj txuag nyiaj los ntawm kev siv lub tshuab tswj tsis siv neeg. Qhov tseem ceeb kwv yees ntau npaum li cas yuav siv lub zog yog tias koj lub ntsuas cua sov tau teeb tsa rau qhov koj xav tau kub 24/7, tom qab ntawd rho tawm koj lub zog tiag tiag siv.

Hmoov zoo tsev.

Pom zoo: