Cov txheej txheem:

Kev Tiv Thaiv Kev Sib tsoo- Txhawb los ntawm Pi: 6 Kauj Ruam
Kev Tiv Thaiv Kev Sib tsoo- Txhawb los ntawm Pi: 6 Kauj Ruam

Video: Kev Tiv Thaiv Kev Sib tsoo- Txhawb los ntawm Pi: 6 Kauj Ruam

Video: Kev Tiv Thaiv Kev Sib tsoo- Txhawb los ntawm Pi: 6 Kauj Ruam
Video: yuav coj li cas kom luag nyiam 2024, Kaum ib hlis
Anonim
Kev Tiv Thaiv Kev Sib tsoo- Txhawb los ntawm Pi
Kev Tiv Thaiv Kev Sib tsoo- Txhawb los ntawm Pi

Cov Lus Qhia no yuav qhia koj ib qib zuj zus qhia rau kev tsim kho Kev Tiv Thaiv Kev Sib tsoo. Txhawm rau pib ib qho yuav tsum tau txais cov npe khoom hauv qab no:

Raspberry PI 3 (nrog lub zog thiab Ethernet chords), 1 GPIO Extension Board thiab Ribbon Cable (GPIO), 1 Loj Breadboard nrog daim duab, 2 lub me me breadboards nrog daim duab, 14 jumper cables, 3 220 Ohms resistor, 1 RGB LED, 3 khawm hloov, 1HB-SR04 Ultrasonic sensor

Kauj ruam 1: GPIO Extension

GPIO txuas ntxiv
GPIO txuas ntxiv
GPIO txuas ntxiv
GPIO txuas ntxiv

Txuas GPIO lub rooj tsav xwm txuas mus rau lub rooj noj mov loj. GPIO yuav tsum tig ntsej muag ib yam li lub khob cij. Muab sab laug ntawm GPIO mus rau lub chaw tso khoom noj khoom haus D1-D20 siv daim duab qhia. Sab xis ces yuav txuas rau H1-H20. Txuas cov hlua txuas rau ob qho Raspberry Pi 3 thiab GPIO lub rooj tsav xwm txuas ntxiv. Tag nrho cov khoom siv tam sim no yuav raug xa mus ua GPIO board (GPIO)

Kauj Ruam 2: Ultrasonic Sensor

Ultrasonic Sensor
Ultrasonic Sensor
Ultrasonic Sensor
Ultrasonic Sensor

Siv lwm lub khob cij me me, txuas rau HR-SR04 lub ntsuas hluav taws xob ultrasonic mus rau qhov chaw me me breadboard A2-5 siv daim duab qhia. Txuas lub jumper cable mus rau lub khob cij me me (BB) E2, ntxig rau lwm qhov kawg hauv GPIO txuas lub rooj tsav xwm chaw nres nkoj J1. Ib yam nkaus, txuas peb tus neeg dhia ntxiv hauv cov qauv hauv qab no. (BB E3, GPIO B17) (BB E4, GPIO B18) (BB E5, GPIO B20)

Kauj ruam 3: LED thiab Resistors

LED thiab Resistors
LED thiab Resistors
LED thiab Resistors
LED thiab Resistors
LED thiab Resistors
LED thiab Resistors

Ntawm tib lub khob cij me me uas tau siv hauv kev qhia yav dhau los, txuas peb 220 ohm resistors hauv cov qauv hauv qab no. (E10, H10) (E12, H12) (E14, H14) Tom qab ntawd txuas lub jumper los ntawm tib lub khob cij E13 rau hauv av tsheb ciav hlau ntawm GPIO board. Txuas plaub kab ntawm LED mus rau qhov chaw me me ntawm lub rooj noj mov (B13) (D14) (D12) (D10). Tom qab ntawd txuas peb tus neeg dhia los ntawm lub khob cij me me mus rau pawg thawj coj saib xyuas GPIO hauv txoj haujlwm tau muab. (BB J10, GPIO J9) (BB J12, GPIO J8) (BB J14, GPIO J6). Daim ntawv qhia zaub mov no tau ua tiav.

Kauj ruam 4: Hauv av

Hauv av
Hauv av

Siv lwm lub jumper los txuas GPIO board J7 rau hauv av tsheb ciav hlau.

Kauj ruam 5: Nyees khawm

Nyees khawm
Nyees khawm

Siv lub khob cij thib ob tso rau sab saum toj ntawm lub pob hloov ntawm chaw nres nkoj E1 thiab D1, tso lwm qhov ntawm E5 thiab D5, thiab thib peb ntawm E9 thiab D9. Txuas peb tus neeg dhia los ntawm txoj kab hluav taws xob zoo ntawm GPIO pawg thawj coj mus rau cov chaw nres nkoj hauv qab no (D3) (D7) (D11). Siv peb txoj hlua txuas txuas txuas ntxiv, txuas lub khob cij rau GPIO lub rooj sib tham txuas ntxiv hauv cov tsev hauv qab no: (BB D1, GPIO J16) (BB D5, GPIO J18) (BB D9, GPIO J20). Thaum kawg, siv cov hlua txuas kawg, txuas GPIO A1 mus rau txoj kev tsheb nqaj hlau zoo. Kev teeb tsa lub cev tam sim no tiav.

Kauj ruam 6: Code

Code
Code
Code
Code

Txuas Ethernet cable thiab fais fab cable rau Pi thiab rau hauv lawv txoj haujlwm. Qhib MATLAB thiab khiav cov ntawv hauv qab no los pib lub micro-controller:

rpi = raspi ('169.254.0.2', 'pi', 'raspberry');

Tom qab ntawd luam thiab muab cov hauv qab no tso rau hauv tsab ntawv tshiab, hu ua Ping, kom ua haujlwm tiv thaiv kev sib tsoo:

muaj nuj nqi dist = ping () trig = 19; ncho = 13; xeem = 21; configurePin (rpi, trig, 'DigitalOutput'); configurePin (rpi, ncha, 'DigitalInput'); configurePin (rpi, xeem, 'DigitalInput');

disp ("Kev Txheeb Ze Nyob Hauv Qhov Kev Kawm");

thaum muaj tseeb writeDigitalPin (rpi, trig, 0); disp ("Cia lub sensor tsaws"); ncua (2);

writeDigitalPin (rpi, trig, 1); ncua (0.002); writeDigitalPin (rpi, trig, 0);

thaum nyeemDigitalPin (rpi, ncha) == 0 tic kawg

thaum nyeemDigitalPin (rpi, ncha) == 1 T = toc; kawg

pulse_duration = T; nrug = mem tes_duration * 17150;

qhib = "Nyob deb ="; ze = "cm"; hlua = [qhib, nrug, kaw]; disp (hlua); deb = nrug; kawg kawg

Hauv tsab ntawv tshiab, khiav cov cai hauv qab no hu ua xwm txheej:

configurePin (rpi, 21, 'DigitalInput'); teeb tsa Pin (rpi, 16, 'DigitalInput'); configurePin (rpi, 12, 'DigitalInput');

xwm txheej = 2; d = 10; Qhov xwm txheej: 0-Liab/Nres 1-Xiav/qeeb 2-Ntsuab/Mus khiav = muaj tseeb; thaum khiav %d = ping (); yog readDigitalPin (rpi, 21) == 1 xwm txheej = 0; elseif nyeemDigitalPin (rpi, 16) == 1 xwm txheej = 1; elseif nyeemDigitalPin (rpi, 12) == 1 xwm txheej = 2; lwm d

Pom zoo: