Springen naar inhoud


PI

A Single Led

Pi Led

  • Log in a.u.b. om te beantwoorden
Er zijn 6 reacties in dit onderwerp

#1 pascalbianca

pascalbianca

    Webmaster/Admin

  • Webmaster
  • 4382 berichten
    Laatst bezocht 12 jan 2024 08:50
  • LocatieSusteren, Nederland, Midden Limburg.
Inzender

Geplaatst op 17 november 2012 - 11:56

Before we even get started with the GPIO, lets make an LED light up by simply wiring it to the +3.3v supply and 0v.

Bijlage  example1-300x225.jpg   28,31K   2 downloads
Bijlage  1led_bb1-267x300.jpg   24,68K   2 downloads

So… We have a yellow wire from the Pi’s +3.3v supply to the breadboard and this connects to an LED then via a 270? (ohm) resistor to 0v. The green wire connects back to the Pi.
(Note that here and in the following pages, the Fritzing breadboard layout is slightly different from the photos – it’s the same circuit, just laid out in a way that makes it easy to see in the images)
Refer to the diagram here
Bijlage  FJA5B1MH2WERJ0U_LARGE_.jpg   38,82K   2 downloads
to work out the pins we’re using. From this view the 3.3v pin on the GPIO connector is to the top-left, or pin number 1 on the connector.
In electronics terms, our circuit diagram looks like this:

Bijlage  test-205x300.png   27,11K   1 downloads

A quick word about the electronics involved. LEDs are Light Emitting Diodes and the diode part is important for us – they only pass electricity one way, so we need to make sure we put them in the right way round. They have a long leg and a slightly shorter leg. The long leg goes to the plus side and the shorter leg to the negative (or 0v) side. If we’re cut the legs short (as I have done here), then another way is to look at the side of the LED – there will be a flat section. Think of the flat as a minus sign and connect that to the 0v side of the circuit.
If we allow too much current through the LED, it will burn very bright for a very short period of time before it burns out, so we need a resistor to limit the current. Calculating the resistor value is not difficult but for now, just use anything from 270? to 330?. Anything higher will make the LED dimmer.
So now we have a lit LED. What we really need to do is make it easily turn on and offable – preferably by a command or program running on the Raspberry Pi.
We need to move the yellow wire to one of the programmable GPIO pins. We’ll move it to wiringPi pin 0 (GPIO-17) which is notionally the first user GPIO pin. (It’s physical location is pin 11 on the GPIO connector)

Bijlage  example2-300x225.jpg   28,47K   1 downloads
Bijlage  1led_gpio_bb1-267x300.jpg   23,56K   0 downloads

Do check against the wiring diagram to work out which pin on the connector to use. The LED will initially be off because normally the GPIO pins are initialised as inputs at power-on time.
If you haven’t already done so, download and install wiringPi. This will give you some libraries to use in C programs, but also a command-line program which we can use to test the GPIO with.

Before we go on, here the instruction how to download and install wiringPi.:
WiringPi is now maintained under GIT for ease of change tracking, however snapshots will occasionally be released under the older system for people not familiar with GIT.
If you do not have GIT installed, then under any of the Debian releases, you can install it with:
sudo apt-get install git-core
To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi
If you have already used the clone operation for the first time, then
cd wiringPi
git pull origin
Will fetch an updated version then you can re-run the build script below.
To build/install there is a new simplified script:
cd wiringPi
./build
The new build script will compile and install it all for you – it does use the sudo command at one point, so you may wish to inspect the script before running it.
The older method:

Click on the following link to fetch the source code for WiringPi Or:
cd /tmp
wget http:// project-downloads.drogon.net /files /wiringPi.tgz
To install
tar xfz wiringPi.tgz
cd wiringPi/wiringPi
make
sudo make install
cd ../gpio
make
sudo make install
cd ../examples
make
And to run:
sudo ./test1
or
sudo ./test2

WiringPi is released under the GNU Lesser Public License version 3.

And we go further where ended before download and installing wirePi.

Type the commands:

Code:
gpio mode 0 out
gpio write 0 1
gpio write 0 0


If all has gone well, the LED should come on, then go off again. The first gpio command above sets pin 0 to output mode, the 2nd sets pin 0 to the value “1? – logic 1 which puts a 3.3v signal on the pin, and turns the LED on, and the last one turns it off again.
A word about GPIO pin numberings…

t’s often customary to refer to the GPIO pins on a microcontroller by the pin number on the chip originating the signal (or by the internal register name and bit-number). The Arduino system decided that that was complex for newcomers and used a system called wiring which started the pin numbers at zero and worked upwards. This had the advantage of making sure that when they moved to new chips which possibly had different internal configurations, etc. the pin numbers would remain the same. I have adopted this scheme in my wiringPi library for the Raspberry Pi, but I also allow for the native GPIO numbering scheme too. You will probably see the GPIO numbering scheme elsewhere though, so I’ll give examples using both schemes.
If you look at the pins chart, then it gives both values. You can see that wiringPi pin 0 is GPIO-17. wiringPi pin 1 is GPIO-18, wiringPi pin 2 is GPIO-21 an so on. To use the GPIO pin numbering then you need to pass the -g flag to the gpio program:

Code:
gpio -g write 17 1
gpio -g write 17 0

This should turn the LED on then off again.

pins chart.:
Bijlage  WIRING1.png   27,93K   0 downloads
Bijlage  WIRING2.png   13,16K   0 downloads

#2 plekke

plekke

    Senior Developer

  • Leden
  • PipPipPip
  • 135 berichten
    Laatst bezocht 25 mei 2017 21:45

Geplaatst op 04 mei 2013 - 21:51

vandaag dit eens geprobeert , dit werkt goed.

#3 pascalbianca

pascalbianca

    Webmaster/Admin

  • Webmaster
  • 4382 berichten
    Laatst bezocht 12 jan 2024 08:50
  • LocatieSusteren, Nederland, Midden Limburg.
Inzender

Geplaatst op 05 mei 2013 - 04:38

Fijn te horen dat dit toch iemand probeert :)

#4 plekke

plekke

    Senior Developer

  • Leden
  • PipPipPip
  • 135 berichten
    Laatst bezocht 25 mei 2017 21:45

Geplaatst op 05 mei 2013 - 11:32

Bericht bekijkenpascalbianca, op 05 mei 2013 - 04:38, zei:

Fijn te horen dat dit toch iemand probeert :)

ge moet ergens beginnen he...

intussen dit 8keer  na elkaar gemaakt


#5 pascalbianca

pascalbianca

    Webmaster/Admin

  • Webmaster
  • 4382 berichten
    Laatst bezocht 12 jan 2024 08:50
  • LocatieSusteren, Nederland, Midden Limburg.
Inzender

Geplaatst op 05 mei 2013 - 17:19

Netjes gedaan.
Die ledbar wat je gebruikt heb ik in mijn project zitten als cpu ledmeter wrkend op i2c.

#6 plekke

plekke

    Senior Developer

  • Leden
  • PipPipPip
  • 135 berichten
    Laatst bezocht 25 mei 2017 21:45

Geplaatst op 05 mei 2013 - 18:33

Bericht bekijkenpascalbianca, op 05 mei 2013 - 17:19, zei:

Netjes gedaan.
Die ledbar wat je gebruikt heb ik in mijn project zitten als cpu ledmeter wrkend op i2c.

merci , de ledbar haalde ik uit electronicascrap.
zijn makkelijk en compact om testbordjes mee te maken.

welke ide gebruik je voor de python?
ik werk met pyscripter  (in win7) maar ik kan daar geen gpio simuleren.

moet men dan altijd in en met de raspi als ide omgeving werken?

#7 pascalbianca

pascalbianca

    Webmaster/Admin

  • Webmaster
  • 4382 berichten
    Laatst bezocht 12 jan 2024 08:50
  • LocatieSusteren, Nederland, Midden Limburg.
Inzender

Geplaatst op 05 mei 2013 - 20:50

Nou ik werk direct in de Raspberry zelf, dan kan ik altijd het resultaat zien, dit doe ik wel on remote, deed dit eerst via vnc maar gebruik al enige tijd de manier die RedThread heeft geplaatst LINK.
Je kunt dit inderdaad ook in een simulator doen (staat idem in dit forum vermeld) maar zoals je al vermeld kun je het GPIO effect niet simuleren.





Ook met taq PI, Pi, Led voorzien

0 gebruiker(s) lezen dit onderwerp

0 lid(leden), 0 bezoeker(s), 0 anonieme gebruikers

Inloggen


[PI] Untitled 1

Met dank aan Jürgen voor de jarenlange inzet van visualbasic.be (anno dec 2000)
Met dank aan Mike en Ronneke voor de jarenlange inzet van vbib.be (anno dec 2010)
Met dank aan PascalBianca voor de jarenlange inzet van vbib.be (anno dec 2016)