Cov txheej txheem:

ColorPicker: 10 Kauj Ruam
ColorPicker: 10 Kauj Ruam

Video: ColorPicker: 10 Kauj Ruam

Video: ColorPicker: 10 Kauj Ruam
Video: Preppy Roblox Avatar Idea ||ROBLOX_UNICORN 2024, Kaum ib hlis
Anonim
ColorPicker
ColorPicker

Lub hom phiaj ntawm txoj haujlwm no yog ntsuas cov xim, thiab txhais lawv mus rau lwm lub tshuab xim. Siv tsuas yog RGB qhov ntsuas tau muab los ntawm lub ntsuas cua, koj tuaj yeem txhais mus rau HSL, CYMK, HEX thiab tseem nyob ze RAL code (tus qauv siv rau xim). Txoj haujlwm no xav tau kev paub pib ntawm Python, MySQL, Linux thiab Javascript.

Yog tias koj tseem tau paub txog lub raj mis thiab SocketIO, tom qab ntawv cov cai rau txoj haujlwm no yuav tsum nkag siab yooj yim rau koj.

Txoj haujlwm no tuaj yeem siv los ntawm cov neeg pleev xim, tsim qauv ib nrab lossis tsuas yog los ntawm ib tus neeg uas xav ntsuas xim.

Txoj haujlwm no tsis kim heev, thiab raug nqi kwv yees _ euros, tsis suav nrog thauj khoom.

Khoom siv

Peb tuaj yeem faib ntu no ua ob ntu:

  • Kho vajtse
  • Software

Kho vajtse

Peb siv cov khoom siv hauv qab no

  • HC04: Kev ntsuas nrug deb, peb nyob deb npaum li cas los ntawm qhov khoom
  • LCD zaub 2x16
  • LCD I2C module (HW061)
  • TCS34725 Xim xim module (Adafruit)
  • Dawb LED
  • Raspberry Pi 3 (Txhua Raspberry Pi yuav tsum ua haujlwm)
  • 5 x 1k Ohm resistor
  • 1x 220 lossis 330 Ohm resistor
  • SD daim npav 16GB (14.4GB)

Software

  • Python IDE, zoo li Visual Code lossis Pycharm (Pycharm siv ntawm no)
  • MySQL Workbench
  • Putty (Download tau Putty)
  • Rufus lossis lwm tus sau daim npav SD (Rub tawm Rufus)

Nqi

Txoj haujlwm no pheej yig heev, yog tias koj twb muaj Rapsberry Pi.

  • HC04: Pib ncig € 2.5 euros (Suav Teb) thiab nce txog € 6 rau ntau lub khw hauv zos.
  • LCD: Ib puag ncig 6-8 Euro.
  • I2C module: Raws li pheej yig hauv qab € 1 (Tuam Tshoj), tab sis mus txog € 4 rau ntau lub khw hauv zos.
  • TCS34725: Ib puag ncig € 9-12 euros. Feem ntau kim tshaj (Tsis suav nrog RPi)
  • Dawb coj: Yuav hauv ntau, 20 LEDS qis li € 1
  • Raspberry Pi: Nyob ntawm seb qhov twg, ib puag ncig € 40 euros
  • Resistors: € 0.10 rau ib tus tiv thaiv
  • SD daim npav: ib ncig € 8

Lub zog hloov pauv rau Raspberry Pi tsis suav nrog tus nqi, vim tias lub adapter no zoo ib yam.

Tus nqi ntau tshaj: ib puag ncig € 70, yog tias koj suav nrog Raspberry Pi thiab rooj plaub rau txoj haujlwm.

Txhawm rau tsim rooj plaub, kuv tau siv cov ntoo nyias nyias. Kuv rov siv ntoo no los ntawm rooj tog. Cov ntaub ntawv rau rooj plaub yog nyob ntawm koj.

Kauj Ruam 1: Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Siv Internet

Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet
Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet
Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet
Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet
Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet
Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet
Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet
Kauj Ruam 1: Txhim Kho RPi OS, teeb tsa SSH thiab Kev Siv Internet

Kauj ruam 1.1: Txhim kho daim duab

Rub tawm daim duab los ntawm qhov chaw raug cai ntawm Raspberry Pi. Nws tsis muaj teeb meem dab tsi duab koj nruab. Txog qhov haujlwm no, tsis xav tau GUI, txij li peb tsuas yog txuas siv SSH.

Sau daim duab rau (tsis muaj) daim npav SD (Txhua cov ntaub ntawv ntawm daim npav yuav raug lwv tawm).

Txhawm rau sau txhua yam rau SD daim npav, peb yuav siv lub cuab yeej hu ua 'Rufus'. Tom qab rub tawm cov duab, qhib Rufus thiab xaiv cov duab ua ntaub ntawv thov. Xaiv lub hom phiaj tsav thiab sau daim duab rau tus tsav. Qhov no tuaj yeem siv sijhawm me ntsis.

> Rufus

Kauj Ruam 1.2: Txhim Kho SSH

Cov kauj ruam tom ntej yog tsim kev sib txuas rau SD daim npav. Txhawm rau ua qhov ntawd, peb yuav tsum tau pab kom SSH.

Txhawm rau ua qhov ntawd yam tsis siv tus saib, qhib koj cov ntaub ntawv tshawb nrhiav thiab qhib qhov muab faib ntawm SD daim npav. Tsim cov ntawv uas tsis muaj npe hu ua "ssh", tsis muaj daim ntawv txuas ntxiv.

Tsis tas li, qhib "cmdline.txt"

Ntxiv "169.254.10.1" hauv qhov kawg ntawm cov ntawv thiab khaws nws.

Unmount SD card thiab ntxig rau hauv Raspberry Pi.

Tam sim no peb tuaj yeem txuas Raspberry Pi mus rau lub zog siv thiab khau raj thiab txuas nrog siv SSH.

Txhawm rau txuas siv SSH, peb siv qhov program "Putty". Txuas koj RPi thiab PC siv txoj hlua txuas txuas ua ntej ua qhov ntawd. Qhib Putty thiab mus rau SSH tab, thiab sau rau tus IP no: 169.254.10.1. Nyem 'txuas' thiab koj yuav txuas nrog.

> Putty

Tus ID nkag mus tsis raug siv los ntawm Raspberry Pi yog 'pi' raws li lub npe siv thiab 'raspberry' rau tus password.

Kauj Ruam 1.3: Kev sib txuas wireless

Koj li Raspberry Pi tam sim no tau qhib.

Peb kuj xav txuas rau RPi siv Wifi, txoj kev ntawd peb tsis xav tau Ethernet cable ntxiv lawm.

Ua cov kab hauv qab no:

'sudo nano /etc/wpa_supplicant/wpa_supplicant.conf'

Qhov no yuav qhib qhov 'nano' cov ntawv sau nrog cov cai tshwj xeeb.

Ntxiv cov kab hauv qab no hauv cov ntawv:

network = {

ssid = "SSID"

psk = "Tus password"

}

Hloov "SSID" nrog SSID ntawm koj lub network Wifi

Hloov "Password" nrog koj tus password.

Tom qab ntawd ua Ctrl+X thiab xaiv qhov 'yog' xaiv. Tam sim no cov ntaub ntawv yuav raug cawm.

Tam sim no peb yuav tsum rov pib dua qhov kev pabcuam sib tham

Ua cov lus txib hauv qab no:

  • 'sudo -i'
  • 'sudo systemctl rov pib dua network'

Koj tuaj yeem sim koj li kev siv internet siv cov lus txib wget.

Piv txwv: 'wget google.com'

> Wget hais kom ua

Kauj Ruam 2: Kauj Ruam 2: Txhim Kho Software ntawm RPi

Txog qhov haujlwm no peb yuav tsum teeb tsa ob peb lub tsev qiv ntawv.

  • Mariadb: MySQL database (sudo apt-tau nruab mariadb-server)
  • Adafruit lub tsev qiv ntawv rau xim xim: Ntsuas xim (pip3 nruab adafruit-circuitpython-tcs34725)
  • PHPmyAdmin: ('sudo apt install phpmyadmin', xaiv apache webserver)

Kuj teeb tsa cov tsev qiv ntawv hauv qab no:

  • hwj txwv_socketio
  • hwj
  • hwj txwv_cors
  • pawg thawj coj saib
  • siv
  • netifaces

Kauj Ruam 3: Kauj Ruam 3: Txuas rau MySQL Database, Tsim Database

Kauj Ruam 3: Txuas rau MySQL Database, Tsim Database
Kauj Ruam 3: Txuas rau MySQL Database, Tsim Database
Kauj Ruam 3: Txuas rau MySQL Database, Tsim Database
Kauj Ruam 3: Txuas rau MySQL Database, Tsim Database
Kauj Ruam 3: Txuas rau MySQL Database, Tsim Database
Kauj Ruam 3: Txuas rau MySQL Database, Tsim Database

Cov kauj ruam tom ntej, yog txuas rau MySQL database siv MySQL workbench.

> Tus IP a

Ua cov lus txib 'ip a', raws li qhia hauv daim duab saum toj no (Nyem txuas)

Hauv ntau qhov xwm txheej, yuav pom 3 nkag. Peb xav tau qhov 'wlan0' nkag. Luam tus IP tom ntej ntawm 'inet', lossis hauv qhov piv txwv no '192.168.1.44'

. >> Tsim kev sib txuas tshiab

Raws li qhia hauv daim duab saum toj no, tsim kev sib txuas tshiab nrog cov ntsuas hauv qab no (Duab hauv qab no rau params)

> Kev sib txuas tsis

Ob npaug nias qhov txuas tshiab uas tau tsim los txuas.

Yog tias muaj qhov tshwm sim tshwm sim, nyem 'Yog'.

Qhov no tseem yog cov ntaub ntawv khoob, yog li cia peb ntxiv qee lub rooj.

Ua ntej tsim cov phiaj xwm, ua li ntawd, ntawm sab laug 'nyem txoj cai' thiab xaiv 'tsim cov phiaj xwm'.

Muab lub npe schema thiab lees paub.

Tam sim no peb xav tau ntxiv cov ntxhuav. Nthuav cov txheej txheem thiab 'right-click', 'tables'.

Tsim cov schema hauv qab no:

> Table 1: RALcolors

> Rooj 2: Hom sensor

> Table 3: Kev ntsuas (Hauv daim duab, 'metingen' yog siv, Dutch rau kev ntsuas)

> Table 4: Website_data || Rooj 4 hauv qab

MySQL yog cov ntaub ntawv txheeb xyuas qhov system, uas txhais tau tias peb tuaj yeem tsim kev sib raug zoo ntawm cov rooj.

Thawj qhov kev sib raug zoo peb yuav tsum tsim yog nruab nrab ntawm 'sensor_type' thiab 'ntsuas'.

Raws li qhia hauv daim duab, txuas ob lub yuam sij.

> Kho lub rooj & txuas cov yuam sij

Tsis txhob hnov qab khaws cov kev hloov pauv los ntawm nyem 'Thov' hauv qab hauv qab.

Kuj hloov kho 'website_data' rooj thiab txuas 'MetingID'.

Tam sim no peb tau ua tiav nrog tsim cov ntxhuav thiab tsim kev sib raug zoo.

Ntxiv cov ntaub ntawv:

RALcolors table yog lub rooj ruaj, qhov twg qhov txiaj ntsig yuav tsis hloov pauv. Peb tuaj yeem ntxiv cov txiaj ntsig no

yooj yim heev

> Rub tawm Excel cov ntawv

Rub tawm cov ntawv excel saum toj no thiab xaiv txhua cov ntaub ntawv thiab 'luam'. Ua zoo li hauv daim duab

> Qhia cov lus

'right-click' ntawm lub rooj thiab xaiv 'Muab kab sib txuas'. 'nyem' 'thov' nyob rau hauv qab kaum sab xis txhawm rau ntxiv cov ntaub ntawv.

Tam sim no txhua RALcolors tau txais kev cawmdim hauv lub database.

Peb tsuas yog xav tau ntxiv cov sensor_type rau cov ntaub ntawv tam sim no.

> Sensortype cov ntaub ntawv

Nco tseg: Cov lus piav qhia ntawm lub sensor yog hauv 'Dutch'

Kauj ruam 4: Kauj Ruam 4: Filezilla

Kauj ruam 4: Filezilla
Kauj ruam 4: Filezilla

Txhawm rau txuas tau yooj yim rau Raspberry Pi thiab xa cov ntaub ntawv, peb tuaj yeem siv Filezilla.

> Download Filezilla

Cov ntaub ntawv hauv cov ntsiab lus txuas thiab txuas. Ntawm sab xis koj tam sim no tuaj yeem xa cov ntaub ntawv los ntawm rub lawv rau hauv.

> Github qhov chaw

Rub tawm cov ntawv los ntawm github qhov chaw saum toj no.

Kauj Ruam 5: Kauj Ruam 5: Tsim Lub Vev Xaib

Kauj Ruam 5: Tsim Lub Vev Xaib
Kauj Ruam 5: Tsim Lub Vev Xaib
Kauj Ruam 5: Tsim Lub Vev Xaib
Kauj Ruam 5: Tsim Lub Vev Xaib

Rau kev tuav lub vev xaib, peb siv PHPmyAdmin thiab Apache2.

Lub webserver ntawm Raspberry Pi siv '/var/www/html' cov npe raws li hauv paus.

Yog tias koj tso koj cov ntaub ntawv nyob rau ntawd, lawv yuav raug tuav ntawm IP ntawm Raspberry Pi. (IP = saib 'ip a')

Koj tuaj yeem rub tawm cov ntawv xav tau los ntawm kuv github repo (cov kauj ruam dhau los)

Hauv '/var/www/html/', muab tag nrho cov ntaub ntawv los ntawm 'Frontend' nplaub tshev.

>/var/www/html/

Kauj Ruam 6: Kauj Ruam 6: Tsim Lub Backend (Flask)

Lub vev xaib backend yog raws li Flask.

Txhua cov ntaub ntawv tuaj yeem pom ntawm github repo.

Luam tag nrho cov ntaub ntawv rau txhua phau ntawv teev npe ntawm Raspberry Pi.

Piv txwv li '/home/pi/colorpicker.

Txhawm rau tsim cov npe, txav mus rau phau ntawv qhia chaw siv 'cd', thiab tom qab ntawd ua tiav 'mkdir'.

Qhov ntawd yog txhua yam rau tam sim no. Txoj cai yuav piav qhia hauv cov kauj ruam tom ntej.

Kauj Ruam 7: Kauj Ruam 7: Kho vajtse

> Download Scheme

Tsim cov phiaj xwm zoo li qhia hauv daim ntawv saum toj no.

NCO TSEG: Ntxiv rau ib qho LED dawb, nrog rau ib tus tiv thaiv (220 lossis 330 Ohms).

Piav txog kho vajtse

HC04

HC04 sensor tso tawm nthwv dej, uas cuam tshuam thiab tau txais dua los ntawm lub ntsuas.

Los ntawm kev suav lub sijhawm delta nruab nrab ntawm kev tso tawm thiab tau txais, peb tuaj yeem suav qhov deb.

Qhov nrug = ((Timestamp_recieve - Timestamp_emit) / suab nrawm) / 2

Peb faib los ntawm ob vim hais tias nthwv dej cuam tshuam, txhais tau tias nws taug kev deb ob zaug.

LCD

Peb siv lub vijtsam LCD los qhia RGB thiab HEX, zoo li tus IP thaum txoj haujlwm pib.

Rau lub LCD no, Kuv yuav ib qho I2C module. Peb tsuas xav tau 4 xov hlau tam sim no. SDA, SCL, GND, VCC

Txhawm rau siv lub LCD no, Kuv tau sau chav kawm Python, kom yooj yim siv.

TIAB SA 34725

Qhov ntsuas no tso cai rau koj ntsuas xim. Peb siv lub tsev qiv ntawv los ntsuas tus nqi RGB.

Kauj Ruam 8: Kauj Ruam 8: Piav Qhia

Kauj Ruam 8: Piav Qhia
Kauj Ruam 8: Piav Qhia
Kauj Ruam 8: Piav Qhia
Kauj Ruam 8: Piav Qhia
Kauj Ruam 8: Piav Qhia
Kauj Ruam 8: Piav Qhia
Kauj Ruam 8: Piav Qhia
Kauj Ruam 8: Piav Qhia

Lub ntsej muag

Lub ntsej muag tshwm sim ntawm peb ntu loj.

Ua ntej tshaj yog cov ntaub ntawv html, uas tsim cov qauv ntawm peb lub vev xaib, tab sis tsis muaj lossis tsawg txheej txheem.

Qhov thib ob peb muaj cov ntaub ntawv css, lossis cov ntaub ntawv style, uas style thiab teeb tsa peb lub vev xaib.

Ob qho no yooj yim heev rau nyeem thiab nkag siab, uas yog vim li cas kuv thiaj tsis piav qhia lawv.

Kawg peb muaj Javascript, nrog ob lub tsev qiv ntawv.

Ob lub tsev qiv ntawv siv yog SocketIO thiab URLSearchParams.

SocketIO tso cai rau koj xa cov lus los ntawm lub backend mus rau lub ntsej muag, thiab hloov pauv.

Cov lus tuaj yeem xa mus rau ib tus neeg siv khoom, tab sis kuj tseem muaj ntau tus neeg siv khoom (Tshaj Tawm)

> Socket IO Javascript

> Socket IO Python

Hauv cov duab saum toj no, koj tuaj yeem pom ib qho ntawm Cov Qhov Txuas Txuas ua hauv qhov haujlwm no.

Cov lus txib kom xa xov yog 'emit', kev ua tiav yog ua los ntawm 'on'.

URLSearchParms tso cai rau koj kom tau txais txiaj ntsig los ntawm cov lus nug yooj yim.

Piv txwv querystring: piv txwv.com/index.html?id=1

URLSearchParams yuav muab rov qab rau koj: {'id' = '1'}

> URLSearchParams Piv txwv

Cov backend

Lub backend tau sau tag nrho hauv Python, nrog rau pawg ntawm cov tsev qiv ntawv.

Thawj lub tsev qiv ntawv peb ntshuam yog 'Flask'. Lub tsev qiv ntawv no xav tau los tsim API, ua txhua yam CRUD ua rau MySQL database. CRUD sawv rau Tsim Nyeem Hloov Tshiab Rho Tawm.

> Flask

Cov duab saum toj no qhia txog ob peb Flask 'txoj kev'. Los ntawm caij nthwv dej mus rau txoj kev, koj yuav cia li ua 'GET' txoj hauv kev, cov cai yuav ua thiab koj yuav tau txais tus nqi los ntawm txoj kev rov qab los. Kuj tseem muaj lwm txoj hauv kev, zoo li 'POST' thiab 'DELETE'. Txhawm rau sim cov txheej txheem no, koj yuav xav tau ib txoj haujlwm zoo li Postman.

Lub tsev qiv ntawv ntshuam tom ntej yog SocketIO, uas kuv tau piav qhia nyob hauv ntu kawg hauv ntej.

Ib qho ntxiv yog GPIO.

Qhov no tso cai rau koj los tswj GPIO tus pin ntawm Rapsberry Pi.

Cov lus txib tseem ceeb tshaj plaws yog:

  • GPIO.setmode (GPIO. BCM) Xaiv qhov teeb tsa ntawm tus pin.
  • GPIO.output (, GPIO. LOW lossis GPIO. HIGH) Sau LOW lossis HIGH rau tus pin.
  • GPIO.setup (,) Txheeb xyuas tus lej PIN li cov tswv yim lossis tso tawm, lossis rub tawm lossis rub tawm

Tom ntej no peb muaj threading.

Tsuas yog cov lus txib peb siv yog:

  • Xov (phiaj =)
  • . pib ()

Siv xov, peb tuaj yeem ua haujlwm ntau zaus ntawm cov lej tib lub sijhawm. Txoj kev no peb tuaj yeem ntsuas kev nrug deb thiab tib lub sijhawm, mloog cov lus nkag hauv qhov io.

Thawj lo lus txib Thread (phiaj =) yuav tsim Thread class, uas thaum pib siv 'pib ()', yuav ua haujlwm hauv lo lus tseem ceeb 'phiaj', uas tau muab rau ntawm kev tsim cov chav kawm.

Tom ntej no peb muaj lub tsev qiv ntawv xim xim, uas yog ncaj nraim rau pem hauv ntej. Kuv tsis piav qhia lub tsev qiv ntawv no, vim tias cov txheej txheem tau meej heev thiab piav qhia hauv txoj cai.

Thaum kawg peb muaj netifaces. Qhov no ua rau peb rov qab tau tus IP chaw nyob uas peb siv rau Kev Sib Txuas Wireless thiab Wired.

Kawg kuv tau ua qee chav kawm kuv tus kheej rau qhov ntsuas qhov deb, LED thiab LCD.

Kuv yuav tsis piav qhia cov haujlwm ntawd li cas.

Kauj Ruam 9: Kauj Ruam 9: Tsim Rooj Plaub

Kauj Ruam 9: Tsim Rooj plaub
Kauj Ruam 9: Tsim Rooj plaub
Kauj Ruam 9: Tsim Rooj Plaub
Kauj Ruam 9: Tsim Rooj Plaub
Kauj Ruam 9: Tsim Rooj plaub
Kauj Ruam 9: Tsim Rooj plaub

Txog qhov haujlwm no, kuv tsim rooj ntoo.

Ntoo yog qhov hnyav, nyias thiab tsis raug nqi ntau.

Raws li qhov ntev kuv tau siv:

  • Qhov siab: 5 cm
  • Dav: 10.5cm
  • Ntev: 12.5cm

Txog cov ntsuas, koj yuav tsum ntxiv 2 qhov thiab tso lawv nyob ib sab.

Tom qab tsim cov ntaub ntawv, teeb tsa lub ntsuas cua, LED thiab LCD.

Kauj Ruam 10: Kauj Ruam Kawg

Txhua yam yog ua tiav.

Tam sim no peb tsuas yog yuav tsum paub tseeb tias peb cov cai pib, lub sijhawm peb ntsaws rau hauv peb lub zog siv.

Muaj ntau txoj hauv kev los ua qhov no.

> Piv txwv

Peb yuav siv thawj txoj kev:

Ua txoj kab no: 'sudo nano /etc/rc.local'

Ntxiv koj cov lus txib kom ua raws txoj cai: 'sudo python3'

Txuag cov ntaub ntawv siv Ctrl-X.

Yog tias koj muaj teeb meem kho. Rov ua cov kauj ruam no, tab sis thawj zaug ua 'sudo -i'.

Pom zoo: