Cov txheej txheem:

Lub Teeb Nyeem Plotting Siv Arduino thiab Python's Arduino Master Library: 5 Kauj Ruam
Lub Teeb Nyeem Plotting Siv Arduino thiab Python's Arduino Master Library: 5 Kauj Ruam

Video: Lub Teeb Nyeem Plotting Siv Arduino thiab Python's Arduino Master Library: 5 Kauj Ruam

Video: Lub Teeb Nyeem Plotting Siv Arduino thiab Python's Arduino Master Library: 5 Kauj Ruam
Video: Nkauj Ntseeg Nkauj Qub. Tswv Yexus Cov Tub Rog 2024, Kaum ib hlis
Anonim
Lub Teeb Nyeem Plotting Siv Arduino thiab Python's Arduino Master Library
Lub Teeb Nyeem Plotting Siv Arduino thiab Python's Arduino Master Library

Arduino yog qhov kev lag luam tseem tsis tau muaj txiaj ntsig zoo thiab muaj txiaj ntsig zoo, ua haujlwm hauv Embedded C ua rau cov txheej txheem ntawm kev ua cov haujlwm tsis txaus ntseeg! Arduino_Master module ntawm Python ua rau qhov no yooj yim thiab cia peb ua cov lej, tshem tawm cov txiaj ntsig pov tseg, thiab npaj kab lus kom pom qhov sawv cev ntawm cov ntaub ntawv.

Yog tias koj tsis paub txog tus qauv no tseem tsis tau, nruab nws siv cov lus txib pip nruab Arduino_Master

Tsis txhob txhawj xeeb yog tias koj tsis paub siv tus qauv no, mus saib qhov txuas no => Arduino_Master

Txawm li cas los xij, txoj cai rau txoj haujlwm no ib txwm muaj nyob hauv phau ntawv qhia no.

Khoom siv

Rau qhov haujlwm no, koj yuav xav tau cov hauv qab no:

  1. Ib Arduino
  2. Lub Teeb Ntsuas Tus Kws Tiv Thaiv (LDR) thiab
  3. Nab hab sej 3 ntsia koj lub computer.

Kauj Ruam 1: Tsim Koj Li Circuit Court:

Tsim Koj Li Circuit Court
Tsim Koj Li Circuit Court

Peb yuav siv tus pin A1 ntawm Arduino kom tau txais cov ntaub ntawv nkag mus. Koj tseem tuaj yeem siv 5V thiab GND pins ntawm Arduino hloov lub Roj Teeb. Ua qhov txuas raws li hauv qab no:

  1. Txuas ib kawg ntawm LDR mus rau lub davhlau ya nyob twg zoo ntawm 5V roj teeb lossis rau 5V tus pin ntawm Arduino.
  2. Txuas lwm qhov kawg ntawm LDR ua ke rau tus pin A1 thiab qhov tsis zoo ntawm lub roj teeb lossis GND tus pin ntawm Arduino.
  3. Siv tus tiv thaiv kom ntseeg tau tias txhua qhov tam sim no tsis ntws mus rau GND uas yuav ua rau koj tsis tau txais lub teeb liab txaus kom nkag siab ntawm A1 davhlau ya nyob twg ntawm Arduino. (Kuv siv tus tiv thaiv ntawm 10k ohms).

Kauj ruam 2: Programming Koj Arduino:

Arduino_Master module siv Serial Monitor ntawm Arduino xa thiab txais cov ntaub ntawv. Qhov zoo ntawm kev siv tus qauv no yog, thaum koj program koj Arduino, koj tuaj yeem hloov pauv qhov kev pab cuam nab nab ib leeg rau cov haujlwm sib txawv txij li kev ua haujlwm hauv nab nab yog piv tau yooj yim!

Txoj Cai:

// LDR_1 qhov sib txawv tau siv los qhia tus pin A1 ntawm Arduino.

int LDR_1 = A1;

// Cov ntaub ntawv tau txais los ntawm A1 yuav raug khaws cia hauv LDR_Value_1.

ntab LDR_Value_1;

Txoj hlua tawm tswv yim;

void teeb tsa ()

{pinMode (LDR_1, INPUT); // LDR_1 tau teeb tsa ua tus pin INPUT. Serial.begin (9600); // Kev sib txuas lus baudrate tau teeb tsa ntawm 9600.}

void lub voj ()

{yog (Serial.available ()> 0) // yog tias muaj cov tswv yim muaj nyob hauv cov ntawv saib tom qab ntawd ua mus ntxiv. {input = Serial.readString (); // Nyeem cov tswv yim ua ib txoj hlua. yog (input == "DATA") {LDR_Value_1 = analogRead (LDR_1) * (5.0 / 1023.0); // (5 /1023) yog qhov hloov pauv kom tau txais tus nqi hauv Volts. Serial.println (LDR_Value_1); // Yog tias cov tswv yim sib npaug rau "DATA", tom qab ntawv nyeem cov ntaub ntawv los ntawm LDR_1 thiab luam tawm ntawm Serial Monitor. } lwm int i = 0; // yog cov tswv yim tsis sib npaug rau "DATA", tsis ua dab tsi! }

}

Kauj Ruam 3: Programming Python rau Graph Cov Ntaub Ntawv Los Ntawm Arduino:

Txhua tus thiab txhua LDR yuav muaj nws tus kheej qhov tseem ceeb tiv thaiv thiab peb yuav tsum nco ntsoov tias tsis muaj cov khoom siv hluav taws xob tau zoo ib yam nkaus hauv kev ua haujlwm. Yog li ua ntej peb yuav tsum nrhiav qhov hluav taws xob ntawm qhov sib txawv ntawm lub teeb.

Rub cov program hauv qab no rau koj li nab nab IDE thiab khiav nws:

Ua qhov no rau qhov sib txawv ntawm lub teeb thiab siv cov duab kos cov lus xaus piv txwv yog tias kev siv tsawg dua 1, chav tsaus ntuj heev. Rau kev siv nruab nrab ntawm 1 thiab 2, chav nyob tsaus ntuj heev. Rau kev siv ntau dua 2, lub teeb tau qhib rau.

# Ntshuam Arduino_Master module

los ntawm Arduino_Master ntshuam *

# khaws cov ntaub ntawv

data = filter (ardata (8, nyem = Tsis yog, dynamic = True, msg = "DATA", kab = 30), xav tau_type = 'num', txwv = [0, 5])

# txwv tau teev rau 5 vim peb tab tom siv roj teeb 5V.

# Plotting qhov tseem ceeb

Teeb duab (cov ntaub ntawv, stl = 'dark_background', daim ntawv lo = 'Teeb pom kev zoo')

Kauj Ruam 4: Qhov Kev Kawm Kawg los Txheeb Xyuas Qhov Teeb Pom Kev Zoo hauv Chav

Tom qab los txog qhov xaus los ntawm cov ntaub ntawv koj tau txais, rub cov program hauv qab no thiab xyuas kom hloov pauv qhov txwv raws li koj qhov xaus.

# Ntshuam Arduino_Master module

los ntawm Arduino_Master ntshuam # khaws cov ntaub ntawv cov ntaub ntawv = lim (ardata (8, nyem = Tsis tseeb, hloov pauv = Muaj tseeb, msg = "DATA", kab = 50), xav tau_type = 'num', txwv = [0, 5]) # cais cov ntaub ntawv raws li qhov xaus cov ntaub ntawv = rau kuv hauv kab (len (cov ntaub ntawv)): siv = cov ntaub ntawv yog siv 1 thiab siv = 2: info.append ('Teeb ON') # Plotting Graph. compGraph (cov ntaub ntawv, cov ntaub ntawv, stl = 'dark_background', label1 = 'Teeb pom kev zoo', label2 = 'Xeev')

Kauj Ruam 5: Qhov tshwm sim:

Qhov tshwm sim
Qhov tshwm sim

Txoj haujlwm yuav siv sijhawm li ib lossis ob feeb los ua haujlwm txij li koj tau nyeem 50 qhov txiaj ntsig tam sim los ntawm Arduino.

Yog tias koj xav ua kom nrawm dua cov txheej txheem sim hloov cov kab kev ntsuas ntawm cov haujlwm ardata. Tab sis nco ntsoov tias qhov tsawg dua qhov kev soj ntsuam, qhov tsawg dua yuav yog qhov zoo ntawm cov ntaub ntawv.

Nco tseg: Yog tias daim duab ua tiav hauv daim duab saum toj no tsis pom, xa cov duab saum toj no Tshooj Lus Taw Qhia.

Pom zoo: