Cov txheej txheem:

IoT Code Breaker Game Device: 8 Kauj Ruam
IoT Code Breaker Game Device: 8 Kauj Ruam

Video: IoT Code Breaker Game Device: 8 Kauj Ruam

Video: IoT Code Breaker Game Device: 8 Kauj Ruam
Video: 20 MOMENTS YOU WOULDN'T BELIEVE IF NOT FILMED 2024, Kaum ib hlis
Anonim
IoT Code Breaker Game Device
IoT Code Breaker Game Device

IoT, lossis Internet ntawm Yam, yog kev nthuav dav hauv computer science. Cov lus qhia hauv qab no tso cai rau ib tus los tsim cov khoom siv ntawm IoT. Cov cuab yeej nws tus kheej tuaj yeem siv los ua si game breaker code. Ib tus neeg tuaj yeem tuaj yeem teeb tus lej siv lub qhov rai browser, txuas ntxiv muab cov lus qhia thib ob rau cov neeg siv, thiab tom qab ntawd kom tus neeg siv thib ob sim nkag mus rau tus lej siv cov cuab yeej kho vajtse. Yog tias tus neeg ua si thib ob raug lub teeb yuav nyem. Yog tsis yog, qhov kev ua si tuaj yeem rov ua dua. Cov cuab yeej yooj yim no tsis yog lom zem nkaus xwb, tab sis nws qhia kev kho vajtse yooj yim thiab tsim daim ntawv thov siv Raspberry Pi thiab sej flask software.

Kauj Ruam 1: Sau Cov Khoom Siv rau Cov Khoom Kho Vajtse

Sau Cov Khoom Siv rau Cov Khoom Kho Vajtse
Sau Cov Khoom Siv rau Cov Khoom Kho Vajtse

Ua ntej, tus tsim khoom yuav tsum sib sau cov ntaub ntawv xav tau rau qhov kho vajtse ib feem ntawm qhov kev ua si. Cov ntaub ntawv muaj npe hauv qab no.

  • 1 Raspberry Pi
  • SD Card rau Raspberry Pi
  • 1 Zaj Duab Xis Ribbon
  • 1 Raspberry Pi mus rau Lub Rooj Sib Tham Rooj Mov
  • 1 Loj Breadboard
  • 1 Daim Ntawv Me Me
  • 1 Teb Encoder
  • 1 LED
  • 17 Segment LED Screen
  • 9330 Ohm Cov neeg tiv taus
  • Ntau Yam Yooj Yim

Kauj Ruam 2: Txhim Kho Lub Tshuab Rotary Encoder

Txhim kho Rotary Encoder
Txhim kho Rotary Encoder
Txhim kho Rotary Encoder
Txhim kho Rotary Encoder
Txhim kho Rotary Encoder
Txhim kho Rotary Encoder

Txhawm rau pib txhim kho Rotary Encoder, peb pib los ntawm kev yuav lub khob cij loj, Raspberry Pi, tus xov tooj txuas xov tooj, tus Pi txuas, Rotary Encoder, thiab ntau yam xov hlau. Peb tsis xav tau tus tiv thaiv ntawm no, vim qhov tseeb tias Rotary Encoder twb muaj tus tiv thaiv ua rau nws. Peb pib los ntawm kev txuas cov kab zaj sawv mus rau Raspberry Pi thiab txuas rau lub khob cij txuas. Tom qab ntawd peb txuas tus txuas rau lub khob cij. Ceev faj thaum tso thiab tshem cov kab zaj sawv vim nws tuaj yeem khoov tus pin ntawm Raspberry Pi.

Tam sim no peb yuav tsum txuas lub zog thiab kab hauv av ntawm lub khob cij mus rau lub zog thiab cov pins hauv av ntawm tus txuas. Yuav ua li cas ua qhov no tau qhia hauv daim duab thib ob saum toj no.

Muab lub Rotary Encoder tso rau ntawm lub khob cij. Nco ntsoov tias tus pin ntawm Rotary Encoder yog txhua tus nyob hauv kab sib txawv ntawm pawg thawj coj saib. Tus encoder muaj tsib tus pin nyob rau hauv tag nrho. Ua ntej tshaj, txuas tus lej cim npe GND lossis hauv av rau kab hauv av ntawm lub khob cij. Nov yog kab ntawv ntawm cov chaw cim nrog kab xiav. Tom ntej no, peb yuav tsum txuas tus lej nkag mus rau lub zog. Txuas tus pin sau rau + rau lub zog. Tus pin thib peb ntawm Rotary Encoder tau sau tias SW. Tus lej no nyeem yog tias lub taub hau ntawm tus lej nkag tau raug nias. Peb txuas tus lej no mus rau tus lej cim npe GPIO16 ntawm tus txuas. Qhov kawg ob tus pin ntawm tus lej cim npe nyeem qhov twg lub pob qhov rooj ntawm tus encoder tam sim no tau teeb tsa. Txuas tus pin sau DT rau tus pin daim ntawv lo GPIO18 ntawm tus txuas thiab tus pin sau CLK rau GPIO17 ntawm tus txuas.

Tam sim no, Rotary Encoder txuas nrog Raspberry Pi.

Kauj Ruam 3: Txheeb Tawm Qhov 7 Segment Screen

Txheeb Tawm Qhov 7 Segment Screen
Txheeb Tawm Qhov 7 Segment Screen
Txheeb Tawm Qhov 7 Segment Screen
Txheeb Tawm Qhov 7 Segment Screen
Txheeb Tawm Qhov 7 Segment Screen
Txheeb Tawm Qhov 7 Segment Screen
Txheeb Tawm Qhov 7 Segment Screen
Txheeb Tawm Qhov 7 Segment Screen

Ib zaug, Rotary Encoder tau teeb tsa, peb tuaj yeem ua haujlwm ntawm thaiv 7 ntu LED npo. Ua ntej, peb yuav tsum tau txais ib daim ntawv me me ntxiv nrog rau 7 ntu nws tus kheej, yim 830 Ohm resistors, thiab ntau yam xov hlau.

Nws yog ib qho tseem ceeb heev uas 7 ntu tau txuas kom raug raws li nws tsis muaj cov resistors ua rau nws zoo li cov lus teb encoder ua. Xya ntu muaj kaum ob tus lej nyob rau hauv tag nrho. Pins ib txog rau rau qhov yog nyob ntawm kab saum toj kawg nkaus ntawm 7 ntu khiav ntawm sab laug mus rau sab xis. Pins xya txog kaum ob nyob ntawm kab hauv qab thiab khiav sab xis mus rau sab laug. Cov kab hauv qab yog ib sab ntawm 7 ntu cim nrog me me tom qab txhua tus lej ntawm 7 ntu.

Peb tso 7 ntu rau ntawm lub khob cij me me thiab xaim txhua tus pin raws li qhia hauv cov lus saum toj no. Yog tias xav tau tus tiv thaiv tso tus tiv thaiv nruab nrab ntawm 7 ntu ntu thiab tus pin txuas. Ib qho ntxiv, ua kom ntseeg tau tias tsis muaj cov neeg tawm tsam kov ib leeg thaum siv lub cuab yeej. Qhov no tuaj yeem cuam tshuam qhov khiav ntawm hluav taws xob.

Kauj Ruam 4: Txuas lub LED

Kev tiv thaiv LED
Kev tiv thaiv LED

Txij li thaum peb muaj cov khoom kho vajtse tau teeb tsa tam sim no, peb tuaj yeem ua tiav los ntawm kev teeb tsa LED. Qhov LED no yuav qhia rau peb paub thaum cov cai uas peb tau nkag mus raug lawm. Txhawm rau ua qhov no, peb yuav xav tau LED, 330 Ohm resistor, thiab ntau lub xov hlau.

LED muaj ob tus pin txuas rau nws. Ib sab ntev dua me ntsis. Ua ntej tshaj, peb yuav tsum txuas qhov ntev ntawm ob tog kom muaj zog. Txhawm rau ua qhov no, peb txuas sab ntev dua los ntawm xaim txhawm rau pin GPIO26 ntawm qhov txuas. Txoj kev no tom qab peb tuaj yeem qhib thiab tua LED. Tom qab ntawd peb tuaj yeem txuas qhov luv ntawm ob sab mus rau hauv av. Txawm li cas los xij, peb yuav tsum ua qhov no los ntawm tus tiv thaiv, kom peb tsis txhob hlawv LED.

Ib zaug, peb tau ua tiav qhov no, peb tau ua tiav nrog LED thiab kho vajtse tag nrho.

Kauj ruam 5: Lub sijhawm rau Daim Ntawv Thov

Txhawm rau tsim daim ntawv thov rau lub cuab yeej no, ib tus yuav xav tau nkag mus rau Python Flask. Flask yog ib qho yooj yim siv web txhim kho software uas tuaj yeem siv los tsim cov browser yooj yim-raws li kev thov.

Txhawm rau rub tawm thawj zaug thiab kawm paub ntau ntxiv txog Flask ua raws qhov txuas muab: FLASK INFORMATION

Txhawm rau tsim daim ntawv thov tshwj xeeb rau lub cuab yeej no. Pib los ntawm kev tsim daim nplaub tshev ntawm koj li Raspberry Pi. Cov ntawv no yuav tsum raug hu ua "iotapp". Rub tawm thiab rub cov ntawv "iotapp.py" rau hauv daim nplaub tshev no. Ib qho ntxiv, hauv daim nplaub tshev no, tsim cov ntawv thib ob hu ua "appFolder". Sab hauv "appFolder" rub tawm cov ntaub ntawv "_init_.py", "forms.py", "RE.py", thiab "routes.py". Tom qab ntawd tsim lwm daim nplaub tshev hu ua "qauv". Daim nplaub tshev tshiab no tseem yuav tsum sab hauv "appFolder".

Kauj Ruam 6: Cov Ntaub Ntawv HTML

Cov ntaub ntawv HTML
Cov ntaub ntawv HTML
Cov ntaub ntawv HTML
Cov ntaub ntawv HTML

Tam sim no peb muaj "tus qauv" nplaub tshev tsim peb tuaj yeem tsim cov ntawv HTML uas yuav ua cov nplooj ntawv rau peb daim ntawv thov. Tsim ob daim ntawv HTML: codeentered.html thiab setcode.html. Cov cai rau cov ntaub ntawv no tau qhia hauv cov duab saum toj no.

Kauj Ruam 7: Khiav Daim Ntawv Thov

Khiav Daim Ntawv Thov
Khiav Daim Ntawv Thov
Khiav Daim Ntawv Thov
Khiav Daim Ntawv Thov

Txhawm rau khiav daim ntawv thov, pib los ntawm qhib lub davhlau ya nyob twg. Tom qab ntawd SSH rau hauv koj li Raspberry Pi. Nkag mus rau "iotapp" nplaub tshev thiab los ntawm kab hais kom ua, sau cov lus txib hauv qab no:

$ export FLASK_APP = iotapp.py

$ python -m flask run --host 0.0.0.0

Yog tias daim ntawv thov ua haujlwm raug, kab hais kom ua hauv lub davhlau ya nyob twg yuav tsum nyeem:

* Ua haujlwm Flask app "iotapp"

* Khiav ntawm https://0.0.0.0:5000/ (Nias CTRL+C kom tawm)

Txhawm rau kom ncav cuag daim ntawv thov, koj yuav tsum mus ntsib lub vev xaib thov nkag los ntawm tus IP chaw nyob ntawm koj tus Raspberry Pi ua raws los ntawm ": 5000/setcode". Piv txwv:

Tam sim no lub cuab yeej tau ua tiav thiab ua tiav. Txoj cai game tuaj yeem ua si.

Txhawm rau kom nres lub cuab yeej, nias CTRL+C hauv lub qhov rai qhov rai thiab kaw Pi.

Kauj Ruam 8: Ua Si Game

Cov hauv qab no yog cov vis dis aus ntawm cov cuab yeej ua haujlwm.

Pom zoo: