Différences entre versions de « Pi-WiringPi-Exemple-Quick2Wire-Install »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
(Page créée avec « {{Pi-WiringPi-NAV}} == Intro == {{bloc-etroit|text=Once I’d soldered it and checked to make sure no solder bridges, etc. I plugged it in to do some testing. The main boa... »)
 
Ligne 12 : Ligne 12 :
 
== Tester le module principal ==
 
== Tester le module principal ==
  
 +
=== Led et bouton ===
 
The button is connected to pin 0 and the LED to pin 1 du GPIO. The button is wired so that the input reads 1 when you push the button.
 
The button is connected to pin 0 and the LED to pin 1 du GPIO. The button is wired so that the input reads 1 when you push the button.
  
Ligne 30 : Ligne 31 :
  
 
should return 1 when you push the button, otherwise 0.
 
should return 1 when you push the button, otherwise 0.
 +
 +
=== Ajouter une LED ===
  
 
At the bottom of the main board is the external GPIO connector as well as some power and ground pins. The GPIO outputs have series resistors, so can be connected directly to LEDs – I connected an LED between 0v and pin7.
 
At the bottom of the main board is the external GPIO connector as well as some power and ground pins. The GPIO outputs have series resistors, so can be connected directly to LEDs – I connected an LED between 0v and pin7.
  
[[Fichier:Pi-WiringPi-Exemple-Quick2Wire-Install.jpg|640px]]<br /><small>Source: [http://wirinPi.com wiringPi.com]</small>
+
[[Fichier:Pi-WiringPi-Exemple-Quick2Wire-Install.jpg|640px]]<br /><small>Source: [http://wirinPi.com wiringPi.com]<br />Testing the board. LED is connected from pin 7 to GND (0v) Long leg to pin 7… Also note the jumpers next to the on-board LED and button near the middle-right of the board.</small>
  
 
Exécutez ensuite le code suivant:
 
Exécutez ensuite le code suivant:
Ligne 42 : Ligne 45 :
 
and used the button to toggle the LED on pin 7 in the same way as above.
 
and used the button to toggle the LED on pin 7 in the same way as above.
  
  <nowiki></nowiki>
+
So the main board on its own is already quite versatile, and using BASH and the command line, we can perform some simple tests on it.
 +
 
 +
== Le programme en C ==
 +
The standard “blink” program in C is:
 +
 
 +
  <nowiki>#include <stdio.h>
 +
#include <wiringPi.h>
 +
 
 +
#define LED    1
 +
 
 +
int main (void)
 +
{
 +
  printf ("Raspberry Pi Quick2Wire blink\n") ;
 +
 
 +
  wiringPiSetup () ;
 +
  pinMode (LED, OUTPUT) ;
 +
 
 +
  for (;;)
 +
  {
 +
    digitalWrite (LED, HIGH) ;  // On
 +
    delay (500) ;              // mS
 +
    digitalWrite (LED, LOW) ;  // Off
 +
    delay (500) ;
 +
  }
 +
  return 0 ;
 +
}</nowiki>
 +
 
 +
Compile this with:
 +
 
 +
<nowiki>gcc -o blink blink.c -lwiringPi</nowiki>
 +
 
 +
and run:
 +
 
 +
<nowiki>sudo ./blink</nowiki>
 +
 
 +
Press Control-C to exit.
 +
 
 +
You’ll find this program along with all the others mentioned here in the ''q2w'' directory under the ''examples'' directory in the wiringPi source distribution.
 +
 
 +
== Le programme Bash ==
 +
 
 +
If you don’t want to run the blink programme in C program just yet, then via BASH:
 +
 
 +
<nowiki>while true; do gpio write 1 1 ; sleep 0.5 ; gpio write 1 0 ; sleep 0.5 ; done</nowiki>
 +
 
 +
This is ''blink.sh'' in the ''q2w'' directory.
 +
 
 +
== Encore plus ==
 +
Have a look at the button.c program too – that will light up the on-board (red) LED but when you push the button it will turn it off an light up an LED connected to pin 7 (as shown above with the yellow LED) Compile and rung this this by typing:
 +
 
 +
<nowiki>make button
 +
sudo ./button</nowiki>
 +
 
 +
Or use the compilation commands as described abive.
 +
 
 +
Using this knowledge, it should be possible to use the Quick2Wire main board for some simple projects – using the on-board LED and button, and using the 8-way connector at the bottom to connect more LEDs and buttons.
  
<nowiki></nowiki>
+
== Ne pas oublier!! ==
  
<nowiki></nowiki>
+
N'oublier pas de retirer les cavaliers de la LED et du bouton (sur la carte principale) si vous voulez utiliser la broche 0 et 1 du GPIO de votre Raspberry Pi.
  
 
{{Pi-WiringPi-TRAILER}}
 
{{Pi-WiringPi-TRAILER}}

Version du 30 septembre 2013 à 10:00


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Intro

Once I’d soldered it and checked to make sure no solder bridges, etc. I plugged it in to do some testing.

The main board has an LED and a button and these can be optionally jumpered into the GPIO pins. The two jumper links next to the LED and button need to be present to use them.


To test, make sure wiringPi est installé

Tester le module principal

Led et bouton

The button is connected to pin 0 and the LED to pin 1 du GPIO. The button is wired so that the input reads 1 when you push the button.

Placer les cavalier de façon a rendre la LED et le bouton fonctionnel. Ensuite:

gpio mode 0 in  # Button pin 0
gpio mode 1 out # LED pin 1
while true; do gpio write 1 `gpio read 0`; done

Pushing the button should light the LED. If not, then check each one individually:

gpio write 1 1 # LED on
gpio write 1 0 # LED off

and for the button:

gpio read 0

should return 1 when you push the button, otherwise 0.

Ajouter une LED

At the bottom of the main board is the external GPIO connector as well as some power and ground pins. The GPIO outputs have series resistors, so can be connected directly to LEDs – I connected an LED between 0v and pin7.

Pi-WiringPi-Exemple-Quick2Wire-Install.jpg
Source: wiringPi.com
Testing the board. LED is connected from pin 7 to GND (0v) Long leg to pin 7… Also note the jumpers next to the on-board LED and button near the middle-right of the board.

Exécutez ensuite le code suivant:

gpio mode 7 out
while true; do gpio write 7 `gpio read 0`; done

and used the button to toggle the LED on pin 7 in the same way as above.

So the main board on its own is already quite versatile, and using BASH and the command line, we can perform some simple tests on it.

Le programme en C

The standard “blink” program in C is:

#include <stdio.h>
#include <wiringPi.h>

#define LED     1

int main (void)
{
  printf ("Raspberry Pi Quick2Wire blink\n") ;

  wiringPiSetup () ;
  pinMode (LED, OUTPUT) ;

  for (;;)
  {
    digitalWrite (LED, HIGH) ;  // On
    delay (500) ;               // mS
    digitalWrite (LED, LOW) ;   // Off
    delay (500) ;
  }
  return 0 ;
}

Compile this with:

gcc -o blink blink.c -lwiringPi

and run:

sudo ./blink

Press Control-C to exit.

You’ll find this program along with all the others mentioned here in the q2w directory under the examples directory in the wiringPi source distribution.

Le programme Bash

If you don’t want to run the blink programme in C program just yet, then via BASH:

while true; do gpio write 1 1 ; sleep 0.5 ; gpio write 1 0 ; sleep 0.5 ; done

This is blink.sh in the q2w directory.

Encore plus

Have a look at the button.c program too – that will light up the on-board (red) LED but when you push the button it will turn it off an light up an LED connected to pin 7 (as shown above with the yellow LED) Compile and rung this this by typing:

make button
sudo ./button

Or use the compilation commands as described abive.

Using this knowledge, it should be possible to use the Quick2Wire main board for some simple projects – using the on-board LED and button, and using the 8-way connector at the bottom to connect more LEDs and buttons.

Ne pas oublier!!

N'oublier pas de retirer les cavaliers de la LED et du bouton (sur la carte principale) si vous voulez utiliser la broche 0 et 1 du GPIO de votre Raspberry Pi.


Source: WiringPi.com. WiringPi est une libraire sous licence GPL écrite par Gordon Henderson. Crédit: wiringpi.com

Traduit de l'anglais par Meurisse D. pour MCHobby.be

Traduit avec l'accord de Gordon Henderson, créateur de wiringPi - Translated with authorization of Gordon Henderson, creator of wiringPi

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.