diff --git a/fr-FR/images/.keep b/fr-FR/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/fr-FR/images/ADC.png b/fr-FR/images/ADC.png new file mode 100644 index 0000000..359af43 Binary files /dev/null and b/fr-FR/images/ADC.png differ diff --git a/fr-FR/images/LDR_and_cap_wired.png b/fr-FR/images/LDR_and_cap_wired.png new file mode 100644 index 0000000..82af0ec Binary files /dev/null and b/fr-FR/images/LDR_and_cap_wired.png differ diff --git a/fr-FR/images/Laser-tripwire_1-01.png b/fr-FR/images/Laser-tripwire_1-01.png new file mode 100644 index 0000000..ed5ce94 Binary files /dev/null and b/fr-FR/images/Laser-tripwire_1-01.png differ diff --git a/fr-FR/images/Laser-tripwire_2-01.jpg b/fr-FR/images/Laser-tripwire_2-01.jpg new file mode 100644 index 0000000..8e28466 Binary files /dev/null and b/fr-FR/images/Laser-tripwire_2-01.jpg differ diff --git a/fr-FR/images/Laser-tripwire_2-01.png b/fr-FR/images/Laser-tripwire_2-01.png new file mode 100644 index 0000000..aaf42de Binary files /dev/null and b/fr-FR/images/Laser-tripwire_2-01.png differ diff --git a/fr-FR/images/Laser-tripwire_3-01.jpg b/fr-FR/images/Laser-tripwire_3-01.jpg new file mode 100644 index 0000000..1e86236 Binary files /dev/null and b/fr-FR/images/Laser-tripwire_3-01.jpg differ diff --git a/fr-FR/images/Laser-tripwire_3-01.png b/fr-FR/images/Laser-tripwire_3-01.png new file mode 100644 index 0000000..f8c12c3 Binary files /dev/null and b/fr-FR/images/Laser-tripwire_3-01.png differ diff --git a/fr-FR/images/analogue-digital.png b/fr-FR/images/analogue-digital.png new file mode 100755 index 0000000..f376ba0 Binary files /dev/null and b/fr-FR/images/analogue-digital.png differ diff --git a/fr-FR/images/battery-pack.png b/fr-FR/images/battery-pack.png new file mode 100644 index 0000000..ce361ef Binary files /dev/null and b/fr-FR/images/battery-pack.png differ diff --git a/fr-FR/images/breadboard.png b/fr-FR/images/breadboard.png new file mode 100644 index 0000000..fec2cee Binary files /dev/null and b/fr-FR/images/breadboard.png differ diff --git a/fr-FR/images/button.png b/fr-FR/images/button.png new file mode 100644 index 0000000..48d6cc9 Binary files /dev/null and b/fr-FR/images/button.png differ diff --git a/fr-FR/images/buzzer-circuit.png b/fr-FR/images/buzzer-circuit.png new file mode 100644 index 0000000..2a4417d Binary files /dev/null and b/fr-FR/images/buzzer-circuit.png differ diff --git a/fr-FR/images/camjam1wiring.png b/fr-FR/images/camjam1wiring.png new file mode 100644 index 0000000..16e51c7 Binary files /dev/null and b/fr-FR/images/camjam1wiring.png differ diff --git a/fr-FR/images/capacitor.png b/fr-FR/images/capacitor.png new file mode 100644 index 0000000..8b8e433 Binary files /dev/null and b/fr-FR/images/capacitor.png differ diff --git a/fr-FR/images/complete.gif b/fr-FR/images/complete.gif new file mode 100644 index 0000000..74a9612 Binary files /dev/null and b/fr-FR/images/complete.gif differ diff --git a/fr-FR/images/complete.png b/fr-FR/images/complete.png new file mode 100644 index 0000000..b1995e0 Binary files /dev/null and b/fr-FR/images/complete.png differ diff --git a/fr-FR/images/cover.png b/fr-FR/images/cover.png new file mode 100644 index 0000000..7f81f07 Binary files /dev/null and b/fr-FR/images/cover.png differ diff --git a/fr-FR/images/gpio-setup.png b/fr-FR/images/gpio-setup.png new file mode 100644 index 0000000..e1fe4f5 Binary files /dev/null and b/fr-FR/images/gpio-setup.png differ diff --git a/fr-FR/images/h-bridge.png b/fr-FR/images/h-bridge.png new file mode 100644 index 0000000..5ca1553 Binary files /dev/null and b/fr-FR/images/h-bridge.png differ diff --git a/fr-FR/images/jumper-female-to-female.png b/fr-FR/images/jumper-female-to-female.png new file mode 100644 index 0000000..0b43ebb Binary files /dev/null and b/fr-FR/images/jumper-female-to-female.png differ diff --git a/fr-FR/images/jumper-male-to-female.png b/fr-FR/images/jumper-male-to-female.png new file mode 100644 index 0000000..fdc4225 Binary files /dev/null and b/fr-FR/images/jumper-male-to-female.png differ diff --git a/fr-FR/images/jumper-male-to-male.png b/fr-FR/images/jumper-male-to-male.png new file mode 100644 index 0000000..cfe235f Binary files /dev/null and b/fr-FR/images/jumper-male-to-male.png differ diff --git a/fr-FR/images/ldr.png b/fr-FR/images/ldr.png new file mode 100644 index 0000000..f229656 Binary files /dev/null and b/fr-FR/images/ldr.png differ diff --git a/fr-FR/images/led-3v3.png b/fr-FR/images/led-3v3.png new file mode 100644 index 0000000..0be79a4 Binary files /dev/null and b/fr-FR/images/led-3v3.png differ diff --git a/fr-FR/images/led-gpio17.png b/fr-FR/images/led-gpio17.png new file mode 100644 index 0000000..8e16ed4 Binary files /dev/null and b/fr-FR/images/led-gpio17.png differ diff --git a/fr-FR/images/led.png b/fr-FR/images/led.png new file mode 100644 index 0000000..6901992 Binary files /dev/null and b/fr-FR/images/led.png differ diff --git a/fr-FR/images/mcb-wiring.png b/fr-FR/images/mcb-wiring.png new file mode 100644 index 0000000..5195444 Binary files /dev/null and b/fr-FR/images/mcb-wiring.png differ diff --git a/fr-FR/images/mcb.png b/fr-FR/images/mcb.png new file mode 100644 index 0000000..aba9abf Binary files /dev/null and b/fr-FR/images/mcb.png differ diff --git a/fr-FR/images/mcp3008-2pots-led.png b/fr-FR/images/mcp3008-2pots-led.png new file mode 100644 index 0000000..21256ef Binary files /dev/null and b/fr-FR/images/mcp3008-2pots-led.png differ diff --git a/fr-FR/images/mcp3008-pot-led.png b/fr-FR/images/mcp3008-pot-led.png new file mode 100644 index 0000000..f1fe4ef Binary files /dev/null and b/fr-FR/images/mcp3008-pot-led.png differ diff --git a/fr-FR/images/mcp3008-pot.png b/fr-FR/images/mcp3008-pot.png new file mode 100644 index 0000000..7f132dc Binary files /dev/null and b/fr-FR/images/mcp3008-pot.png differ diff --git a/fr-FR/images/mcp3008.png b/fr-FR/images/mcp3008.png new file mode 100644 index 0000000..49a7729 Binary files /dev/null and b/fr-FR/images/mcp3008.png differ diff --git a/fr-FR/images/motor-controller.png b/fr-FR/images/motor-controller.png new file mode 100644 index 0000000..e7323f6 Binary files /dev/null and b/fr-FR/images/motor-controller.png differ diff --git a/fr-FR/images/motor.png b/fr-FR/images/motor.png new file mode 100644 index 0000000..76fdee1 Binary files /dev/null and b/fr-FR/images/motor.png differ diff --git a/fr-FR/images/motor2.png b/fr-FR/images/motor2.png new file mode 100644 index 0000000..a522be2 Binary files /dev/null and b/fr-FR/images/motor2.png differ diff --git a/fr-FR/images/piezo-buzzer.png b/fr-FR/images/piezo-buzzer.png new file mode 100644 index 0000000..8e463f8 Binary files /dev/null and b/fr-FR/images/piezo-buzzer.png differ diff --git a/fr-FR/images/pinout.png b/fr-FR/images/pinout.png new file mode 100644 index 0000000..24ba723 Binary files /dev/null and b/fr-FR/images/pinout.png differ diff --git a/fr-FR/images/pir.png b/fr-FR/images/pir.png new file mode 100644 index 0000000..e831ea6 Binary files /dev/null and b/fr-FR/images/pir.png differ diff --git a/fr-FR/images/pir_module.png b/fr-FR/images/pir_module.png new file mode 100644 index 0000000..0008724 Binary files /dev/null and b/fr-FR/images/pir_module.png differ diff --git a/fr-FR/images/pir_potentiometers.png b/fr-FR/images/pir_potentiometers.png new file mode 100644 index 0000000..c8273e0 Binary files /dev/null and b/fr-FR/images/pir_potentiometers.png differ diff --git a/fr-FR/images/pir_pots.jpg b/fr-FR/images/pir_pots.jpg new file mode 100644 index 0000000..6f094c6 Binary files /dev/null and b/fr-FR/images/pir_pots.jpg differ diff --git a/fr-FR/images/pir_wiring.png b/fr-FR/images/pir_wiring.png new file mode 100644 index 0000000..80ecaea Binary files /dev/null and b/fr-FR/images/pir_wiring.png differ diff --git a/fr-FR/images/potentiometer.png b/fr-FR/images/potentiometer.png new file mode 100644 index 0000000..4970ac3 Binary files /dev/null and b/fr-FR/images/potentiometer.png differ diff --git a/fr-FR/images/potentiometerA.jpg b/fr-FR/images/potentiometerA.jpg new file mode 100644 index 0000000..58ab840 Binary files /dev/null and b/fr-FR/images/potentiometerA.jpg differ diff --git a/fr-FR/images/python3-app-menu.png b/fr-FR/images/python3-app-menu.png new file mode 100644 index 0000000..d8b8e88 Binary files /dev/null and b/fr-FR/images/python3-app-menu.png differ diff --git a/fr-FR/images/raspio-ports.jpg b/fr-FR/images/raspio-ports.jpg new file mode 100644 index 0000000..42f5774 Binary files /dev/null and b/fr-FR/images/raspio-ports.jpg differ diff --git a/fr-FR/images/rcgui.png b/fr-FR/images/rcgui.png new file mode 100644 index 0000000..09895e2 Binary files /dev/null and b/fr-FR/images/rcgui.png differ diff --git a/fr-FR/images/resistor-330r.png b/fr-FR/images/resistor-330r.png new file mode 100644 index 0000000..66fcdb3 Binary files /dev/null and b/fr-FR/images/resistor-330r.png differ diff --git a/fr-FR/images/resistor-470r.png b/fr-FR/images/resistor-470r.png new file mode 100644 index 0000000..5e0b29b Binary files /dev/null and b/fr-FR/images/resistor-470r.png differ diff --git a/fr-FR/images/tactile-push-button.png b/fr-FR/images/tactile-push-button.png new file mode 100644 index 0000000..70c8811 Binary files /dev/null and b/fr-FR/images/tactile-push-button.png differ diff --git a/fr-FR/images/traffic-lights.png b/fr-FR/images/traffic-lights.png new file mode 100644 index 0000000..e3931d4 Binary files /dev/null and b/fr-FR/images/traffic-lights.png differ diff --git a/fr-FR/images/ultrasonic-distance-sensor.png b/fr-FR/images/ultrasonic-distance-sensor.png new file mode 100644 index 0000000..a5e2a9f Binary files /dev/null and b/fr-FR/images/ultrasonic-distance-sensor.png differ diff --git a/fr-FR/images/wiring-uds.png b/fr-FR/images/wiring-uds.png new file mode 100644 index 0000000..4fba490 Binary files /dev/null and b/fr-FR/images/wiring-uds.png differ diff --git a/fr-FR/meta.yml b/fr-FR/meta.yml new file mode 100644 index 0000000..7e8881c --- /dev/null +++ b/fr-FR/meta.yml @@ -0,0 +1,40 @@ +--- +title: Physical Computing with Python +hero_image: images/cover.png +subtitle: Getting started with physical computing +description: Get started with physical computing on the Raspberry Pi using Python. +original_url: https://www.raspberrypi.org/learning/physical-computing-with-python/ +theme: green +duration: 2 +copyedit: true +listed: true +ingredient: false +curriculum: 1, design-0, programming-1, phys-comp-1, manufacture-0, community-0 +technologies: electronic-components, python +interests: '' +hardware: electronic-components +software: python +site_areas: projects +version: 3 +last_tested: 2017-01-01 +steps: +- title: Introduction +- title: GPIO pins +- title: Lighting an LED + completion: + - engaged +- title: Switching an LED on and off +- title: Flashing an LED +- title: Using buttons to get input +- title: Manually controlling the LED +- title: Making a switch +- title: Using a buzzer +- title: Making traffic lights +- title: Using a light-dependent resistor +- title: Using a PIR sensor +- title: Using an ultrasonic distance sensor +- title: Analogue inputs +- title: Using motors + completion: + - internal +- title: What next? diff --git a/fr-FR/resources/.keep b/fr-FR/resources/.keep new file mode 100644 index 0000000..e69de29 diff --git a/fr-FR/solutions/.keep b/fr-FR/solutions/.keep new file mode 100644 index 0000000..e69de29 diff --git a/fr-FR/solutions/basic_button.py b/fr-FR/solutions/basic_button.py new file mode 100644 index 0000000..2064566 --- /dev/null +++ b/fr-FR/solutions/basic_button.py @@ -0,0 +1,5 @@ +from gpiozero import Button +button = Button(2) ##The pin the button is wired to + +button.wait_for_press() +print('You pushed me') diff --git a/fr-FR/solutions/basic_buzzer.py b/fr-FR/solutions/basic_buzzer.py new file mode 100644 index 0000000..a362b9c --- /dev/null +++ b/fr-FR/solutions/basic_buzzer.py @@ -0,0 +1,7 @@ +from gpiozero import Buzzer +from time import sleep + +buzzer = Buzzer(17) + +while True: + buzzer.beep() diff --git a/fr-FR/solutions/buggy.py b/fr-FR/solutions/buggy.py new file mode 100644 index 0000000..547bc10 --- /dev/null +++ b/fr-FR/solutions/buggy.py @@ -0,0 +1,14 @@ +from gpiozero import Robot +from time import sleep + +robot = Robot((4, 14), (17, 27)) + +robot.forward() +sleep(5) +robot.right() +sleep(1) +robot.backward() +sleep(1) +robot.left() +sleep(1) +robot.stop() diff --git a/fr-FR/solutions/flash_led.py b/fr-FR/solutions/flash_led.py new file mode 100644 index 0000000..d2b28fd --- /dev/null +++ b/fr-FR/solutions/flash_led.py @@ -0,0 +1,10 @@ +from gpiozero import LED +from time import sleep + +led = LED(17) + +while True: + led.on() + sleep(1) + led.off() + sleep(1) diff --git a/fr-FR/solutions/hold_to_light.py b/fr-FR/solutions/hold_to_light.py new file mode 100644 index 0000000..d20a940 --- /dev/null +++ b/fr-FR/solutions/hold_to_light.py @@ -0,0 +1,10 @@ +rom gpiozero import LED, Button +from signal import pause + +led = LED(17) +button = Button(2) + +button.when_pressed = led.on +button.when_released = led.off + +pause() diff --git a/fr-FR/solutions/ldr.py b/fr-FR/solutions/ldr.py new file mode 100644 index 0000000..0d8fc0c --- /dev/null +++ b/fr-FR/solutions/ldr.py @@ -0,0 +1,6 @@ +from gpiozero import LightSensor + +ldr = LightSensor(4) # alter if using a different pin + +while True: + print(ldr.value) diff --git a/fr-FR/solutions/led_button.py b/fr-FR/solutions/led_button.py new file mode 100644 index 0000000..1d86a46 --- /dev/null +++ b/fr-FR/solutions/led_button.py @@ -0,0 +1,10 @@ +from gpiozero import LED, Button +from time import sleep + +led = LED(17) +button = Button(2) + +button.wait_for_press() +led.on() +sleep(3) +led.off() diff --git a/fr-FR/solutions/light_and_led.py b/fr-FR/solutions/light_and_led.py new file mode 100644 index 0000000..102f683 --- /dev/null +++ b/fr-FR/solutions/light_and_led.py @@ -0,0 +1,6 @@ +from gpiozero import LED +led = LED(17) ##The pin the long leg is wired to + +led.on() + +#led.off() ##Uncomment this line and run to turn off the LED diff --git a/fr-FR/solutions/light_switch.py b/fr-FR/solutions/light_switch.py new file mode 100644 index 0000000..6803e42 --- /dev/null +++ b/fr-FR/solutions/light_switch.py @@ -0,0 +1,10 @@ +from gpiozero import LED, Button +from time import sleep + +led = LED(17) +button = Button(2) + +while True: + button.wait_for_press() + led.toggle() + sleep(0.5) diff --git a/fr-FR/solutions/motors.py b/fr-FR/solutions/motors.py new file mode 100644 index 0000000..ae4a304 --- /dev/null +++ b/fr-FR/solutions/motors.py @@ -0,0 +1,13 @@ +from gpiozero import Motor +from time import sleep + +motor1 = Motor(4, 14) +motor2 = Motor(17, 27) + +motor1.forward() +motor2.forward() + +while True: + sleep(5) + motor1.reverse() + motor2.reverse() diff --git a/fr-FR/solutions/pir.py b/fr-FR/solutions/pir.py new file mode 100644 index 0000000..1ab507d --- /dev/null +++ b/fr-FR/solutions/pir.py @@ -0,0 +1,8 @@ +rom gpiozero import MotionSensor + +pir = MotionSensor(4) + +while True: + pir.wait_for_motion() + print("You moved") + pir.wait_for_no_motion() diff --git a/fr-FR/solutions/traffic_lights.py b/fr-FR/solutions/traffic_lights.py new file mode 100644 index 0000000..b2f1442 --- /dev/null +++ b/fr-FR/solutions/traffic_lights.py @@ -0,0 +1,19 @@ +from gpiozero import Button, TrafficLights, Buzzer +from time import sleep + +button = Button(21) +lights = TrafficLights(25, 8, 7) +buzzer = Buzzer(15) + +button.wait_for_press() + + +while True: + button.wait_for_press() + lights.green.on() + sleep(1) + lights.amber.on() + sleep(1) + lights.red.on() + sleep(1) + lights.off() diff --git a/fr-FR/solutions/uds.py b/fr-FR/solutions/uds.py new file mode 100644 index 0000000..b6b66a0 --- /dev/null +++ b/fr-FR/solutions/uds.py @@ -0,0 +1,12 @@ +from gpiozero import DistanceSensor + +ultrasonic = DistanceSensor(echo=17, trigger=4, threshold_distance=0.5) + +def hello(): + print("Hello") + +def bye(): + print("Bye") + +ultrasonic.when_in_range = hello +ultrasonic.when_out_of_range = bye diff --git a/fr-FR/step_1.md b/fr-FR/step_1.md new file mode 100644 index 0000000..6a2e3a1 --- /dev/null +++ b/fr-FR/step_1.md @@ -0,0 +1,74 @@ +## Introduction + +Apprendre à utiliser les ports GPIO de votre Raspberry Pi pour s'interfacer avec des composants électronique, comme des LEDs et des PIRs. + +### Ce que vous allez faire + +--- no-print --- +![Complete project example](images/complete.gif) +--- /no-print --- + +--- print-only --- +![Complete project example](images/complete.png) +--- /print-only --- + +--- collapse --- +--- +title: Ce dont vous aurez besoin +--- +## Ce dont vous aurez besoin + +### Matériel + +En plus d'un Raspberry Pi avec un carte SD et les périphériques habituels, vous aurez aussi besoin: + +|1x Solderless breadboard | Male-to-female jumper leads | Female-to-female jumper leads | Male-to-male jumper leads | +|:--------:|:-------:|:--------:|:--------:| +| ![breadboard](images/breadboard.png) | ![m to f jumper leads](images/jumper-male-to-female.png) | ![f to f jumper leads](images/jumper-female-to-female.png) | ![m to m jumper leads](images/jumper-male-to-male.png) | + +| 1x Bouton tactile | 3x LEDs | Ultrasonic distance sensor| Passive infrared motion sensor | +|:--------:|:-------:|:--------:|:--------:| +| ![tactile button](images/tactile-push-button.png) | ![LED](images/led.png) | ![ultrasonic distance sensor](images/ultrasonic-distance-sensor.png) | ![PIR sensor](images/pir.png) | + +| Light Dependent Resistor | Moteur 5V | 3x Résistance 330Ω | 1x Résistance 470Ω | +|:--------:|:-------:|:--------:|:--------:| +| ![LDR](images/ldr.png) | ![motor](images/motor2.png) | ![330 resistor](images/resistor-330r.png) | ![470 resistor](images/resistor-470r.png) | + +| 1x Capaciteur 1μF | 1x Buzzer | 1x Contrôleur de Moteur | +|:--------:|:-------:|:--------:| +| ![capacitor](images/capacitor.png) | ![buzzer](images/piezo-buzzer.png) | ![motor controller](images/motor-controller.png) | + +| Battery Pack | 1x MCP3008 ADC | Potentiomètre | +|:--------:|:--------:|:-------:| +| ![battery pack](images/battery-pack.png) | ![ADC](images/ADC.png) | ![potentiometer](images/potentiometer.png) | + +### Logiciels + +Il n'y a pas de logiciels additionnels requis pour cette ressource en plus de ce qui est pré-installé sur l'image courante de Raspbian. + +--- /collapse --- + + +--- collapse --- +--- +title: Ce que vous allez apprendre +--- + ++ Apprendre comment câbler une variété de composants à un Raspberry Pi ++ Apprendre comment intéragir avec une variété de composants à l'aide de Python + +--- /collapse --- + +--- collapse --- +--- +title: Additional information for educators +--- + +Si vous avez besoin d'imprimer ce projet, utilisez la [version compatible impression](https://projects.raspberrypi.org/fr/projects/physical-computing/print){:target="_blank"}. + +You can [trouver la solution pour ce projet ici](http://rpf.io/p/en/physical-computing-get){:target="_blank"}. + +--- /collapse --- + + + diff --git a/fr-FR/step_10.md b/fr-FR/step_10.md new file mode 100644 index 0000000..fd8560f --- /dev/null +++ b/fr-FR/step_10.md @@ -0,0 +1,273 @@ +## Making traffic lights + +For this worksheet you'll need a breadboard, three LEDs, a button, a buzzer, and the necessary jumper cables and resistors. You can purchase these individually, or get everything you need in the [CamJam EduKit](https://thepihut.com/products/camjam-edukit). + +### Wiring + +To get started, you'll need to place all the components on the breadboard and connect them to the appropriate GPIO pins on the Raspberry Pi. + ++ First, you need to understand how each component is connected: + + - A push button requires 1 ground pin and 1 GPIO pin + - An LED requires 1 ground pin and 1 GPIO pin, with a current limiting resistor + - A buzzer requires 1 ground pin and 1 GPIO pin + + Each component requires its own individual GPIO pin, but components can share a ground pin. We will use the breadboard to enable this. + ++ Place the components on the breadboard and connect them to the Raspberry Pi GPIO pins, according to the following diagram: + + ![GPIO diagram](images/camjam1wiring.png) + + Note that the row along the long side of the breadboard is connected to a ground pin on the Raspberry Pi, so all the components in that row (which is used as a ground rail) are hence connected to ground. + ++ Observe the following table, showing which GPIO pin each component is connected to: + +| Component | GPIO pin | +| --------- | :------: | +| Button | 21 | +| Red LED | 25 | +| Amber LED | 8 | +| Green LED | 7 | +| Buzzer | 15 | + +### Dive into Python + ++ Create a new file by clicking **New**. + ++ Save the new file straight away by clicking **Save**; name the file `trafficlights.py`. + ++ Enter the following code: + + ```python + from gpiozero import Button + + button = Button(21) + + while True: + print(button.is_pressed) + ``` + + In GPIO Zero, you create an object for each component used. Each component interface must be imported from the `gpiozero` module, and an instance created on the GPIO pin number to which it is connected. + ++ Save and run the code. + ++ In the shell it will be constantly printing `False`. When you press the button this will switch to `True`, and when you let go it will return to `False`. + + `button.is_pressed` is a property of the `button` object, which provides the state of the button (pressed or not) at any given time. + ++ Now return to the code window and modify your `while` loop to show the following: + + ```python + while True: + if button.is_pressed: + print("Hello") + else: + print("Goodbye") + ``` + ++ Run the code again and you'll see "Hello" printed when the button is pressed, and "Goodbye" when the button is not pressed. + ++ Modify the loop again: + + ```python + while True: + button.wait_for_press() + print("Pressed") + button.wait_for_release() + print("Released") + ``` + ++ When you run the code this time, nothing will happen until you press the button, when you'll see "Pressed", then when you let go you'll see "Released". This will occur each time the button is pressed, but rather than continuously printing one or the other, it only does it once per press. + +### Add an LED + +Now you'll add an LED into the code and use GPIO Zero to allow the button to determine when the LED is lit. + ++ In your code, add to the `from gpiozero import...` line at the top to also bring in `LED`: + + ```python + from gpiozero import Button, LED + ``` + ++ Add a line below `button = Button(21)` to create an instance of an `LED` object: + + ```python + led = LED(25) + ``` + ++ Now modify your `while` loop to turn the LED on when the button is pressed: + + ```python + while True: + button.wait_for_press() + led.on() + button.wait_for_release() + led.off() + ``` + ++ Run your code and the LED will come on when you press the button. Hold the button down to keep the LED lit. + ++ Now swap the `on` and `off` lines to reverse the logic: + + ```python + while True: + led.on() + button.wait_for_press() + led.off() + button.wait_for_release() + ``` + ++ Run the code and you'll see the LED stays on until the button is pressed. + ++ Now replace `led.on()` with `led.blink()`: + + ```python + while True: + led.blink() + button.wait_for_press() + led.off() + button.wait_for_release() + ``` + ++ Run the code and you'll see the LED blink on and off until the button is pressed, at which point it will turn off completely. When the button is released, it will start blinking again. + ++ Try adding some parameters to `blink` to make it blink faster or slower: + + - `led.blink(2, 2)` - 2 seconds on, 2 seconds off + - `led.blink(0.5, 0.5)` - half a second on, half a second off + - `led.blink(0.1, 0.2)` - one tenth of a second on, one fifth of a second off + + `blink`'s first two (optional) parameters are `on_time` and `off_time`': they both default to 1 second. + +### Traffic lights + +You have three LEDs: red, amber, and green. Perfect for traffic lights! There's even a built-in interface for traffic lights in GPIO Zero. + ++ Amend the `from gpiozero import...` line to replace `LED` with `TrafficLights`: + + ```python + from gpiozero import Button, TrafficLights + ``` + ++ Replace your `led = LED(25)` line with the following: + + ```python + lights = TrafficLights(25, 8, 7) + ``` + + The `TrafficLights` interface takes three GPIO pin numbers, one for each pin: red, amber, and green (in that order). + ++ Now amend your `while` loop to control the `TrafficLights` object: + + ```python + while True: + button.wait_for_press() + lights.on() + button.wait_for_release() + lights.off() + ``` + + The `TrafficLights` interface is very similar to that of an individual LED: you can use `on`, `off`, and `blink`, all of which control all three lights at once. + ++ Try the `blink` example: + + ```python + while True: + lights.blink() + button.wait_for_press() + lights.off() + button.wait_for_release() + ``` + +### Add a buzzer + +Now you'll add your buzzer to make some noise. + ++ Add `Buzzer` to the `from gpiozero import...` line: + + ```python + from gpiozero import Button, TrafficLights, Buzzer + ``` + ++ Add a line below your creation of `button` and `lights` to add a `Buzzer` object: + + ```python + buzzer = Buzzer(15) + ``` + ++ `Buzzer` works exactly like `LED`, so try adding a `buzzer.on()` and `buzzer.off()` into your loop: + + ```python + while True: + lights.on() + buzzer.off() + button.wait_for_press() + lights.off() + buzzer.on() + button.wait_for_release() + ``` + ++ `Buzzer` has a `beep()` method which works like `LED`'s `blink`. Try it out: + + ```python + while True: + lights.blink() + buzzer.beep() + button.wait_for_press() + lights.off() + buzzer.off() + button.wait_for_release() + ``` + +### Traffic lights sequence + +As well as controlling the whole set of lights together, you can also control each LED individually. With traffic light LEDs, a button and a buzzer, you can create your own traffic lights sequence, complete with pedestrian crossing! + ++ At the top of your file, below `from gpiozero import...`, add a line to import the `sleep` function: + + ```python + from time import sleep + ``` + ++ Modify your loop to perform an automated sequence of LEDs being lit: + + ```python + while True: + lights.green.on() + sleep(1) + lights.amber.on() + sleep(1) + lights.red.on() + sleep(1) + lights.off() + ``` + ++ Add a `wait_for_press` so that pressing the button initiates the sequence: + + ```python + while True: + button.wait_for_press() + lights.green.on() + sleep(1) + lights.amber.on() + sleep(1) + lights.red.on() + sleep(1) + lights.off() + ``` + + Try some more sequences of your own. + ++ Now try creating the full traffic lights sequence: + + - Green on + - Amber on + - Red on + - Red and amber on + - Green on + + Be sure to turn the correct lights on and off at the right time, and make sure you use `sleep` to time the sequence perfectly. + ++ Try adding the button for a pedestrian crossing. The button should move the lights to red (not immediately), and give the pedestrians time to cross before moving back to green until the button is pressed again. + ++ Now try adding a buzzer to beep quickly to indicate that it is safe to cross, for the benefit of visually impaired pedestrians. diff --git a/fr-FR/step_11.md b/fr-FR/step_11.md new file mode 100644 index 0000000..73f9b18 --- /dev/null +++ b/fr-FR/step_11.md @@ -0,0 +1,68 @@ +## Using a light-dependent resistor + +### Analogue inputs + +In the world of electrical engineering, there are two type of input and output (I/O): analogue and digital. Digital I/O is fairly easy to understand; it's either *on* or *off*, *1* or *0*. + +When talking about voltages and the Raspberry Pi, any input that is approximately below 1.8V is considered *off* and anything above 1.8V is considered *on*. For output, 0V is off and 3.3V is on. + +Analogue I/O is a little trickier. With an analogue input, we can have a range of voltages from 0V up to 3.3V, and the Raspberry Pi is unable to detect exactly what that voltage is. + +![](images/analogue-digital.png) + +How, then, can we use a Raspberry Pi to determine the value of an analogue input, if it can only tell when the voltage to a GPIO pin goes above 1.8V? + +### Using a capacitor for analogue inputs + +Capacitors are electrical components that store charge. + +![](images/capacitor.png) + +When current is fed into a capacitor, it will begin to store charge. The voltage across the capacitor will start off low, and increase as the charge builds up. + +By putting a resistor in series with the capacitor, you can slow the speed at which it charges. With a high resistance, the capacitor will charge slowly, whereas a low resistance will let it charge quickly. + +If you time how long it takes the capacitor's voltage to get over 1.8V (or be *on*), you can work out the resistance of the component in series with it. + +Many, but not all, capacitors are polarised which means they have a positive and a negative leg. In this case, the negative leg is shorter and should be marked with a '-' symbol. + +### Light-dependent resistors + +An LDR (sometimes called a photocell) is a special type of resistor. + +![](images/ldr.png) + +When light hits the LDR, its resistance is very low, but when it's in the dark its resistance is very high. + +By placing a capacitor in series with an LDR, the capacitor will charge at different speeds depending on whether it's light or dark. + +### Creating a light-sensing circuit + ++ Place an LDR into your breadboard, as shown below: + +![](images/Laser-tripwire_1-01.png) + ++ Now place a capacitor in series with the LDR. As the capacitor is a polar component, you must make sure the positive, long leg is on the same track as the LDR leg. + +![](images/Laser-tripwire_2-01.jpg) + ++ Finally, add jumper leads to connect the two components to your Raspberry Pi. + +![](images/Laser-tripwire_3-01.jpg) + +### Coding a light sensor + +Luckily, most of the complicated code you would have to write to detect the light levels received by the LDR has been abstracted away by the `gpiozero` library. This library will handle the timing of the capacitor's charging and discharging for you. + +Use the following code to set up the light sensor: + +```python + from gpiozero import LightSensor, Buzzer + + ldr = LightSensor(4) # alter if using a different pin + while True: + print(ldr.value) + +``` + +Run this code, then cover the LDR with your hand and watch the value change. Try shining a strong light onto the LDR. diff --git a/fr-FR/step_12.md b/fr-FR/step_12.md new file mode 100644 index 0000000..494051a --- /dev/null +++ b/fr-FR/step_12.md @@ -0,0 +1,42 @@ +## Using a PIR sensor + +Humans and other animals emit radiation all the time. This is nothing to be concerned about, though, as the type of radiation we emit is infrared radiation (IR), which is pretty harmless at the levels at which it is emitted by humans. In fact, all objects at temperatures above absolute zero (-273.15C) emit infrared radiation. + +A PIR sensor detects changes in the amount of infrared radiation it receives. When there is a significant change in the amount of infrared radiation it detects, then a pulse is triggered. This means that a PIR sensor can detect when a human (or any animal) moves in front of it. + +![pir](images/pir_module.png) + +### Wiring a PIR sensor + +The pulse emitted when a PIR detects motion needs to be amplified, and so it needs to be powered. There are three pins on the PIR: they should be labelled **Vcc**, **Gnd**, and **Out**. These labels are sometimes concealed beneath the Fresnel lens (the white cap), which you can temporarily remove to see the pin labels. + +![wiring](images/pir_wiring.png) + +1. As shown above, the **Vcc** pin needs to be attached to a **5V** pin on the Raspberry Pi. +1. The **Gnd** pin on the PIR sensor can be attached to **any** ground pin on the Raspberry Pi. +1. Lastly, the **Out** pin needs to be connected to **any** of the GPIO pins. + +### Tuning a PIR + +Most PIR sensors have two potentiometers on them. These can control the sensitivity of the sensors, and also the period of time for which the PIR will signal when motion is detected. + +![pir pots](images/pir_pots.jpg) + +In the image above, the potentiometer on the right controls the sensitivity, and the potentiometer on the left controls the timeout. Here, both are turned fully anti-clockwise, meaning that the sensitivity and timeout are at their lowest. + +When the timeout is turned fully anti-clockwise, the PIR will output a signal for about 2.5 seconds, whenever motion is detected. If the potentiometer is turned fully clockwise, the output signal will last for around 250 seconds. When tuning the sensitivity, it is best to have the timeout set as low as possible. + +### Detecting motion + +You can detect motion with the PIR using the code below: + +```python +from gpiozero import MotionSensor + +pir = MotionSensor(4) + +while True: + pir.wait_for_motion() + print("You moved") + pir.wait_for_no_motion() +``` diff --git a/fr-FR/step_13.md b/fr-FR/step_13.md new file mode 100644 index 0000000..84cc7ca --- /dev/null +++ b/fr-FR/step_13.md @@ -0,0 +1,97 @@ +## Using an ultrasonic distance sensor + +In air, sound travels at a speed of 343 metres per second. An ultrasonic distance sensor sends out pulses of ultrasound which are inaudible to humans, and detects the echo that is sent back when the sound bounces off a nearby object. It then uses the speed of sound to calculate the distance from the object. + +![Ultrasonic distance sensor](images/ultrasonic-distance-sensor.png) + +### Wiring + +The circuit connects to two GPIO pins (one for echo, one for trigger), the ground pin, and a 5V pin. You'll need to use a pair of resistors (330Ω and 470Ω) as a potential divider: + +![wiring](images/wiring-uds.png) + +### Code + +To use the ultrasonic distance sensor in Python, you need to know which GPIO pins the echo and trigger are connected to. + + ++ Use the following code to read the `DistanceSensor`. + + ```python + from gpiozero import DistanceSensor + ultrasonic = DistanceSensor(echo=17, trigger=4) + while True: + print(ultrasonic.distance) + ``` + ++ The value should get smaller the closer your hand is to the sensor. Press **Stop** to exit the loop. + +### Ranges + +As well as being able to see the distance value, you can also get the sensor to do things when the object is in or out of a certain range. + ++ Use a loop to print different messages when the sensor is in range or out of range: + + ```python + while True: + ultrasonic.wait_for_in_range() + print("In range") + ultrasonic.wait_for_out_of_range() + print("Out of range") + ``` + + Now wave your hand in front of the sensor; it should switch between showing the message "In range" and "Out of range" as your hand gets closer and further away from the sensor. See if you can work out the point at which it changes. + ++ The default range threshold is 0.3m. This can be configured when the sensor is initiated: + + ```python + ultrasonic = DistanceSensor(echo=17, trigger=4, threshold_distance=0.5) + ``` + + Alternatively, this can be changed after the sensor is created, by setting the `threshold_distance` property: + + ```python + ultrasonic.threshold_distance = 0.5 + ``` + ++ Try the previous loop again and observe the new range threshold. + ++ The `wait_for` functions are **blocking**, which means they halt the program until they are triggered. Another way of doing something when the sensor goes in and out of range is to use `when` properties, which can be used to trigger actions in the background while other things are happening in the code. + + First, you need to create a function for what you want to happen when the sensor is in range: + + ```python + def hello(): + print("Hello") + ``` + + Then set `ultrasonic.when_in_range` to the name of this function: + + ```python + ultrasonic.when_in_range = hello + ``` + ++ Add another function for when the sensor goes out of range: + + ```python + def bye(): + print("Bye") + + ultrasonic.when_out_of_range = bye + ``` + + Now these triggers are set up, you'll see "hello" printed when your hand is in range, and "bye" when it's out of range. + ++ You may have noticed that the sensor distance stopped at 1 metre. This is the default maximum and can also be configured on setup: + + ```python + ultrasonic = DistanceSensor(echo=17, trigger=4, max_distance=2) + ``` + + Or after setup: + + ```python + ultrasonic.max_distance = 2 + ``` + ++ Try different values of `max_distance` and `threshold_distance`. diff --git a/fr-FR/step_14.md b/fr-FR/step_14.md new file mode 100644 index 0000000..0e3c6b2 --- /dev/null +++ b/fr-FR/step_14.md @@ -0,0 +1,181 @@ +## Analogue inputs + +The Raspberry Pi's GPIO pins are digital pins, so you can only set outputs to high or low, or read inputs as high or low. However, using an ADC chip (Analogue-to-Digital converter), you can read the value of analogue input devices such as potentiometers. + +### SPI + +The analogue values are communicated to the Pi using the SPI protocol. While this will work in GPIO Zero out of the box, you may get better results if you enable full SPI support. + ++ Open a terminal window and install the `spidev` package: + + ```bash + sudo apt-get install python3-spidev python-spidev + ``` + ++ Open the **Raspberry Pi Configuration** dialogue from the main menu and enable **SPI** in the **Interfaces** tab: + + ![Enable SPI](images/rcgui.png) + ++ Click **OK** and reboot the Pi. + +### Wiring the ADC (MCP3008) + +The MCP3008 is an ADC providing eight input channels. The eight connectors on one side are connected to the Pi's GPIO pins, and the other eight are available to connect analogue input devices to read their values. + +Place the MCP3008 chip on a breadboard and carefully wire it up as shown in the following diagram. You should see a small notch, or dot, in one end of the chip. In the diagram, this end of the chip is alligned with column **19** on the breadboard. + +![MCP3008 wiring](images/mcp3008.png) + +Alternatively, you could use the [Analog Zero](http://rasp.io/analogzero/) board, which provides the MCP3008 chip on a handy add-on board to save you from the complicated wiring. + +### Add a potentiometer + +Now that the ADC is connected to the Pi, you can wire devices up to the input channels. A potentiometer is a good example of an analogue input device: it's simply a variable resistor, and the Pi reads the voltage (from 0V to 3.3V). + +![Potentiometer](images/potentiometer.png) + +A potentiometer's pins are ground, data, and 3V3. This means you connect it to ground and a supply of 3V3, and read the actual voltage from the middle pin. + ++ Place a potentiometer on the breadboard and wire one side to the ground rail, the other to the 3V3 rail, and the middle pin to the first input channel as shown: + + ![Add a potentiometer](images/mcp3008-pot.png) + +### Code + +Now your potentiometer is connected and its value can be read from Python! + ++ Open **Mu** from the main menu. + ++ Start by importing the `MCP3008` class from the GPIO Zero library: + + ```python + from gpiozero import MCP3008 + ``` + ++ Create an object representing your analogue device: + + ```python + pot = MCP3008(0) + ``` + + Note the `0` represents the ADC's channel 0. There are 8 channels (0 to 7), and you're using the first one. + ++ Try to read its value: + + ```python + print(pot.value) + ``` + ++ Run your code. You should see a number between 0 and 1. This represents how far the dial is turned. + ++ Now read the value in a loop: + + ```python + while True: + print(pot.value) + ``` + + Try twisting the dial around to see the value change. + +### PWMLED + +Now you've tested you can read values from the potentiometer, you should connect it to another GPIO device. + ++ Add an LED to your breadboard and wire it to the Pi, connecting it to GPIO pin 21: + + ![Add LED](images/mcp3008-pot-led.png) + ++ In your Python code, start by importing the `PWMLED` class: + + ```python + from gpiozero import PWMLED + ``` + + The `PWMLED` class lets you control the brightness of an LED using PWM, or pulse-width modulation. + ++ Create a `PWMLED` object on pin 21: + + ```python + led = PWMLED(21) + ``` + ++ Test you can control the LED manually: + + ```python + led.on() # the led should be lit + led.off() # the led should go off + led.value = 0.5 # the led should be lit at half brightness + ``` + ++ Now connect the LED to the potentiometer: + + ```python + led.source = pot.values + ``` + ++ Turn the dial to change the LED brightness! + +### Source and values + +GPIO Zero has a powerful feature: **source and values**. Every device has a `value` property (the current value) and a `values` property (a stream of the device's values at all times). Every output device has a `source` property which can be used to set what the device's value should be. + +- `pot.value` gives the potentiometer's current value (it's read only, as it's an input device) +- `led.value` is the LED's current value (it's read/write: you can see what it is, and you can change it) +- `pot.values` is a generator constantly yielding the potentiometer's current value +- `led.source` is a way of setting where the LED gets its values from + +Rather than continuously setting the value of the LED to the value of the potentiometer in a loop, you can just pair the two devices. Therefore the line `led.source = pot.values` is equivalent to the following loop: + +```python +while True: + led.value = pot.value +``` + +### Multiple potentiometers + ++ Add a second potentiometer to your breadboard and connect it to the ADC's channel 1: + + ![Second potentiometer](images/mcp3008-2pots-led.png) + ++ Now create a second `MCP3008` object on channel 1: + + ```python + pot2 = MCP3008(1) + ``` + ++ Make the LED blink: + + ```python + led.blink() + ``` + + The LED will blink continuously, one second on and one second off. + ++ Change the `on_time` and `off_time` parameters to make it blink faster or slower: + + ```python + led.blink(on_time=2, off_time=2) + led.blink(on_time=0.5, off_time=0.1) + ``` + ++ Now use a loop to change the blink times according to the potentiometer values: + + ```python + while True: + print(pot.value, pot2.value) + led.blink(on_time=pot.value, off_time=pot2.value, n=1, background=False) + ``` + + Note you have to make it blink once in the foreground, so that each iteration gets time to finish before it updates the blink times. + ++ Rotate the dials to make it blink at different speeds! + ++ Also try changing `blink` to `pulse` and change `on_time` and `off_time` to `fade_in_time` and `fade_out_time` so that it fades in and out at different speeds, rather than just blinking on and off: + + ```python + while True: + print(pot.value, pot2.value) + led.pulse(fade_in_time=pot.value, fade_out_time=pot2.value, n=1, background=False) + ``` + ++ Rotate the dials to change the effect. diff --git a/fr-FR/step_15.md b/fr-FR/step_15.md new file mode 100644 index 0000000..43e0e62 --- /dev/null +++ b/fr-FR/step_15.md @@ -0,0 +1,153 @@ +## Using motors + +Motors are great for physical computing: they allow you to turn a wheel forwards and backwards, or make something spin around. + +A motor can't be controlled directly from the Raspberry Pi's GPIO pins, because it needs a variable supply of 5 volts. This means you need to power it separately. However, motor controller add-on boards can be used to provide this functionality. + +In this guide, you'll be controlling two motors from your Raspberry Pi using Python on the desktop. First, it's best just to learn how to control the motor. Then, once you have it working, you could easily use your code to drive a Raspberry Pi-powered robot by detaching the monitor, mouse, and keyboard and building a robot around a chassis. + +### H bridge + +A motor can be driven forwards or backwards depending on which way around current flows through it. However, it would be awkward to have to rewire a motor, every time you want to change the direction it spins. To overcome this issue, motor controller boards include an H bridge. An H bridge uses 4 transistors to allow digital control of which way current flows through the motor. Most H bridges also contain *flyback diodes*. A flyback diode prevents the voltage spike that is generated by the motor when it is no longer powered (but still spinning) from damaging delicate electronics. + +![H-Bridge](images/h-bridge.png) + +*Image credit: [Wikipedia](https://en.wikipedia.org/wiki/H_bridge), CC BY-SA* + +### Wiring + +You'll need to wire up two motors and your battery pack using the motor controller. + ++ With your Pi switched off, mount your motor controller board on the GPIO pins: + + ![Motor controller board](images/mcb.png) + ++ Connect a battery pack to the power ports of the motor controller, connecting the positive (red) battery wire to the positive (+) power terminal on the motor controller, and the negative (black) battery wire to the negative (-) power terminal on the motor controller, and connect two motors: + + ![Connect battery pack](images/mcb-wiring.png) + ++ You'll need to know which GPIO pins your motor controller uses. Refer to the board's documentation. This will usually be described as Motor A and Motor B, or MA1, MA2, MB1, and MB2. Make a note of these pin numbers. If you're not sure which is which, you can investigate this next. + +### Motor class + +You can use the built-in `Motor` class to control motors. + ++ Import the `Motor` class: + + ```python + from gpiozero import Motor + ``` + ++ Now create a `Motor` instance using the pin numbers for each motor: + + ```python + motor1 = Motor(4, 14) + motor2 = Motor(17, 27) + ``` + + Note: to make it easier to see which pin is which, you can use `Motor(forward=4, backward=14)` for future reference. + ++ Now drive one of the motors forward using the following code: + + ```python + motor1.forward() + ``` + ++ And the other backwards: + + ```python + motor2.backward() + ``` + ++ Or try half speed: + + ```python + motor1.forward(0.5) + motor2.backward(0.5) + ``` + ++ The `Motor` class also allows you to reverse the motor's direction. Try using this loop: + + ```python + motor1.forward() + motor2.backward() + while True: + sleep(5) + motor1.reverse() + motor2.reverse() + ``` + + This will make the motors spin in opposite directions, then switch every five seconds. Press **Ctrl + C** to exit the loop. + ++ Now stop the motors: + + ```python + motor1.stop() + motor2.stop() + ``` + +### Robot class + +If you had a robot with two wheels you would want to control the two motors together, rather than separately, just like you did for the two pins of each motor. Luckily, there's also a `Robot` class in GPIO Zero. + ++ Import the `Robot` class: + + ```python + from gpiozero import Robot + ``` + ++ Now create a `Robot` instance using the pin numbers for each motor: + + ```python + robot = Robot((4, 14), (17, 27)) + ``` + + Note: to make it easier to see which pin is which, you can use `Robot(left=(4, 14), right=(17, 27))` for future reference. + ++ Now drive one of the motors forward using the following code: + + ```python + robot.forward() + ``` + + Both motors should now be driving forwards. + ++ And backwards: + + ```python + robot.backward() + ``` + + Both motors should now be driving backwards. + ++ Try reverse a few times: + + ```python + robot.reverse() + robot.reverse() + robot.reverse() + ``` + ++ Or try half speed: + + ```python + robot.forward(0.5) + ``` + ++ That's not all! What would happen if the left wheel went forwards and the right wheel went backwards? The robot would turn right. Try it: + + ```python + robot.right() + ``` + ++ Then try this: + + ```python + robot.left() + ``` + ++ Now stop the robot: + + ```python + robot.stop() + ``` diff --git a/fr-FR/step_16.md b/fr-FR/step_16.md new file mode 100644 index 0000000..1806a75 --- /dev/null +++ b/fr-FR/step_16.md @@ -0,0 +1,8 @@ +## What next? + +Try some of our other physical computing projects which use Python: + ++ [Burping jelly baby](https://projects.raspberrypi.org/en/projects/burping-jelly-baby) - turn a jelly baby into an input device for your Raspberry Pi. ++ [GPIO music box](https://projects.raspberrypi.org/en/projects/gpio-music-box) - make a device thats plays music when you push its buttons. ++ [Quick Reaction Game](https://projects.raspberrypi.org/en/projects/python-quick-reaction-game) - use electronics to create a quick reaction game which you will program using Python. ++ [Build a robot buggy](https://projects.raspberrypi.org/en/projects/build-a-buggy) - build a robot buggy that you can program to move around using simple Python commands. \ No newline at end of file diff --git a/fr-FR/step_2.md b/fr-FR/step_2.md new file mode 100644 index 0000000..111abaa --- /dev/null +++ b/fr-FR/step_2.md @@ -0,0 +1,27 @@ +## GPIO pins + +One powerful feature of the Raspberry Pi is the row of GPIO pins along the top edge of the board. GPIO stands for General-Purpose Input/Output. These pins are a physical interface between the Raspberry Pi and the outside world. At the simplest level, you can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output). + +The GPIO pins allow the Raspberry Pi to control and monitor the outside world by being connected to electronic circuits. The Pi is able to control LEDs, turning them on or off, run motors, and many other things. It's also able to detect whether a switch has been pressed, the temperature, and light. We refer to this as physical computing. + +There are 40 pins on the Raspberry Pi (26 pins on early models), and they provide various different functions. + +If you have a RasPiO pin label, it can help to identify what each pin is used for. Make sure your pin label is placed with the keyring hole facing the USB ports, pointed outwards. + +![](images/raspio-ports.jpg) + +If you don't have a pin label, then this guide can help you to identify the pin numbers: + +![](images/pinout.png) + +You'll see pins labelled as 3V3, 5V, GND and GP2, GP3, etc: + +| | | | +|---|---|---| +| 3V3 | 3.3 volts | Anything connected to these pins will always get 3.3V of power | +| 5V | 5 volts | Anything connected to these pins will always get 5V of power | +| GND | ground | Zero volts, used to complete a circuit | +| GP2 | GPIO pin 2 | These pins are for general-purpose use and can be configured as input or output pins | +| ID_SC/ID_SD/DNC | Special purpose pins || + +**WARNING**: If you follow the instructions, then playing about with the GPIO pins is safe and fun. Randomly plugging wires and power sources into your Pi, however, may destroy it, especially if using the 5V pins. Bad things can also happen if you try to connect things to your Pi that use a lot of power; LEDs are fine, motors are not. If you're worried about this, then you might want to consider using an add-on board such as the [Explorer HAT](https://shop.pimoroni.com/products/explorer-hat) until you're confident enough to use the GPIO directly. diff --git a/fr-FR/step_3.md b/fr-FR/step_3.md new file mode 100644 index 0000000..e707694 --- /dev/null +++ b/fr-FR/step_3.md @@ -0,0 +1,15 @@ +## Lighting an LED + +LEDs are delicate little things. If you put too much current through them they will pop (sometimes quite spectacularly). To limit the current going through the LED, you should always use a resistor in series with it. + +Try connecting the long leg of an LED to the Pi's 3V3 and the short leg to a GND pin. The resistor can be anything over about 50Ω. + +![](images/led-3v3.png) + +The LED should light up. It will always be on, because it's connected to a 3V3 pin, which is itself always on. + +Now try moving it from 3V3 to GPIO pin 17: + +![](images/led-gpio17.png) + +The LED should now turn off, but now it's on a GPIO pin, and can therefore be controlled by code. diff --git a/fr-FR/step_4.md b/fr-FR/step_4.md new file mode 100644 index 0000000..9905bc8 --- /dev/null +++ b/fr-FR/step_4.md @@ -0,0 +1,32 @@ +## Switching an LED on and off + +GPIO Zero is a new Python library which provides a simple interface to everyday GPIO components. It comes installed by default in Raspbian. + ++ Open Mu. + +[[[mu-open]]] + ++ You can switch an LED on and off by typing commands directly into the REPL. Click on the REPL button in the menu bar. + ++ First import the GPIO Zero library, and tell the Pi which GPIO pin you are using - in this case pin 17. + + ``` python + In [1]: from gpiozero import LED + In [2]: led = LED(17) + ``` + + Press **Enter** on the keyboard. + ++ To make the LED switch on, type the following and press **Enter**: + + ``` python + In [3]: led.on() + ``` + ++ To make it switch off you can type: + + ```python + In [4]: led.off() + ``` + ++ Your LED should switch on and then off again. But that's not all you can do. diff --git a/fr-FR/step_5.md b/fr-FR/step_5.md new file mode 100644 index 0000000..de7e433 --- /dev/null +++ b/fr-FR/step_5.md @@ -0,0 +1,26 @@ +## Flashing an LED + +With the help of the `time` library and a little loop, you can make the LED flash. + ++ Create a new file by clicking **New**. + ++ Save the new file by clicking **Save**. Save the file as `gpio_led.py`. + ++ Enter the following code to get started: + + ```python + from gpiozero import LED + from time import sleep + + led = LED(17) + + while True: + led.on() + sleep(1) + led.off() + sleep(1) + ``` + ++ Save the file and run the code with by clicking on **Run**. + ++ The LED should be flashing on and off. To exit the program click **Stop**. diff --git a/fr-FR/step_6.md b/fr-FR/step_6.md new file mode 100644 index 0000000..263ec86 --- /dev/null +++ b/fr-FR/step_6.md @@ -0,0 +1,29 @@ +## Using buttons to get input + +Now you're able to control an output component (an LED), let's connect and control an input component: a button. + ++ Connect a button to another GND pin and GPIO pin 2, like this: + + ![](images/button.png) + ++ Create a new file by clicking **New**. + ++ Save the new file by clicking **Save**. Save the file as `gpio_button.py`. + ++ This time you'll need the `Button` class, and to tell it that the button is on pin 2. Write the following code in your new file: + + ```python + from gpiozero import Button + button = Button(2) + ``` + ++ Now you can get your program to do something when the button is pushed. Add these lines: + + ```python + button.wait_for_press() + print('You pushed me') + ``` + ++ Save and run the code. + ++ Press the button and your text will appear. diff --git a/fr-FR/step_7.md b/fr-FR/step_7.md new file mode 100644 index 0000000..57b1ab3 --- /dev/null +++ b/fr-FR/step_7.md @@ -0,0 +1,24 @@ +## Manually controlling the LED + +You can now combine your two programs written so far to control the LED using the button. + ++ Create a new file by clicking **New**. + ++ Save the new file by clicking **Save**. Save the file as `gpio_control.py`. + ++ Now write the following code: + + ```python + from gpiozero import LED, Button + from time import sleep + + led = LED(17) + button = Button(2) + + button.wait_for_press() + led.on() + sleep(3) + led.off() + ``` + ++ Save and run your program. When you push the button the LED should come on for three seconds. diff --git a/fr-FR/step_8.md b/fr-FR/step_8.md new file mode 100644 index 0000000..e193765 --- /dev/null +++ b/fr-FR/step_8.md @@ -0,0 +1,39 @@ +## Making a switch + +With a switch, a single press and release on the button would turn the LED on, and another press and release would turn it off again. + ++ Modify your code so that it looks like this: + + ```python + from gpiozero import LED, Button + from time import sleep + + led = LED(17) + button = Button(2) + + while True: + button.wait_for_press() + led.toggle() + sleep(0.5) + ``` + + `led.toggle()` switches the state of the LED from on to off, or off to on. Since this happens in a loop the LED will turn on and off each time the button is pressed. + ++ It would be great if you could make the LED switch on only when the button is being held down. With GPIO Zero, that's easy. There are two methods of the `Button` class called `when_pressed` and `when_released`. These don't block the flow of the program, so if they are placed in a loop, the program will continue to cycle indefinitely. + ++ Modify your code to look like this: + + ```python + from gpiozero import LED, Button + from signal import pause + + led = LED(17) + button = Button(2) + + button.when_pressed = led.on + button.when_released = led.off + + pause() + ``` + ++ Save and run the program. Now when the button is pressed, the LED will light up. It will turn off again when the button is released. diff --git a/fr-FR/step_9.md b/fr-FR/step_9.md new file mode 100644 index 0000000..cf9feef --- /dev/null +++ b/fr-FR/step_9.md @@ -0,0 +1,44 @@ +## Using a buzzer + +There are two main types of buzzer: *active* and *passive*. + +A *passive* buzzer emits a tone when a voltage is applied across it. It also requires a specific signal to generate a variety of tones. The *active* buzzers are a lot simpler to use, so these are covered here. + +### Connecting a buzzer + +An *active* buzzer can be connected just like an LED, but as they are a little more robust, you won't be needing a resistor to protect them. + +Set up the circuit as shown below: + +![buzzer](images/buzzer-circuit.png) + ++ Add `Buzzer` to the `from gpiozero import...` line: + + ```python + from gpiozero import Buzzer + from time import sleep + ``` + ++ Add a line below your creation of `button` and `lights` to add a `Buzzer` object: + + ```python + buzzer = Buzzer(17) + ``` + ++ In GPIO Zero, a `Buzzer` works exactly like an `LED`, so try adding a `buzzer.on()` and `buzzer.off()` into your loop: + + ```python + while True: + buzzer.on() + sleep(1) + buzzer.off() + sleep(1) + + ``` + ++ A `Buzzer` has a `beep()` method which works like an `LED`'s `blink`. Try it out: + + ```python + while True: + buzzer.beep() + ```