GPIO: zonse zokhudzana ndi Raspberry Pi 4 ndi 3 yolumikizana

Rasipiberi Pi 4 GPIO

ndi Zikhomo za GPIO za board ya Raspberry Pi 4, 3, komanso omwe adatsogola, amapatsa bolodi la SBC maluso ofanana ndi omwe Arduino angakhale nawo, popeza ndi iwo mutha kupanga mapulogalamu osangalatsa amagetsi olamulidwa kuchokera ku makina ogwiritsira ntchito pogwiritsa ntchito manambala azilankhulo zosiyanasiyana, monga Python.

Izi zimapangitsa kuti board azingokhala makompyuta otsika mtengo. Ikuthandizani kuti mugwirizane ndi zinthu zamagetsi zomwe mungagwiritse ntchito ndi Arduino, koma zomwe zingathenso kuyang'aniridwa kuchokera ku Pi. Mu bukhuli ndikuyesera kukupatsani zambiri zazomwe zingachitike pa zikhomo za GPIO kuti muthe kugwiritsa ntchito mwayi wawo ...

Kodi GPIO ndi chiyani?

GPIO

GPIO ndilo dzina la General Purpose Input / Output, ndiko kuti, General Purpose Input / Output. Zida zamagetsi zosiyanasiyana zimatha kukhala nazo, monga tchipisi tokha kapena ma board ena a PCB monga Raspberry Pi iyi. Monga momwe dzinali likusonyezera, ndi zikhomo zomwe zimatha kukhazikitsidwa kuti zizigwira ntchito zosiyanasiyana, chifukwa chake ndizofunikira osati zongogwiritsa ntchito.

Adzakhala wogwiritsa ntchito nthawi yothamanga yemwe angathe konzani zikhomo za GPIO izi kuti achite zomwe akufuna. Zitha kuchitidwa mosiyanasiyana, monga ma code ena kapena zolembedwa kuchokera ku kontrakitala kapena pulogalamu ya Python, yomwe ndi imodzi mwanjira zosavuta komanso zosankhidwa kwambiri chifukwa cha kuchuluka kwa zomwe mungasankhe.

Mwanjira iyi, Rasipiberi Pi sikuti imangokhala ndi madoko angapo komanso mawonekedwe kuti mugwirizane ndi zida zingapo, koma onjezani zikhomo za GPIO kuti muthe kuwonjezera zida zina zamagetsi kapena mapulani omwe mudadzipanga nokha. Momwemonso momwe mungachitire ndi Arduino ndi zikhomo zake za I / O zowongolera.

Y osati kokha kwa Arduino kapena Raspberry Pi, momwemonso matabwa ena ofanana a SBC ndi zinthu zophatikizidwa.

Ntchito za GPIO

Ndipo pakati MAKHALIDWE ake chopambana:

  • Iwo akhoza kukhazikitsidwa mochuluka monga zolowetsera monga zotulutsa. Ali ndi mawonekedwe awiriwa monga zimachitikira kwa Arduino.
  • Zikhomo za GPIO nazonso itha kuyambitsidwa ndikuzimitsa ndi code. Ndiye kuti, amatha kukhazikitsidwa ku 1 (high voltage level) kapena 0 (low voltage level).
  • Inde angathe werengani zosankha za binary, monga omwe ndi maziro, ndiye kuti, ma voltage kapena kusakhalapo.
  • Zotsatira za Kuwerenga ndi kulemba.
  • Zowonjezera zitha kukhazikitsidwa nthawi zina monga zochitika kotero kuti apange mtundu wina wa zochita pa bolodi kapena dongosolo. Machitidwe ena ophatikizidwa amawagwiritsa ntchito ngati ma IRQ. Mulandu wina ndikukhazikitsa kuti pini imodzi kapena zingapo zikamagwira ntchito ndi masensa ena, chitani kanthu ...
  • Ponena zamagetsi ndi mphamvu yake, muyenera kudziwa bwino mphamvu zomwe bolodi ili nayo, pankhaniyi Raspberry Pi 4 kapena 3. Simuyenera kuwadutsa kuti musawawononge.

Mwa njira, pamene gulu la zikhomo za GPIO liphatikizidwa, monga momwe ziliri ndi Raspberry Pi, gululi limadziwika kuti Doko la GPIO.

Zikhomo za GPIO za Raspberry Pi

Rasipiberi Pi GPIO

Chiwembu chovomerezeka pamtundu wa 4, 3, Zero

Watsopano Mabungwe a rasipiberi Pi 4 ndi mtundu 3 Amakhala ndi zikhomo zambiri za GPIO. Osati matembenuzidwe onse amapereka ndalama zofanana, kapena kuwerengedwa chimodzimodzi, chifukwa chake muyenera kusamala ndi izi kuti mudziwe momwe mungalumikizire molingana ndi mtundu komanso kukonzanso komwe muli nako.

Koma chomwe chiri generic ndi mitundu ya GPIO yomwe mungapeze padoko la Raspberry Pi board. Ndipo icho chidzakhala chinthu choyamba ndikufuna kufotokoza, chifukwa ndi momwe mudzadziwire mitundu ya zikhomo mutha kudalira ntchito zanu:

  • ChakudyaZipini izi zimagwiritsidwa ntchito kulumikiza zingwe zamagetsi kapena zingwe zama projekiti anu amagetsi. Amayenderana ndi zikhomo zofanana ndi zomwe zili pa board ya Arduino, zomwe zimapereka ma voltages a 5v ndi 3v3 (3.3v ochepa 50mA katundu). Kuphatikiza apo, mupezanso zapansi (GND kapena Ground). Ngati simugwiritsa ntchito magetsi akunja monga mabatire, kapena ma adapter, zikhomo izi zitha kukuthandizani kuyendetsa dera lanu.
  • DNC (Osalumikiza): ndi zikhomo zomwe zili mumitundu ina zomwe sizigwira ntchito, koma kuti m'mabungwe atsopano apatsidwa cholinga china. Mudzapeza izi mumitundu yakale ya Pi. Mu 3 ndi 4 yatsopano adzalembedwa kuti ndi GND ambiri, kutha kuphatikizika mgululi.
  • Zipini zosinthika: Ndiwo ma GPIO abwinobwino, ndipo amatha kusinthidwa ndi ma code monga ndikufotokozereni pambuyo pake kuti muchite zomwe mukufuna.
  • Zipini zapadera: Awa ndi maulalo ena omwe amapangidwira kulumikizana kwapadera kapena polumikizira monga UART, TXD ndi RXD serial, etc., monga zimachitikira ndi Arduino. Mutha kupeza ena ngati SDA, SCL, MOSI, MISO, SCLK, CE0, CE1, ndi zina zambiri. Amadziwika pakati pawo:
    • PWM, yomwe imatha kuwongolera kukula kwazomwe zimachitika m'nkhani yapita. Pa Raspberry Pi 3 ndi 4 iwo ndi GPIO12, GPIO13, GPIO18 ndi GPIO19.
    • SPI ndi njira ina yolumikizirana yomwe ndidakambirananso m'nkhani ina. Pankhani yama board atsopano a 40-pini, ndiye zikhomo (zokhala ndi njira zosiyanasiyana zolumikizirana monga mukuwonera):
      • SPI0: MOSI (GPIO10), MISO (GPIO9), SCLK (GPIO11), CE0 (GPIO8), CE1 (GPIO7)
      • SPI1: MOSI (GPIO20); MISO (GPIO19); SCLK (GPIO21); CE0 (GPIO18); CE1 (GPIO17); CE2 (GPIO16)
    • I2C ndi kulumikizana kwina komwe ndafotokozanso mu blog iyi. Basi iyi ili ndi chizindikiritso cha data (GPIO2) ndi wotchi (GPIO3). Kuphatikiza pa EEPROM Data (GPIO0) ndi EEPROM Clock (GPIO1).
    • Siriyo, kulumikizana kwina kothandiza kwambiri ndi zikhomo za TX (GPIO14) ndi RX (GPIO15) ngati zomwe mungapeze pa bolodi Arduino UNO.

Kumbukirani kuti ma GPIO ndiwo mawonekedwe pakati pa Raspberry Pi ndi akunja, koma ali nawo zofooka zake, makamaka magetsi. China chake chomwe muyenera kukumbukira kuti musawononge bolodi ndikukumbukira kuti zikhomo za GPIO nthawi zambiri zimakhala zopanda mabulogu, ndiye kuti, popanda chosungira. Izi zikutanthauza kuti alibe chitetezo, chifukwa chake muyenera kuwunika kukula kwa mphamvu yamagetsi ndi mphamvu yake kuti musamalize ndi mbale yopanda pake ...

Kusiyana kwa GPIO pakati pamitundu

Zipini zakale za Raspberry Pi GPIO

Monga ndidanenera, si mitundu yonse yomwe ili ndi zikhomo zofananaNayi zithunzi kuti muwone kusiyana pakati pa mitundu ndipo mutha kuyang'ana pa Raspberry Pi 4 ndi 3, zomwe ndi zatsopano kwambiri komanso zomwe mwina muli nazo. Zimasiyana pakati (gulu lililonse limagawana zikhomo zofananira):

  • Rasipiberi Pi 1 Model B Rev 1.0, yokhala ndi ma pini 26 mosiyana pang'ono ndi Rev2.
  • Rasipiberi Pi 1 Model A ndi B Rev 2.0, onse awiri okhala ndi pini 26.
  • Rapsberry Pi Model A +, B +, 2B, 3B, 3B +, Zero ndi Zero W, komanso mitundu ya 4. Onsewa ali ndi mutu wa 40-pini wa GPIO.

Kodi ndingalowe chiyani mu ma GPIO?

Chipewa cha rasipiberi

Simungathe kutero polumikiza zida zamagetsi Como Zojambulajambula, chinyezi / masensa otentha, otentha, magalimoto oyendetsa, LEDs, etc. Muthanso kulumikiza zigawo kapena ma module omwe amapangidwira Rasipiberi Pi ndikukulitsa kuthekera kwa bolodi kupitilira zomwe zili pamunsi.

Ndikunena za otchuka zipewa kapena zipewa ndi mbale zomwe mungapeze pamsika. Pali mitundu yambiri, kuyambira yomwe imagwiritsidwa ntchito kuwongolera ma mota ndi ma driver, kupita kwa ena kuti apange gulu lowerengerandi Gulu la LED controllable, kuwonjezera Kutha kwa TV ya DVB, Chophimba cha LCD, Ndi zina zotero.

Zipewa kapena zipewa Amayikidwa pa bolodi la Raspberry Pi, kufanana ndi ma GPIO omwe amafunikira kuti igwire ntchito. Chifukwa chake, msonkhano wake ndi wosavuta komanso wachangu. Zachidziwikire, onetsetsani mtundu wa mbale wogwirizana ndi chipewa chilichonse, popeza doko la GPIO ndi losiyana ndi momwe mwawonera ...

Ndikunena izi ngati muli ndi mbale yakale, popeza zipewa zili n'zogwirizana okha atsopano. Monga mitundu ya Raspberry Pi Model A +, B +, 2, 3, ndi 4.

Kuyamba kugwiritsa ntchito GPIO pa Raspberry Pi

Sakani lamulo lotulutsa

Source: Rasipiberi Pi

Kuti muyambe, pa Raspbian, mutha kutsegula kontrakitala ndikuyimira lamulo pepalaZomwe zidzabwerenso kwa inu ndi chithunzi mu terminal ndi zikhomo za GPIO zomwe zilipo pa bolodi lanu ndi zomwe aliyense akufuna. China chake chothandiza kwambiri kuti muzikhala nacho nthawi zonse pantchito kuti musasokonezeke.

Ntchito yoyamba: kuwunikira ma LED ndi ma GPIO

GPIO yokhala ndi LED pa Rasipiberi Pi

Njira yofunikira kwambiri yopangira mtundu wa "Moni dziko" ndi ma GPIO ndikugwiritsa ntchito LED yosavuta yolumikizidwa ndi zikhomo za Raspberry Pi kuti muwone momwe amagwirira ntchito. Poterepa, ndalumikiza ku GND ndipo inayo kuti ikanike 17, ngakhale mutha kusankha zikhomo zina ...

Mukalumikiza, mutha muwalamulire ku Raspbian kugwiritsa ntchito osachiritsika. Mu Linux, mafayilo enieni amagwiritsidwa ntchito ngati omwe ali mu / sys / class / gpio / directory. Mwachitsanzo, kupanga fayilo yokhala ndi zofunikira kuti muyambe kugwira ntchito:

echo 17 > /sys/class/gpio/export

Ndiye mutha sintha monga cholowetsera (mu) kapena ngati chotulutsa (kunja) pini 17 wosankhidwa chitsanzo chathu. Mutha kuzichita mosavuta ndi:

echo out > /sys/class/gpio/gpio17/direction

Pachifukwa ichi ngati chotulutsa, popeza tikufuna kutumiza magetsi ku LED kuti ayatse, koma ngati inali sensa, ndi zina zambiri, mutha kugwiritsa ntchito. Tsopano kwa kuyatsa (1) kapena kuzimitsa (0) LED yomwe mungagwiritse ntchito:

echo 1 > /sys/class/gpio/gpio17/value
echo 0 > /sys/class/gpio/gpio17/value

Ngati mukufuna kupita kuntchito ina ndipo winawake kulowa kulengedwa, mutha kuzichita motere:

echo 17 > /sys/class/gpio/unexport

Mwa njira, mutha kusonkhanitsanso malamulo onse oyenera pulojekiti yanu, monga onse akale, sungani mu fayilo bash script ndiyeno muziwongolera m'matumba onse nthawi imodzi, m'malo mozilemba chimodzi ndi chimodzi. Izi ndizothandiza mukamabwereza zochitika zomwezo nthawi zambiri, chifukwa chake simuyenera kulembanso. Ingothamangani ndikupita. Mwachitsanzo:

nano led.sh

#!/bin/bash
source gpio 
gpio mode 17 out
while true; do 
gpio write 17 1 
sleep 1.3 
gpio write 17 0 
sleep 1.3 done

Mukangomaliza, mumasunga kenako mutha kuzipatsa yoyenera ndikuchita zilolezo script kuti kuyatsa kuyatsegule, dikirani masekondi 1.3 ndikuzimitsa motere ...

chmod +x led.sh
./led.sh

Mapulogalamu patsogolo

pulogalamu yoyambira chilankhulo

Zachidziwikire kuti zomwe zili pamwambazi zimagwirira ntchito zamagetsi zazing'ono zopangidwa ndi zinthu zochepa, koma ngati mukufuna kupanga china chopita patsogolo, m'malo mwa malamulo, zomwe mungagwiritse ntchito ndi izi zinenero zolumikiza kupanga zolemba zosiyanasiyana kapena manambala achinsinsi omwe amayendetsa ntchitoyo.

Zitha kugwiritsidwa ntchito zipangizo zosiyanasiyana pulogalamu, ndi zilankhulo zosiyanasiyana. Malaibulale omwe anthu ammudzi apanga amatipangitsa kukhala kosavuta kwa inu, monga WiringPi, sysfs, pigpio, ndi zina zambiri. Mapulogalamuwa akhoza kukhala osiyanasiyana, kuchokera ku Python, yomwe ndi njira yomwe ambiri amakonda, kudzera mu Ruby, Java, Perl, BASIC, ngakhale C #.

Mwalamulo, Raspberry Pi imakupatsirani malo ambiri kukonza ma GPIO anu, monga:

  • Sakani, kwa iwo omwe sakudziwa kupanga pulogalamu ndipo akufuna kugwiritsa ntchito zovuta za ntchitoyi yomwe Arduino imatha kupangidwanso, ndi zina zambiri. Kupanga mapulogalamu okhala ndi zithunzi ndizabwino kwambiri komanso kothandiza pantchito zamaphunziro.
  • Python: Chilankhulo chamasulira chosavuta ichi chimakupatsani mwayi wopanga ma code osavuta komanso amphamvu, ndi malaibulale ambiri omwe mungathe kuchita pafupifupi chilichonse chomwe mukuganiza.
  • C / C ++ / C #: ndi zilankhulo zamphamvu kwambiri zopanga mapulogalamu kuti azitha kulumikizana ndi ma GPIO. Mutha kuzichita m'njira zingapo, pogwiritsa ntchito mawonekedwe wamba kapena mawonekedwe amtundu kudzera pa librarywachiwiri, komanso kudzera mu laibulale ya chipani chachitatu monga nkhumba.
  • Kufufuza3, ofanana ndi Arduino.

Sankhani mosavuta amene mumamukonda kwambiri kapena mukuganiza kuti ndi yosavuta.


Zomwe zili m'nkhaniyi zikutsatira mfundo zathu za malamulo okonzekera. Kuti mufotokoze cholakwika dinani Apa.

Khalani oyamba kuyankha

Siyani ndemanga yanu

Anu email sati lofalitsidwa. Amafuna minda amalembedwa ndi *

*

*

  1. Wotsogolera pazosankhazi: Miguel Ángel Gatón
  2. Cholinga cha deta: Control SPAM, kasamalidwe ka ndemanga.
  3. Kukhazikitsa: Kuvomereza kwanu
  4. Kulumikizana kwa zomwe zafotokozedwazo: Zomwezo siziziwululidwa kwa anthu ena kupatula pakukakamizidwa mwalamulo.
  5. Zosunga: Zosungidwa ndi Occentus Networks (EU)
  6. Ufulu: Nthawi iliyonse mutha kuchepetsa, kuchira ndikuchotsa zidziwitso zanu.