Cov txheej txheem:

Shockbot: 8 Kauj Ruam (nrog Duab)
Shockbot: 8 Kauj Ruam (nrog Duab)

Video: Shockbot: 8 Kauj Ruam (nrog Duab)

Video: Shockbot: 8 Kauj Ruam (nrog Duab)
Video: 9. 10 los koj yuav nrauj 8/7/2019 2024, Hlis ntuj nqeg
Anonim
Shockbot
Shockbot

Raspberry Pi + hluav taws xob tam sim no lub paj hlwb stimulator + Twitter = Shock-bot

Nws yog Xyoo Tshiab Xyoo yog li kuv tau txiav txim siab xaim xov tooj nrog TEES (Kev hloov pauv hluav taws xob cov hlab paj hlwb) ntaus ntawv los ntawm kev xa mus rau raspberry pi thiab tom qab ntawd sau cov ntawv nab nab uas ntsuas kuv li Twitter pub rau hashtag #happynewyear. Txhua lub sijhawm nws pom #happynewyear, nws ua rau kuv poob siab! GREAT IDEA, YOG!?!?

Lub sijhawm los tshuaj xyuas cov npe khoom:

Kauj Ruam 1: Daim Ntawv Teev Npe

Daim Ntawv Teev Npe
Daim Ntawv Teev Npe

Nov yog yam koj yuav xav tau rau txoj haujlwm no

✔ Raspberry Pi

E TSO Ntaus ntawv

Ay Relay Breakout

✔ Twitter Account

✔ Hlau

Tsis tas li, Tsis txhob ua qhov no yog tias koj muaj teeb meem plawv!

Kauj ruam 2: Npaj Pi Npaj

Ua ntej, Kuv xav tias koj paub nrog siv Raspberry Pi los ntawm SSH yog li peb yuav pib los ntawm kev hloov kho Pi

SSH rau hauv koj tus Pi thiab khiav

sudo apt-tau hloov tshiab

thiab

sudo apt-tau hloov tshiab

yog li peb tuaj yeem pib nrog qhov hloov tshiab Pi. Tam sim no peb yuav tsum tau txais ob peb pob los nruab.

Khiav cov lus txib no txhawm rau rub tawm txhua pob khoom xav tau rau txoj haujlwm no:

sudo apt-tau nruab nruab sej-pip

sudo pip nruab twython

Kauj Ruam 3: Ua Koj Li Twitter App

Tam sim no peb yuav mus rau Twitter

Mus ntsib apps.twitter.com thiab sau npe lossis nkag mus yog tias koj twb muaj tus as khauj lawm.

Thaum koj tau kos npe rau hauv, nyem rau ntawm koj tus neeg siv lub cim, thiab xaiv "Kuv Cov Ntawv Thov".

Nyem rau ntawm "Tsim daim ntawv thov tshiab" khawm, ua daim ntawv hais txog koj daim ntawv thov. Sau lub npe thiab cov lus piav qhia. Rau "Lub Vev Xaib," koj tuaj yeem tso txhua yam uas zoo li raug cai. Hauv qab ntawm nplooj ntawv, nyem rau ntawm lub npov kom pom zoo rau cov lus, thiab nyem rau "Tsim koj li Twitter app" khawm.

Tam sim no koj yuav tsum tsim tus lej nkag mus los ntawm txhaj rau "Tsim kuv nkag token" khawm hauv qab ntawm qhov screen. Luam theej "Tus yuam sij neeg siv khoom," "Tus neeg siv khoom zais," "Nkag mus rau tus lej," thiab "Nkag mus rau tus lej zais." Koj yuav xav tau cov no rau tsab ntawv shockbot.py.

Kauj Ruam 4: Ua tiav Qhov Software

Rov qab mus rau Pi kom ua cov ntawv nab nab.

Peb yuav ua cov npe rau peb txoj haujlwm los ntawm kev ntaus:

sudo mkdir shockbot

Tsiv mus rau hauv phau ntawv teev npe tshiab no los ntawm kev ntaus ntawv

cd shockbot

Tam sim no peb yuav ua cov ntawv Python.

Siv qhov hais kom ua

nano sockbot.py

qhib cov ntawv nyeem editor.

Luam cov ntawv Python. Nco ntsoov tias koj ntxiv rau hauv koj cov ntaub ntawv token uas koj tau txais thaum tsim Twitter app.

ntshuam sijhawm ntshuam RPi. GPIO li GPIO los ntawm twython ntshuam TwythonStreamer

# Tshawb nrhiav cov ntsiab lus

TERMS = '#yourhashtag'

# GPIO tus lej tus lej ntawm LED

LED = 22 hli

# Twitter daim ntawv pov thawj kev lees paub

APP_KEY = 'YOUR_APP_KEY' APP_SECRET = 'YOUR_APP_SECRET' OAUTH_TOKEN = 'YOUR_TOKEN' OAUTH_TOKEN_SECRET = 'YOUR_TOKEN_SECRET'

# Teeb kev hu rov qab los ntawm Twython Streamer

chav BlinkyStreamer (TwythonStreamer): def on_success (tus kheej, cov ntaub ntawv): yog 'ntawv' hauv cov ntaub ntawv: luam cov ntaub ntawv ['ntawv']. encode ('utf-8') luam GPIO.output (LED, GPIO. HIGH) lub sijhawm. pw tsaug zog (1) GPIO.output (LED, GPIO. LOW)

# Teeb GPIO raws li tso tawm

GPIO.setmode (GPIO. BOARD) GPIO.setup (LED, GPIO. OUT) GPIO.output (LED, GPIO. LOW)

# Tsim streamer

sim: kwj = BlinkyStreamer (APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) stream.statuses.filter (khiav = TERMS) tshwj tsis yog KeyboardInterrupt: GPIO.cleanup ()

Txij ntawm no mus, koj xav teeb koj li Twitter lo lus tseem ceeb. Kuj teem sijhawm. sijhawm pw tsaug zog rau lub sijhawm koj xav kom poob siab.

Txuag thiab tawm

Qhov ntawd ua tiav qhov software ib feem ntawm txoj haujlwm no

*Txoj cai no tau pab txhawb rau Sparkfun tutorials project los ntawm ShawnHymel. Peb tau rov txhim kho nws kom ua rau peb lub cuab yeej.

Kauj Ruam 5: Npaj TEEV Txuas

Npaj TEEV Txuas
Npaj TEEV Txuas

Lub sijhawm kom tshem tawm TEES thiab xa tawm thiab hack qee yam khoom siv

The T. E. N. S. cov cuab yeej muaj ob lub ncoo nkag rau sab saum toj, peb tsuas yog xav tau ib qho. Nqa ib txheej ntawm cov ntaub qhwv thiab rub cov xov hlau sib nrug mus txog 4 lossis 5 ntiv tes los ntawm lub ntsaws.

Ua raws cov xaim nrog lub txuas liab nyob saum thiab txiav nws ze rau hauv qab qhov uas nws ntsaws rau hauv lub cuab yeej. Kuv tau siv lub taub hau taub hau rau qhov kawg ntawm txhua lub xov hlau.

Kauj Ruam 6: Txhim Kho Koj Li Relay

Txhim Kho Koj Tus Kheej
Txhim Kho Koj Tus Kheej
Txhim Kho Koj Tus Kheej
Txhim Kho Koj Tus Kheej

Coj koj qhov kev sib kis tawm mus thiab txuas lub ntsaws sab ntawm cov xaim txiav mus rau hauv "Common" davhlau ya nyob twg ntawm kev xa xov.

Txuas lub ncoo sab ntawm cov xaim txiav rau hauv "Feem ntau Qhib" lub davhlau ya nyob twg. Koj tuaj yeem siv lub ntsuas ntsuas ntau los nrhiav qhov no yog tias koj qhov txuas tsis muaj cov cim rau ntawm nws. Ntawm qhov qis hluav taws xob sab ntawm kev xa tawm, txuas xov hlau mus rau Lub Hwj Chim, Hauv Paus, thiab Cov Piav Qhia.

Kauj Ruam 7: Txuas Txuas Txuas mus rau Pi

Txuas tus Relay rau Pi
Txuas tus Relay rau Pi

Lub Hwj Huam thiab Hauv av pins yuav txuas rau lub zog thiab Hauv av ntawm Pi thiab Cov Cim yuav txuas rau tus pin 22 ntawm Pi. Google tshawb nrhiav tus pinouts kom phim tus qauv Pi koj siv.

Pop lub roj teeb rau hauv koj TEES thiab qhov ntawd ua tiav kho vajtse.

Kauj ruam 8:

Duab
Duab

Tig rau T. E. N. S. thiab muab cov ntaub qhwv rau ntawm koj lub xub pwg thiab npaj kom pib cov ntawv nab nab

Ntawm koj Pi hauv koj phau ntawv teev npe shockbot khiav

sudo python shockbot.py

los ntawm phau ntawv teev npe shockbot.

Tam sim no zaum rov qab thiab tos. Koj yuav xav pib nrog cov chaw qis thiab tsoo lawv. Koj tseem tuaj yeem cuam tshuam nrog cov cuab yeej teeb tsa kom tau txais qhov txiaj ntsig xav tau.

Cov haujlwm no yog muab rau kev kawm nkaus xwb. Tsuas yog rov ua qhov no ntawm koj tus kheej txoj kev pheej hmoo. Kuv tsis yog lub luag haujlwm yog tias koj mus rau hauv tsev kaw neeg lossis tuag!

Pom zoo: