Cov txheej txheem:

RaspberryPI Lub Koob Yees Duab Yees Duab - MagicBox: 13 Cov Kauj Ruam (nrog Duab)
RaspberryPI Lub Koob Yees Duab Yees Duab - MagicBox: 13 Cov Kauj Ruam (nrog Duab)

Video: RaspberryPI Lub Koob Yees Duab Yees Duab - MagicBox: 13 Cov Kauj Ruam (nrog Duab)

Video: RaspberryPI Lub Koob Yees Duab Yees Duab - MagicBox: 13 Cov Kauj Ruam (nrog Duab)
Video: Tswv Yexus lub neej thaum pib txug thaum xaus 2024, Hlis ntuj nqeg
Anonim
Image
Image
Tsim
Tsim

Ib pliag dhau los, Kuv muaj lub tswv yim vwm no los tsim lub tshuab yees duab tawm ntawm Raspberry PI. Hauv kuv lub nroog, muaj qhov yeeb yam me me uas tib neeg yuav mus thiab qhia qhov lawv tau ua lossis tau siv hluav taws xob, khoos phis tawj, thiab lwm yam … Kuv zoo li tus neeg pluag Maker Faire, tab sis nyob ntawm thaj tsam ib puag ncig.

Ib tus tau los txog, thiab, ua ke nrog kuv tus poj niam, peb tsim qhov no.

Nws ua haujlwm li cas?

Koj nias lub pob xiav - nws pib ntsais muag - thiab tom qab 3 vib nas this ib daim duab tau tshwm sim. Ntawm lwm sab ntawm lub koob yees duab muaj tus saib xyuas uas tau qhia txog kev suav rov qab thiab tom qab thaij duab, saib ua ntej ntawm daim duab.

Tam sim no koj tuaj yeem xaiv xa nws mus rau Twitter thiab Facebook lossis rho tawm thiab sim dua. Nws yog qhov yooj yim.

Txhua yam tau teeb tsa hauv Python, siv PI framebuffer - Tsis muaj Xorg, tsis siv GUI.

Nov yog daim vis dis aus ntawm txoj haujlwm ua haujlwm

Khoom siv

  • Raspberry PI (Kuv siv version 2)
  • Raspberry PI Lub Koob Yees Duab (Siv version 1)
  • 3 X Loj Dome thawb khawm
  • TFT/LCD Saib nrog VGA/HDMI
  • MDF
  • Hlau hinges, ntsia hlau, thiab lwm yam..
  • Cov Cuab Yeej Siv Hluav Taws Xob
  • Txuag sijhawm thiab lom zem heev

Kauj ruam 1: Tsim

Tsim
Tsim
Tsim
Tsim

Tsim nws yog kev lom zem. Ntau qhov txiav, pleev xim thiab drilling.

Kuv siv MDF vaj huam sib luag los tsim lub hauv paus qauv ntawm lub koob yees duab. Lawv yog lub teeb thiab yooj yim los ua haujlwm nrog. Tsis tas li ntawd, nws yog ib hom ntoo uas siv lub tshuab Laser ntawm lub zos Fablab tuaj yeem txiav tau.

Kev nkag mus rau cov hlua sab hauv yog ua los ntawm tus saib sab, siv cov khawm khawm kom lawv tuaj yeem pab nqa lub saib.

Kauj Ruam 2: Lub Koob Yees Duab

Lub Koob Yees Duab
Lub Koob Yees Duab
Lub Koob Yees Duab
Lub Koob Yees Duab
Lub Koob Yees Duab
Lub Koob Yees Duab

Lub Koob Yees Duab

Lub koob yees duab yog lub npov uas muaj qhov ntev hauv qab no: 60cm x 40cm x 30cm Koj li tuaj yeem me dua, loj dua, nws yog koj li. Tsuas yog xav tau kom haum rau lub monitor koj yuav siv. Cov vaj huam sib luag MDF tau txiav laser ntawm Fablab lub zos. Muaj qhov xav tau 3 qhov nyob tom qab - ob lub khawm loj dome thawb thiab ib qho rau tus saib. Nyob rau sab xub ntiag, 2 qhov - ib qho rau lub khawm dome loj thiab lwm qhov - me dua - rau Raspberry PI lub koob yees duab. Kuv tsis muaj kev ntsuas tshwj xeeb - tsuas yog xav txog lub koob yees duab thiab siv qhov ntawd.

Kauj Ruam 3: Saib Xyuas

Saib xyuas
Saib xyuas
Saib xyuas
Saib xyuas
Saib xyuas
Saib xyuas

Saib xyuas

Kev saib xyuas tau ua ntxiv cov ntoo me me los txhawb nws hauv nws qhov ntev.

Nws yog kab txaij los ntawm lub tsev yas thiab ruaj khov nrog cov ntsia hlau. Txhawm rau pab nqa nws, ob lub khawm khawm hydraulic (siv) tau siv.

Kauj ruam 4: Kho kom zoo nkauj

Kho kom zoo nkauj
Kho kom zoo nkauj
Kho kom zoo nkauj
Kho kom zoo nkauj
Kho kom zoo nkauj
Kho kom zoo nkauj
Kho kom zoo nkauj
Kho kom zoo nkauj

Txij li thaum kuv nyiam ntau yam ntawm kuv tus Fuji X-T30, peb tau mus thiab ua qee yam zoo sib xws.

Ua ntej, peb tau npog nws nrog ua npuas dej thiab tom ntej no peb tsuag xim nws dub. Tom qab pleev xim, peb ntxiv cov ntawv txhuas rau cov nyiaj thiab qhwv rau hauv

Txhawm rau sim lub lens, peb tsuas yog siv Tupperware puag ncig peb tau ua lub qhov me me rau Raspberry PI lub koob yees duab module los zaum.

Kauj ruam 5: Programming

Kev tsim lub Koob Yees Duab yog qhov nyuaj, tab sis nws lom zem heev.

Tsis muaj GUI - qhov no khiav ntawm CLI thiab nws khiav ntawm Python version 3.

Kuv xub pib los ntawm kev sim thiab teeb tsa cov nyees khawm, tom ntej no tau thaij duab siv cov cuab yeej twb tau muab thiab Python API. Kuv mam li txav mus rau cov duab thaub qab hauv lub koob yees duab tso tawm (rau suav rov qab) thiab tom ntej no los cuam tshuam nrog Twitter thiab Facebook.

Tom qab kuv tau xis nyob nrog txhua qhov ntawd, zoo li cov duab dhos ua si, Kuv tau sau txhua daim ua ke. Nyob ntawm no, peb mus nrog tib txoj kev. Pib qeeb thiab me me thiab mus nrawm thiab loj.

Ua ntej, cia pib los ntawm kev teeb tsa Raspberry PI

Kauj Ruam 6: Npaj Raspberry PI

Npaj Raspberry PI
Npaj Raspberry PI
Npaj Raspberry PI
Npaj Raspberry PI
Npaj Raspberry PI
Npaj Raspberry PI

Kuv yuav tsis piav qhia yuav ua li cas rau nruab Raspbian ntawm Raspberry PI - muaj ntau yam kev qhia tawm, txawm tias ntawm Raspberry PI official lub vev xaib.

Koj tsuas yog yuav tsum muaj SSH nkag mus rau nws, lossis txuas nws mus rau tus saib xyuas thiab ntsaws rau hauv cov keyboard thiab nas.

NCO TSEG: Thaum pib nrog Raspberry PI lub koob yees duab, koj yuav tsum muaj nws ntsaws rau hauv lub monitor. Txog thaum muaj, txhua kauj ruam tuaj yeem ua tau siv SSH.

Tom qab pib koj lub Raspberry PI, peb yuav tsum ua kom lub koob yees duab Raspberry PI. Cia peb siv cov cuab yeej raspi-teeb tsa rau qhov ntawd.

sudo raspi-teeb tsa

  1. Xaiv qhov kev xaiv 5 - Kev xaiv cuam tshuam
  2. Xaiv P1 - Pab/Disable txuas rau Raspberry PI lub koob yees duab
  3. Hais Yog
  4. rau OK
  5. Xaiv Tiav
  6. Xaiv Yog kom rov pib dua tam sim no

Tom qab rov pib dua, peb tuaj yeem ua mus ntxiv

Kauj ruam 7: Software

Peb yuav xav tau qee lub tsev qiv ntawv Python los teeb tsa. Qhov no tau hloov kho tshiab rau qhov tseeb Raspbian version - Buster

Ua ntej, cia teeb Python 3 ua lub neej ntawd. Ua raws qhov txuas no kom paub yuav teeb nws li SYSTEM WIDE

Tsev qiv ntawv:

  • nab hab sej-pil.imagetk los tswj cov duab
  • nab hab sej-rpi.gpio txhawm rau nkag mus rau GPIO PINS
  • nab hab sej-picamera txhawm rau nkag mus rau Raspberry PI Lub Koob Yees Duab
  • Tweepy los qhia daim duab rau twitter
  • facebook-sdk los qhia rau hauv Facebook nplooj ntawv

sudo apt-tau nruab python3-pil.imagetk python3-rpi.gpio python3-picamera python3-tweepy python3-pip

Siv Python pip los nruab facebook-sdk

sudo pip3 nruab facebook-sdk

Kauj Ruam 8: Programming - Saib Ua Ntej Lub Koob Yees Duab

Image
Image
Programming - Saib ua ntej lub koob yees duab
Programming - Saib ua ntej lub koob yees duab
Programming - Saib ua ntej lub koob yees duab
Programming - Saib ua ntej lub koob yees duab

Ib qho ntawm qhov yuav tsum tau kuv teeb tsa rau txoj haujlwm no yog tias qhov haujlwm no tau ua haujlwm hauv CLI hom. Yog li, peb yuav tsum tso saib lub koob yees duab duab ntawm lub console. Txog qhov no, cia siv Python Picamera. Tom qab ntawd, cia peb siv pil.imagetk los tso saib ib qho kev sib tshooj nyob saum lub koob yees duab saib ua ntej

Peb qhov haujlwm me me (peb tab tom tsim kho cov haujlwm me me kom txog rau thaum ib qho loj thaum kawg) yuav tso saib lub koob yees duab saib ua ntej.

#!/usr/bin/env nab hab sej

ntshuam lub sijhawm ntshuam picamera los ntawm lub sijhawm ntshuam lub koob yees duab = picamera. PiCamera () # Teeb lub rooj koj xav tau camera.resolution = (1280, 1024) camera.framerate = 24 camera.start_preview () sim: thaum (Muaj tseeb): pw tsaug zog (1) tshwj tsis yog (KeyboardInterrupt, SystemExit): luam tawm ("Tawm …") camera.stop_preview ()

Txhawm rau sim nws tsuas yog ua nws

nab hab sej lub koob yees duabPreview.py

Saib ua ntej lub koob yees duab nrog cov duab nyob saum

Txij li thaum kuv xav kom suav suav daws tshwm sim ua ntej thaij duab, Kuv xav tau cov duab sib tshooj ntawm lub koob yees duab saib ua ntej.

Tsim cov duab-p.webp" />

Cov cai hauv qab no yuav sib tshooj 1-p.webp

ntshuam picamerafrom PIL ntshuam duab los ntawm lub sijhawm ntshuam pw nrog picamera. PiCamera () raws li lub koob yees duab: camera.resolution = (1920, 1080) camera.framerate = 24 camera.start_preview () # ntsaws duab img = Image.open ('1-p.webp

Sim nws:

nab hab sej imageOverlay.py

Cia tam sim no tsim kev suav nrog suav cov duab. Zoo li koj tau tsim 1-p.webp

Tom qab ntawd, tsuas yog siv cov cai hauv qab no:

ntshuam picamera

los ntawm PIL ntshuam duab los ntawm lub sijhawm ntshuam pw nrog picamera. PiCamera () raws li lub koob yees duab: camera.resolution = (1280, 1024) camera.framerate = 24 camera.start_preview () # thauj cov duab img1 = Image.open ('3.png') img2 = Image.open ('2.png') img3 = Image.open ('1.png') # tsim ncoo = Image.new ('RGB', (((img1.size [0] + 31)) / / 32) * 32, ((img1.size [1] + 15) // 16) * 16,)) pad.paste (img1, (0, 0)) o = camera.add_overlay (pad.tobytes (), size = img1.size) o.alpha = 128 o.layer = 3 pw (2) #tshem tawm yav dhau los overlay camera.remove_overlay (o) pad.paste (img2, (0, 0)) o = camera.add_overlay (ncoo. tobytes (), qhov loj = img2.size) o.alpha = 128 o.layer = 3 pw (2) # tshem tawm yav dhau los overlay camera.remove_overlay (o) pad.paste (img3, (0, 0)) o = lub koob yees duab. add_overlay (pad.tobytes (), loj = img3.size) o.alpha = 128 o.layer = 3 pw (2)

Tam sim no ua nws:

nab hab sej imageOverlayCounter.py

Thiab saib cov suav rov qab

Wow - Qee qhov ntau thiab tsis muaj daim duab thaij … Wb daws qhov ntawd los ntawm kev sib koom ua ke - saib ua ntej lub koob yees duab, suav rov qab thiab thaij duab

ntshuam picamerafrom PIL ntshuam duab los ntawm lub sij hawm ntshuam pw def overlayCounter (): # ntsaws cov duab img1 = Image.open ('3.png') img2 = Image.open ('2.png') img3 = Image.open ('1.-p.webp

Sim nws:

nab hab sej duabWithTimer.py

Thiab ntawm no peb muaj Yoda

Kauj Ruam 9: Kev Ua Haujlwm - Loj Dome Push Button

Programming - Loj Dome Push Button
Programming - Loj Dome Push Button
Programming - Loj Dome Push Button
Programming - Loj Dome Push Button

Lub khawm loj dome thawb yog lub khawm puag ncig loj - nrog ib ncig 100mm tawm txoj kab uas hla nrog lub me me LED. Nws hais tias nws ua haujlwm ntawm 12V, tab sis 3.3v ntawm Raspberry PI txaus los teeb nws

Siv cov txheej txheem ntsuas

Cov cai:

los ntawm RPi ntshuam GPIO

takeButton = 17 ledButton = 27 GPIO.setmode (GPIO. BCM) GPIO.setup (takeButton, GPIO. IN, GPIO. PUD_UP) GPIO.setup (coj Kev thaiv kev ua haujlwm GPIO.wait_for_edge (siv, Button, GPIO. FALLING) luam tawm ("Nias Nias") GPIO.output (ledButton, False) GPIO.cleanup ()

Qee qhov piav qhia ntawm txoj cai Ib qho ntawm cov ntawv tau txais txiaj ntsig los ntawm GPIOS yog los ntawm kev cuam tshuam (lwm qhov yog kev xaiv tsa) - kev txheeb xyuas ntug.

Ntug ntug yog lub npe ntawm kev hloov pauv los ntawm HIGH mus rau LOW (ntog ntug) lossis LOW mus rau HIGH (nce ntug). Thaum tus lej PIN tsis txuas nrog ib yam dab tsi, ib qho nyeem yuav tsis tau txhais. Ib qho kev daws teeb meem yog kom muaj kev rub tawm/nqis resistor hauv tus lej PIN. Raspberry PI tso cai rau teeb tsa rub tawm/nqis resistors los ntawm software.

Kab

GPIO.setup (takeButton, GPIO. IN, GPIO. PUD_UP)

teeb tsa tus lej PIN kom ua li ntawd - rub tawm

Vim li cas rub? Zoo, lub khawm loj dome khawm muaj 2 tus lej PIN - thawb kom tawg lossis thawb kom ua (ib yam li cov khawm me me uas feem ntau tuaj nrog Arduino/Raspberry PI cov khoom siv). Kuv tau txuas nws mus rau "thawb ua" PIN ntawm lub pob. Thaum nias, lub kaw lus kaw thiab hluav taws xob hla (ib txwm qhib).

Kab

GPIO.wait_for_edge (takeButton, GPIO. FALLING)

yuav tos (tshem tawm qhov ua tiav ntawm tsab ntawv) kom txog thaum nws pom qhov poob ntawm tus lej PIN - tso lub pob yuav txiav cov hluav taws xob ntws thiab tus lej PIN yuav los ntawm 3.3v txog 0v

LED PIN tsuas yog txhawm rau teeb lub LED ntawm lub pob

Xav paub ntau ntxiv txog kev thawb hloov los ntawm Arduino Tutorials, Wikipedia ntawm kev thawb los ua lossis thawb kom tawg thiab GPIO cuam tshuam

Tam sim no, cia ua ke lub laub khawm nrog lub koob yees duab - thaij duab tsuas yog thaum lub pob nyem

ntshuam picamera los ntawm lub sijhawm ntshuam pw los ntawm RPi ntshuam GPIO los ntawm PIL ntshuam duab # LUS CEEB TOOM: Nov yog dab tsi yuav yog lub khawm rho tawm hauv txoj haujlwm tseem ceeb # Kuv tsuas yog siv nws ntawm no kom pom tseeb hauv qhov yees duab takeButton = 24 ledCancel = 5 GPIO.setmode (GPIO. BCM) GPIO.setup (takeButton, GPIO. IN, GPIO. PUD_UP) GPIO.setup (ledCancel, GPIO. OUT) def onLeds (): GPIO.output (ledCancel, Tseeb) pw (1) def offLeds (): GPIO.output (ledCancel, False) # Muaj nuj nqi rau overlay duab def overlayCounter (): # thauj cov duab img1 = Image.open ('3.png') img2 = Image.open ('2.png') img3 = Image.open ('1.png') # Tsim kev sib tshooj # Siv nrog img1 vim tias txhua yam zoo ib yam me me = Image.new ('RGB', (((img1.size [0] + 31) // 32) * 32, ((img1.size [1] + 15) // 16) * 16,)) # muab cov ntawv tso rau - 3 pad.paste (img1, (0, 0)) ov = camera.add_overlay (pad.tobytes (), qhov loj = img1.size) ov.alpha = 200 # txheej yog 3 vim lub koob yees duab saib ua ntej yog nyob rau txheej 2 ov.layer = 3 pw (1) camera.remove_overlay (ov) # muab tshuaj txhuam rau - 2 ncoo.paste (img2, (0, 0)) ov = camera.add_overlay (pad.tobytes (), size = img2.size) ov.alpha = 200 # txheej yog 3 vim lub koob yees duab saib ua ntej yog txheej 2 ov.layer = 3 pw (1) camera.remove_overlay (ov) # muab tshuaj txhuam tso rau - 1 pad.paste (img3, (0, 0)) ov = camera.add_overlay (pad.tobytes (), loj = img3.size) ov.alpha = 200 # txheej yog 3 vim lub koob yees duab saib ua ntej ntawm txheej 2 ov.layer = 3 pw (1) camera.remove_overlay (ov) camera = picamera. PiCamera () camera.resolution = (1280, 1024) camera.framerate = 24 camera.start_preview () GPIO.wait_for_edge (takeButton, GPIO. FALLING) onLeds () overlayCounter () camera.capture ('pushTesting.jpg') camera.stop_preview () offLeds () GPIO.cleanup ()

Kev piav me ntsis

Nws pib lub koob yees duab saib ua ntej thiab tos nyob ntawd kom txog thaum lub pob nyem. Tom qab lub pob nyem, lub teeb ci LED thiab suav rov pib dua. Thaum mus txog qhov kawg, daim duab raug coj thiab LED tau muab tua

Kauj ruam 10: Tshaj tawm rau Twitter

Tshaj tawm rau Twitter
Tshaj tawm rau Twitter
Tshaj tawm rau Twitter
Tshaj tawm rau Twitter
Tshaj tawm rau Twitter
Tshaj tawm rau Twitter

Tam sim no, peb tab tom siv Python thiab tshaj tawm tweet!:) Koj yuav xav tau daim duab los tshaj tawm - xaiv ntse ntsuav.

Ua ntej, peb yuav tsum tau txais twitter API thiab rau qhov uas peb xav tau los tsim APP. Mus rau https://apps.twitter.com tsim daim ntawv thov tshiab.

Koj yuav tsum tau thov rau tus account tsim tawm - sau qee cov lus nug thiab paub meej tias koj tus email chaw nyob. Tom qab ntawd, koj yuav tuaj yeem tsim APP tshiab.

Tom qab tsim lub APP, mus rau Cov Keys thiab Tokens thiab Tsim Kev Nkag Nkag Nkag thiab nkag mus rau Token Secret. Ib lub qhov rai yuav pom nrog Cov YOOJ YIM TSHIAB nkaus xwb - Luam cov no thiab khaws lawv rau tom qab.

Siv cov cai hauv qab no los xa daim duab rau koj tus account twitter. Tsis txhob hnov qab sau:

  • tus neeg siv_key
  • neeg_secret
  • access_token
  • access_token_secret

twitter cov lus yog cov ntawv xa hauv tweet.

jpg_foto_to_send yog daim duab uas yuav muab txuas rau hauv tweet. Thov muaj qee daim duab nyob hauv phau ntawv teev npe ib yam li Python tsab ntawv thiab hloov lub npe hauv txoj cai.

ntshuam tweepy # Twitter teeb tsa def get_api (cfg): auth = tweepy. OAuthHandler (cfg ['consumer_key'], cfg ['consumer_secret']) auth.set_access_token (cfg ['access_token'], cfg ['access_token_secret']) rov qab tweepy. API (auth) # Xa rau twitter def sendToTwitter (): cfg = {"consumer_key": "", "consumer_secret": "", "access_token": "", "access_token_secret": ""} api = get_api (cfg) # Cov xwm txheej Xov xwm tweet = "Twitter message" xwm txheej = api.update_with_media ("jpg_foto_to_Send", tweet) xaToTwitter ()

Txheeb xyuas koj li Twitter pub rau koj li tweet.

Nov yog Tweet

Sau hauv qab no:

#RaspberryPI MagicBox. Siv cov duab, tshuaj xyuas lawv thiab xaiv xa lawv mus rau twitter thiab Facebook. Txhawb los ntawm Raspberry PI. @@ Raspberry_Pi#RaspberryPI#RaspberryPIProjectpic.twitter.com/cCL33Zjb8p

- Bruno Ricardo Santos (@feiticeir0) Lub Ob Hlis 29, 2020

Kauj Ruam 11: Ua ke Qee Yam

Ua ke qee Yam
Ua ke qee Yam
Ua ke qee Yam
Ua ke qee Yam

Tam sim no cia ua ke Loj Dome Push khawm, nias nws, suav sau, thaij duab, txiav txim siab seb puas yuav xa nws mus rau twitter.

Peb yuav ntxiv lwm daim duab thav duab thiab siv tag nrho peb lub khawm thawb. Thaum thaij duab, tag nrho 3 khawm LEDs yuav ci.

Peb ntxiv lwm daim duab, uas qhia cov cim rau tshaj tawm rau kev sib raug zoo network

SelectOption-p.webp

Aenviar-p.webp

Hauv cov vis dis aus tsis tau qhia lub khawm xiav (lub hauv ntej ntawm lub koob yees duab), tab sis LED tau qhib thiab nws pib ntsais muag sai li sai tau thaum nws nias.

Cov cai yog txuas yog tias koj xav tau

Nov yog qhov kev xeem zaum kawg ua ntej txoj haujlwm tseem ceeb.

# coding = utf-8 ntshuam picamera ntshuam _thread ntshuam subprocess li sp los ntawm lub sijhawm ntshuam pw los ntawm RPi ntshuam GPIO los ntawm PIL ntshuam duab ntshuam ntshuam # Twitter ntshuam tweepy # Facebook ntshuam facebook # Khawm kom thaij duab takeButton = 17 # SocialNetwork Khawm socialNetworkButton = 23 # Nthuav Tawm Daim Duab rho tawmButton = 24 # Siv daim duab khawm LED nqaPicButtonLed = 27 # Tshaj tawm rau Social Network khawm LED postSNLed = 22 # Tshem tawm khawm LED tshem tawm ButtonLed = 5 GPIO.setmode (GPIO. BCM) GPIO.setup (takeButton, GPIO. IN, GPIO. PUD_UP) GPIO.setup (socialNetworkButton, GPIO. IN, GPIO. PUD_UP) GPIO.setup (tshem tawm Button, GPIO. IN, GPIO. PUD_UP) GPIO.setup (takePicButtonLed, GPIO. OUT) GPIO.setup (postSNLed, GPIO. OUT) GPIO.setup (cancelButtonLed, GPIO. OUT) # Twitter teeb tsa def get_api (cfg): auth = tweepy. OAuthHandler (cfg ['consumer_key'], cfg ['consumer_secret']) auth.set_access_token (cfg ['access_token'], cfg ['access_token_secret']) rov tweepy. API (auth) # Xa mus rau twitter def sendToTwitter (): cfg = {"con sumer_key ":" "," consumer_secret ":" "," access_token ":" "," access_token_secret ":" "} api = get_api (cfg) # Status Message tweet =" MagicBox qhia paub ntsuas #MagicBox #RaspberryPI #Raspberry #Instructables "xwm txheej = api.update_with_media (" pushTesting.jpg ", tweet) #Facebook AOth def get_api_facebook (cfg): teeb = facebook. GraphAPI (cfg ['access_token']) #Tau txais nplooj ntawv token Koj tuaj yeem hla # cov hauv qab no yog tias koj xav tshaj tawm raws li koj tus kheej. resp = graph.get_object ('kuv/tus lej') page_access_token = Tsis muaj rau nplooj hauv resp ['cov ntaub ntawv']: yog nplooj ntawv ['id'] == cfg ['page_id']: page_access_token = page ['access_token'] graph = facebook. GraphAPI (page_access_token) rov teeb duab # Xa rau facebook def sendToFacebook (): # Tus nqi rau kev nkag mus cfg = {"page_id": "", "access_token": ""} api = get_api_facebook (cfg) kab lus = "Caption daim duab" albumid = "" api.put_photo (duab = qhib ("pushTesting.jpg", "rb"), kab lus = "Kab lus duab ") # Teeb tsuas yog TakePicButtonLed def onlyTakePicLed (): GPIO.output (takePicButtonLed, Tseeb) GPIO.output (postSNLed, False) GPIO.output (cancelButtonLed, False) # Lub teeb tsuas tso tseg thiab SocialNetwork khawm def cancelPostLEDS (): GPI O.output (takePicButtonLed, False) GPIO.output (postSNLed, True) GPIO.output (cancelButtonLed, True) # Tsaus muag duab LED thaum suav down def countingTimerPicture (): GPIO.output (takePicButtonLed, Tseeb) pw tsaug zog (0.5) GPIO.output (takePicButtonLed, False) pw (0.5) GPIO.output (takePicButtonLed, Tseeb) pw tsaug zog (0.5) GPIO.output (takePicButtonLed,Cuav) pw (0.5) GPIO.output (takePicButtonLed, Tseeb) pw (0.5) GPIO.output (takePicButtonLed, Cuav) # Blink postSNLed thaum tshaj tawm rau cov koom tes sib tham def blinkPosting (stop_event): # Pib thaum (tsis tsum_event.is_set ()): print ("off") GPIO.output (postSNLed, False) pw (0.5) print ("on") GPIO.output (postSNLed, True) pw (0.5) def timer (): GPIO.output (takePicButtonLed, Muaj tseeb) pw tsaug zog (1) GPIO.output (postSNLed, Tseeb) pw (1) GPIO.output (tshem tawm ButtonLed, Tseeb) pw tsaug zog (1) def showAllLeds (): GPIO.output (takePicButtonLed, Muaj tseeb) GPIO.output (postSNLed, Tseeb) GPIO.output (cancelButtonLed, True) # Tso saib ua ntej ntawm txheej 1 def displayPreview (imgName): # Txij li PIL cov duab pom yog qhov tsis zoo # peb siv cov duab los ntawm lub koob yees duab los tso saib # saib ua ntej img = Image.open (imgName) padding = Image.new ('RGB', (((img.size [0] + 31) // 32) * 32, ((img.size [1] + 15) // 16) * 16,)) padding.paste (img, (0, 0)) ov = camera.add_overlay (padding.tobytes (), loj = img.size) ov.layer = 1 # Tso saib ua ntej ntawm txheej 3 def displayPreview3 (imgName): # Txij li PIL cov duab qhia yog crapp # peb siv cov duab los ntawm lub koob yees duab los tso saib # saib ua ntej img = Image.open (imgName) padding = Image.new ('RGB', ((((img.size [0] + 31) // 32) * 32, ((img.size [1] + 15) // 16) * 16,)) padding.paste (img, (0, 0)) ov = camera.add_overlay (padding.tobytes (), loj = img.size) ov.alpha = 150 ov.layer = 3 rov ov # Muaj nuj nqi overlaySocialNetwork def overlaysn (): imgsn = Image.open ('SelectOption.png') # Tsim Overlay ncoo = Image.new ('RGB', (((imgsn.size [0] + 31) // 32) * 32, ((imgsn.size [1] + 15) // 16) * 16,)) # Muab cov ntaub qhwv tso rau saum. Paste (imgsn, (0, 0)) ov = camera.add_overlay (pad.tobytes (), qhov loj = imgsn.size) ov.alpha = 100 ov.layer = 3 rov ov # Muaj nuj nqi rau overlay duab def overlayCounter (): # thauj cov duab img1 = Image.open ('3.png') img2 = Image.open ('2.png') img3 = Image.open ('1.png') # Tsim kev thaub qab # Siv nrog img1 vim tias txhua tus yog qhov loj tib lub ncoo = Image.new ('RGB', (((img1.size [0] + 31) // 32) * 32) * 32, ((img1.size [1] + 15) // 16) * 16,)) # muab tshuaj txhuam rau - 3 pad.paste (img1, (0, 0)) ov = camera.add_overlay (pad.tobytes (), loj = img1.size) ov.alpha = 200 # txheej yog 3 vim lub koob yees duab saib ua ntej yog txheej 2 ov.layer = 3 pw tsaug zog (1) camera.remove_overlay (ov) # muab tshuaj txhuam tso rau - 2 pad.paste (img2, (0, 0)) ov = camera.add_overlay (pad.tobytes (), size = img2.size) ov.alpha = 200 # txheej yog 3 vim lub koob yees duab saib ua ntej yog txheej 2 ov.layer = 3 pw (1) camera.remove_overlay (ov) # muab tshuaj txhuam tus txheej - 1 pad.paste (img3, (0, 0)) ov = camera.add_overlay (pad.tobytes (), loj = img3.size) ov.alpha = 200 # txheej yog 3 vim lub koob yees duab saib ua ntej yog txheej 2 ov.layer = 3 pw tsaug zog (1) camera.remove_overlay (ov) # Lub luag haujlwm tseem ceeb # Ntshiab lub vijtsam kom cov lus khau raj tsis nyob tam sim no # tej zaum nws yuav zoo dua los ua qhov no hauv bash tmp = sp.call ('meej', plhaub = Tseeb) lub koob yees duab = picamera. PiCamera () camera.resolution = (1280, 1024) camera.framerate = 24 camera.brightness = 55 camera.sharpness = 0 camera.contrast = 0 #camera.exposure_co mpensation = 0 #camera.exposure_mode = 'auto' #camera.meter_mode = 'nruab nrab' #Xeem ntawm no sim: thaum (Tseeb): camera.start_preview () #Show LED Tsuas Yog Siv Duab nkaus xwbTakePicLed () #Tos kom khawm coj Daim duab GPIO.wait_for_edge (takeButton, GPIO. FALLING) # Pib xov los suav nrog cov LEDs thaum cov duab pom # Tej zaum tuaj yeem siv tau rau hauv kev ua haujlwm suav tus lej, # vim tias nws tseem muaj timers los qhia cov duab, tab sis coj cov teebmeem yuav tsis zoo ib yam _thread.start_new_thread (suavTimerPicture, ()) # Qhia cov duab nyob hauv lub koob yees duab daim duab overlayCounter () # Qhia tag nrho LEDS thaum siv daim duab showAllLeds () camera.capture ('pushTesting.jpg') lub koob yees duab. stop_preview () #display duab displayPreview ('pushTesting.jpg') # Qhia overlay oo = overlaysn () # Qhia LEDs kom thim lossis Tshaj Tawm rau Social Networks cancelPostLEDS () GPIO.add_event_detect (socialNetworkButton, GPIO. FALLING) GPIO.add_event_detect (tshem tawm), GPIO. FALLING) thaum (Muaj tseeb): yog GPIO.event_detecte d (socialNetworkButton): camera.remove_overlay (oo) GPIO.output (cancelButtonLed, False) o = displayPreview3 ('Aenviar.png') #print "Social Networks Button" sendToTwitter () sendToFacebook () camera.remove_overlay (o) so if GPIO.event_detected (cancelButton): #print "Canceled" camera.remove_overlay (oo) so # reset GPIOS GPIO.remove_event_detect (socialNetworkButton) GPIO.remove_event_detect (cancelButton) GPIO.remove_event_detect (takeButton) lub koob yees duab. "Tawm …") #offLeds () GPIO.cleanup ()

Kauj Ruam 12: Txuas kab

Image
Image
Thaiv
Thaiv
Thaiv
Thaiv

Cov xov hlau tsuas yog txuas lub Dome Loj Push khawm mus rau Raspberry PI.

Tsuas yog ua raws Fritzing Schematic.

Cov kev sib txuas yog:

ConnectionRPI GPIO PIN GND Green Push ButtonGND (#3) GND Yellow Push ButtonGND (#9) GND Blue Push ButtonGND (#39) Coj Duab (Blue Push Button "Push to make") 17 (BCM) Tshaj Tawm rau Social Networks (Green Push Khawm "Push to make") 23 (BCM) Cancel (Yellow Push Button "Push to make") 24 (BCM) Blue Push button LED27 (BCM) Green Push button LED22 (BCM) Yellow Push button LED5 (BCM)

Cov cua sov kuj tseem yog xim xim

  • Dub yog GND kev sib txuas
  • Daj yog "thawb kom" sib txuas
  • Xiav yog LED sib txuas

GPIO. BCM tus lej vs GPIO. BOARD kev sib txuas

Txij li thaum kuv kev sib txuas yog BCM, Kuv xav tias tam sim no yog lub sijhawm zoo los tham txog nws thiab qhov sib txawv ntawm BCM thiab BOARD.

Qhov sib txawv tseem ceeb yog koj xa mus rau GPIO PINs li cas, uas nyob rau hauv lem yuav tsav koj li kev sib txuas. GPIO.board yuav xa tus lej PIN los ntawm tus lej luam tawm ntawm txhua qhov txheej txheem GPIO hauv internet.

GPIO. BCM hais txog tus lej PIN raws li Broadcom SOC pom lawv. Qhov no zoo li yuav hloov pauv qhov tshiab ntawm Raspberry PI.

Ntawm tus pinout.xyz qhov chaw, cov lej lej yog tus uas nyob ib sab ntawm tus pin thiab BCM tau hais rov zoo li ntawd - BCM X (qhov twg X yog tus lej)

Kauj ruam 13: MagicBox

Cov lej txuas nrog rau cov kauj ruam no yog qhov kawg.

Koj tuaj yeem khiav nws ntawm raspberry PI khau raj, tsis tas yuav xav tau tus ID nkag mus. Txhawm rau ua qhov ntawd, tsuas yog tsim cov ntawv me me hauv cov npe uas koj tau tso cai - hloov txoj hauv kev raws li

#!/bin/tsoo

cd/tsev/pi/magicbox nab hab sej MagicBox.py

Ua kom nws executable

chmod +x start_magicbox.sh

Tam sim no, hu nws hauv /etc/rc.local, tsuas yog ua ntej qhov kev tawm 0 instuction

sudo vi /etc/rc.local

/home/pi/magicbox/start_magicbox.sh &

txuag thiab tawm mus.

Tam sim no, nrog txhua qhov rov pib dua, Python program yuav ua tiav

NCO TSEG: Txhua daim duab duab yuav tsum nyob hauv tib phau ntawv raws li tsab ntawv. Koj yuav tsum muaj:

  • 1-p.webp" />
  • 2-p.webp" />
  • 3. pwg
  • Aenviar.png
  • SelectOption.png

Koj tuaj yeem tau txais tag nrho cov ntaub ntawv no ntawm MagicBox's github.

Pom zoo: