GPIO: duk game da Rasberi Pi 4 da haɗin 3

Rasberi Pi 4 GPIO

da GPIO fil na Rasberi Pi 4 allon, da 3, da kuma wadanda suka gabace shi, suna ba kwamitin SBC ƙwarewa irin waɗanda Arduino zai iya samu, tunda tare da su zaku iya ƙirƙirar ayyukan lantarki masu ban sha'awa waɗanda ake sarrafawa daga tsarin aiki ta hanyar lamba a cikin yare daban-daban, kamar Python.

Wannan ya sa kwamitin ya fi kawai kwamfutar mai arha. Zai ba ka damar haɗa ɗimbin abubuwan lantarki cewa zaku iya amfani dashi tare da Arduino, amma kuma ana iya sarrafa shi daga Pi. A cikin wannan jagorar zan yi kokarin baku cikakken bayani gwargwadon iko game da waɗannan fil ɗin GPIO don ku fara cin amfanin su ...

Menene GPIO?

GPIO

GPIO shi ne ainahin ma'anar General Purput Input / Output, wato, General Purpose Input / Output. Daban-daban kayan lantarki zasu iya samun sa, kamar su kwakwalwan kansu ko wasu allon PCB kamar wannan Rasberi Pi. Kamar yadda sunan su ya nuna, su ne fil waɗanda za a iya saita su don yin ayyuka daban-daban, saboda haka sun kasance manufa ce gaba ɗaya ba don takamaiman amfani ba.

Zai zama mai amfani a lokacin gudu wanda zai iya saita waɗannan fil ɗin GPIO domin su aikata abin da yake so. Ana iya yin sa ta hanyoyi daban-daban, kamar tare da wasu lambobi ko rubutu daga na'ura mai kwakwalwa ko kuma tare da shirin Python, wanda shine ɗayan mafi sauƙi kuma mafi fifikon hanyoyi saboda yawan zaɓuɓɓukan da kuke da su.

Ta wannan hanyar, Rasberi Pi ba kawai yana da tashar tashar jiragen ruwa kawai ba kuma musaya don haɗa na'urori masu daidaitattun abubuwa, amma ƙara waɗannan fil ɗin GPIO don haka zaku iya ƙara wasu na'urorin lantarki ko ayyukan maƙerin da kuka ƙirƙira da kanku. Kamar yadda zaku yi tare da Arduino da maɓallan I / O don sarrafawa.

Y ba keɓaɓɓe ga Arduino ko Rasberi Pi ba, haka ma sauran kwatancen SBC masu kama da kayayyakin sakawa.

Ayyukan GPIO

Kuma tsakanin ta HALAYE mafi fice:

  • Za su iya a saita sosai azaman shigarwa azaman fitarwa. Bã su da wancan duality kamar yadda ya faru da waɗanda na Arduino.
  • GPIO fil ma za a iya kunna da kashe ta lambar. Wato, ana iya saita su zuwa 1 (matakin ƙarfin lantarki mai ƙarfi) ko 0 (ƙananan ƙarfin wuta).
  • Tabbas zasu iya karanta bayanan binary, a matsayin su da sifiri, ma’ana, siginar lantarki ko rashin sa.
  • Fitarwa dabi'u na Karatu da rubutu.
  • Ana iya saita ƙididdigar shigarwar a wasu lokuta kamar abubuwan da suka faru don haka suna samar da wani nau'in aiki a kan allo ko tsarin. Wasu tsarin da aka saka suna amfani dasu azaman IRQs. Wata shari'ar ita ce saita lokacin da ɗaya ko fiye fil ke aiki da wasu na'urori masu auna firikwensin, yi wasu ayyuka ...
  • Game da ƙarfin lantarki da ƙarfi, dole ne ku san iyakar ƙarfin da za a yarda da shi a hukumar, a wannan yanayin Rasberi Pi 4 ko 3. Bai kamata ku wuce su ba don kauce wa lalata shi.

Af, yayin da aka haɗa rukuni na GPIO fil, kamar yadda lamarin yake tare da Rasberi Pi, ana kiran ƙungiyar da GPIO tashar jiragen ruwa.

GPIO din fil na Rasberi Pi

Rasberi Pi GPIO

Tsarin aiki mai inganci don sigar 4, 3, Zero

Sabon Rasberi Pi 4 allon da sigar 3 An sanye su da babban adon GPIO. Ba duk sigar ke ba da adadin daidai ba, kuma ba a ƙidaya su a hanya guda, saboda haka dole ne ku yi hankali da wannan don sanin yadda ya kamata ku haɗa haɗin gwargwadon samfurin da bita da kuke da su.

Amma abin da ya fi dacewa shine nau'ikan GPIO da zaku iya samu a tashar jiragen ruwan Rasberi Pi. Kuma wannan shine farkon abinda zan so bayyana, tunda hakane zaku sani nau'ikan fil zaku iya dogara ga ayyukanku:

  • AbincinAna amfani da waɗannan fil ɗin don haɗa layin wutar lantarki ko wayoyi don ayyukan lantarki. Sun dace da fil kamar irin waɗanda suke a kan jirgin Arduino, kuma hakan yana samar da ƙananan ƙarfi na 5v da 3v3 (3.3v an iyakance ga kaya 50mA). Kari akan haka, zaka kuma sami wadanda ke kasa (GND ko Ground). Idan baku yi amfani da tushen wutan lantarki na waje kamar batura, ko adaftan ba, waɗannan fil ɗin na iya zama babban taimako don ƙarfafa da'irar ku.
  • DNC (Kada a Haɗa): su fil ne waɗanda suke a wasu sifofin kuma basu da aiki, amma cewa a cikin sabon allon an basu wata manufa. Waɗannan kawai zaku same su a cikin samfuran zamani na Pi. A cikin sabon 3 da 4 za'a sanya musu alama a matsayin GND gaba ɗaya, suna iya haɗa kai a cikin ƙungiyar da ta gabata.
  • Configurable fil: Su GPIOs ne na al'ada, kuma ana iya tsara su ta hanyar lambobin kamar yadda zan yi bayani nan gaba don yin abin da kuke buƙata.
  • Musamman fil: waɗannan wasu haɗin ne waɗanda aka yi niyya don haɗi na musamman ko musaya kamar UART, TXD da RXD haɗin kai, da sauransu, kamar yadda yake faruwa da Arduino. Har ma zaka samu wasu kamar SDA, SCL, MOSI, MISO, SCLK, CE0, CE1, da sauransu. Sun yi fice a tsakanin su:
    • PWM, wanda zai iya daidaita faɗin bugun jini kamar yadda muka gani a cikin labarin da ya gabata. A kan Rasberi Pi 3 da 4 sune GPIO12, GPIO13, GPIO18 da GPIO19.
    • SPI wata hanyar sadarwa ce wacce ni ma na tattauna a cikin wani labarin. Game da sabbin allon-pin 40, su ne fil (tare da hanyoyin sadarwa daban-daban kamar yadda kake gani):
      • 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 wani haɗin ne wanda na kuma bayyana a cikin wannan shafin. Wannan motar bas din ta kunshi siginar bayanai (GPIO2) da agogo (GPIO3). Baya ga EEPROM Data (GPIO0) da EEPROM Clock (GPIO1).
    • Serial, wata hanyar sadarwa mai amfani tare da TX (GPIO14) da RX (GPIO15) fil kamar waɗanda zaku iya samu akan jirgin Arduino UNO.

Ka tuna cewa GPIOs shine haɗin tsakanin Rasberi Pi da duniyar waje, amma suna da iyakokinta, musamman wutar lantarki. Wani abu da yakamata kuyi la'akari dashi don kada ku lalata allon shine ku tuna cewa waɗannan fil ɗin GPIO galibi ba buɓfighter ne, ma'ana, ba tare da yin ajiya ba. Wannan yana nufin cewa basu da kariya, saboda haka dole ne ku lura da girman ƙarfin lantarki da ƙarfin da aka yi amfani da shi don kar ku ƙare da farantin da ba shi da amfani ...

Bambancin GPIO tsakanin siga

Tsohon Rasberi Pi GPIO fil

Kamar yadda na ce, ba duk samfuri iri ɗaya baneAnan akwai wasu zane-zane don haka zaku iya ganin bambance-bambance tsakanin samfuran kuma don haka ku sami damar mai da hankali kan Rasberi Pi 4 da 3, waɗanda sune sababbi kuma wanda wataƙila kuke da shi a cikin mallakar ku. Ya bambanta tsakanin (kowane ɗayan ƙungiya yana raba fil ɗaya):

  • Rasberi Pi 1 Model B Rev 1.0, tare da 26-pin dan bambanci da Rev2.
  • Rasberi Pi 1 Model A da B Rev 2.0, duka samfuran suna da 26-pin.
  • Rapsberry Pi Model A +, B +, 2B, 3B, 3B +, Zero da Zero W, da kuma samfura 4. Dukansu suna da maɓallin GPIO mai pin 40.

Me zan iya toshewa a cikin GPIOs?

Rasberi Pi hat

Ba za ku iya kawai ba haɗa na'urorin lantarki kamar yadda transistors, na'urori masu auna zafi / zafin jiki, masanan wuta, stepper Motors, LEDs, da dai sauransu Hakanan zaka iya haɗa abubuwan haɗin ko kayayyaki waɗanda aka kirkira musamman don Rasberi Pi kuma hakan yana faɗaɗa ƙarfin allon fiye da abin da aka haɗa a cikin tushe.

Ina nufin shahararren huluna ko huluna da faranti da zaka iya samu a kasuwa. Akwai nau'ikan da yawa, daga waɗanda ake amfani da su don sarrafa motoci tare da direbobi, zuwa wasu don ƙirƙirar gungu mai sarrafa kwamfutatare da LED panel mai sarrafawa, don ƙarawa DVB TV iyawa, LCD allo, Da dai sauransu

Waɗannan hulunan ko hulunan An saka su a kan jirgin Rasberi Pi, daidai da GPIOs da ake buƙata don aiki. Saboda haka, taronta yana da sauki da sauri. Tabbas, tabbatar da samfurin farantin wanda ya dace da kowane hat, tunda tashar GPIO ta bambanta kamar yadda kuka gani ...

Nace wannan idan har kuna da wani tsohon kwano, tunda huluna suna dace kawai da sabuwar. Kamar yadda samfurin Rasberi Pi Model A +, B +, 2, 3, da 4 suke.

Gabatarwa don amfani da GPIO akan Rasberi Pi

Fitowar umarnin Pinout

Source: Rasberi Pi

Don farawa, akan Raspbian, zaka iya buɗe na'urar wasan ka buga umarni kurajeAbin da zai dawo gare ku hoto ne a cikin tashar tare da GPIO fil ɗin da ake samu akan allon ku kuma abin da kowannensu yake don shi. Wani abu mai matukar amfani koyaushe ya gabatar dashi a lokacin aiki saboda kar ku rude.

Aikin farko: walƙiya LED tare da GPIOs

GPIO tare da LED akan Rasberi Pi

Hanya mafi mahimmanci don yin nau'in "Sannu duniya" tare da GPIOs shine a yi amfani da LED mai sauki wanda aka hada shi da fil din Rasberi Pi dan haka zaka ga yadda suke aiki. A wannan yanayin, na haɗa shi zuwa GND da ɗayan don zura 17, kodayake zaku iya zaɓar wani daga cikin al'amuran yau da kullun ...

Da zarar an haɗa ka, za ka iya sarrafa su daga Raspbian yin amfani da m. A cikin Linux, ana amfani da takamaiman fayiloli kamar waɗanda suke cikin / sys / class / gpio / directory. Misali, don ƙirƙirar fayil tare da tsarin da ya dace don fara aiki:

echo 17 > /sys/class/gpio/export

Sannan zaka iya saita azaman shigarwa (a) ko azaman fitarwa (fita) lambar 17 da aka zaba don misalinmu. Kuna iya yin saukinsa tare da:

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

A wannan yanayin azaman fitarwa, tunda muna son aika bugun lantarki zuwa LED don kunna shi, amma idan firikwensin ne, da sauransu, kuna iya amfani da shi. Yanzu don kunna (1) ko kashe (0) LED ɗin da zaka iya amfani da shi:

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

Idan kanaso ka matsa zuwa wani aikin kuma share shigarwa halitta, zaka iya yin ta wannan hanya:

echo 17 > /sys/class/gpio/unexport

Af, zaku iya tattara duk umarnin da ake buƙata don aikin ku, kamar duk waɗanda suka gabata, adana su cikin nau'in fayil bash rubutun sannan a kwashe su a dunkule gaba daya, maimakon buga su daya bayan daya. Wannan yana da amfani yayin da kuka maimaita wannan aikin sau da yawa, don haka ba lallai bane ku sake rubutawa. Kawai gudu ka tafi. Misali:

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

Da zarar kun gama, kun adana sannan kuma kuna iya ba shi dacewar aiwatarwa da aiwatar da izini rubutun don LED ya kunna, jira sakan 1.3 ya kashe kamar haka a madauki ...

chmod +x led.sh
./led.sh

Ci gaban shiri

lambar tushe na shirye-shirye

Babu shakka abubuwan da ke sama suna aiki ne don ƙananan ayyukan lantarki tare da componentsan abubuwan da aka haɗa, amma idan kuna son ƙirƙirar wani abu mai ci gaba, maimakon umarnin, abin da zaku iya amfani da shi harsuna shirye-shirye don yin rubutun daban-daban ko lambobin tushe waɗanda ke sarrafa aikin.

Ana iya amfani da su daban-daban kayan aiki don shirin, tare da yare daban-daban. Dakunan karatun da al'umma suka kirkira sun sauwaka maka abubuwa, kamar su WiringPi, sysfs, pigpio, da sauransu. Shirye-shiryen na iya zama da bambamcin gaske, daga Python, wanda shine mafi fifiko zaɓi ga mutane da yawa, ta hanyar Ruby, Java, Perl, BASIC, har ma da C #.

A bisa hukuma, Rasberi Pi yana ba ku wurare da yawa don shirya GPIOs ɗinku, kamar:

  • Tashi, ga wadanda basu san yadda ake shiryawa ba kuma suke son amfani da tubalin wannan aikin wanda Arduino shima za'a iya tsara shi, da sauransu. Shiryawa tare da zane-zanen hoto yana da mahimmanci kuma yana da amfani sosai ga fagen ilimi.
  • Python: Wannan harshe mai sauƙin fassara shirye-shirye yana ba ku damar ƙirƙirar lambobi masu sauƙi da ƙarfi, tare da ɗakunan karatu da yawa a hannunku don aiwatar da kusan duk abin da kuke tsammani.
  • C / C ++ / C #: sun fi ƙarfin yarukan shirye-shirye don ƙirƙirar binaries waɗanda da su don hulɗa tare da GPIOs. Kuna iya yin ta hanyoyi da yawa, ta amfani da daidaitaccen tsari ko ƙirar kernel ta ɗakin karatulibgpood, amma kuma ta hanyar dakin karatu na ɓangare na uku kamar alade.
  • Tsarin aiki3, kwatankwacin Arduino.

Zaɓi sassauƙa wanda ka fi so ko kuma kake tunanin mai sauki ne.


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

Kasance na farko don yin sharhi

Bar tsokaci

Your email address ba za a buga. Bukata filayen suna alama da *

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.