issue123:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue123:python [2017/07/29 10:43] – créée d52fr | issue123:python [2017/08/10 10:55] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | In the last few days, I have seen at least two projects on the web that deal with Raspberry Pi producing music. I’ve seen many over the years, but with two showing up on my virtual doorstep, I took it as a sign. With music being one of my hobbies, I decided that we would start a project that would look into using a RPi as a controller, based on a project called the Music Box. More information can be found at http:// | + | **In the last few days, I have seen at least two projects on the web that deal with Raspberry Pi producing music. I’ve seen many over the years, but with two showing up on my virtual doorstep, I took it as a sign. With music being one of my hobbies, I decided that we would start a project that would look into using a RPi as a controller, based on a project called the Music Box. More information can be found at http:// |
With that in mind, one of the libraries that his project uses is the GPIOZERO library. I’ve mentioned this in the past, but have never really dealt with it in any depth. So, I thought a good starting point would be to spend this month in examining this library in detail by doing some simple LED type projects. That way, when we get to the actual hardware and software portion, we will all know some of the commands from its API. | With that in mind, one of the libraries that his project uses is the GPIOZERO library. I’ve mentioned this in the past, but have never really dealt with it in any depth. So, I thought a good starting point would be to spend this month in examining this library in detail by doing some simple LED type projects. That way, when we get to the actual hardware and software portion, we will all know some of the commands from its API. | ||
- | All of these projects are taken from the GPIOZERO documentation (http:// | + | All of these projects are taken from the GPIOZERO documentation (http:// |
- | GPIOZERO is a collection of classes to make accessing some of the most common input and output devices like LEDs and buttons super easy. It also gives easy support for things like Analogue-to-Digital converters, proximity sensors, motion detectors and so much more. | + | Au cours des derniers jours, j'ai vu au moins deux projets sur le Web qui traitent de la production de musique par le Raspberry Pi. J'en ai vu pas mal au fil des ans, mais, puisque ces deux se sont pointés devant ma porte virtuelle, je l'ai pris pour un signe. La musique étant l'un de mes violons d' |
+ | |||
+ | En gardant cela à l' | ||
+ | |||
+ | J'ai trouvé tous ces projets dans la documentation de GPIOZERO (http:// | ||
+ | |||
+ | **GPIOZERO is a collection of classes to make accessing some of the most common input and output devices like LEDs and buttons super easy. It also gives easy support for things like Analogue-to-Digital converters, proximity sensors, motion detectors and so much more. | ||
Traffic Signal | Traffic Signal | ||
Ligne 17: | Ligne 23: | ||
The code is very simple (next page, top right). | The code is very simple (next page, top right). | ||
- | The line “lights = TrafficLights(2, | + | The line “lights = TrafficLights(2, |
- | Button LED | + | GPIOZERO est une collection de classes pour faciliter au maximum l' |
+ | |||
+ | Feux de signalisation | ||
+ | |||
+ | Pour ce projet, nous aurons besoin de 3 LED (une verte, une orange/ | ||
+ | |||
+ | Les cathodes des LED sont toutes connectées au bus de masse. L' | ||
+ | |||
+ | Vous trouverez le diagramme Fritzing ci-dessous. | ||
+ | |||
+ | Le code est très simple (page suivante, en haut à droite). | ||
+ | |||
+ | La ligne « lights = TrafficLights(2, | ||
+ | |||
+ | **Button LED | ||
For this project, we’ll need one LED of any colour, one 220 ohm resistor, a button, a breadboard,, | For this project, we’ll need one LED of any colour, one 220 ohm resistor, a button, a breadboard,, | ||
Ligne 27: | Ligne 47: | ||
The code for this project is even simpler (bottom right). | The code for this project is even simpler (bottom right). | ||
- | Notice in this project we don’t have a while True loop that keeps the code going. That’s because we are using the pause routine from the signal library. The button functions are referred to as callbacks that are “triggered” when the specified action (pressed or released) happens. | + | Notice in this project we don’t have a while True loop that keeps the code going. That’s because we are using the pause routine from the signal library. The button functions are referred to as callbacks that are “triggered” when the specified action (pressed or released) happens.** |
- | Potentiometer | + | LED par bouton-poussoir |
+ | |||
+ | Il faut, pour ce projet, une LED de n' | ||
+ | |||
+ | Comme dans le projet précédent, | ||
+ | |||
+ | Le code en est encore plus simple (en bas à droite). | ||
+ | |||
+ | Remarquez que ce projet ne comporte pas de boucle while True qui entretient le code. C'est parce que nous utilisons la routine pause de la bibliothèque signal. Les fonctions du bouton s' | ||
+ | |||
+ | **Potentiometer | ||
We’ve talked before about the fact the RPi doesn’t have any analogue inputs. In this project we will be using a MCP3008 Analogue to Digital converter chip to handle the heavy lifting for us. | We’ve talked before about the fact the RPi doesn’t have any analogue inputs. In this project we will be using a MCP3008 Analogue to Digital converter chip to handle the heavy lifting for us. | ||
Ligne 41: | Ligne 71: | ||
• GPIO 9 (physical pin 21 SPI MISO) -> MCP3008 pin 12 (Dout) | • GPIO 9 (physical pin 21 SPI MISO) -> MCP3008 pin 12 (Dout) | ||
• GPIO 10 (physical pin 19 SPI MOSI) -> MCP3008 pin 11 (Din) | • GPIO 10 (physical pin 19 SPI MOSI) -> MCP3008 pin 11 (Din) | ||
- | • GPIO 8 (physical pin 24 SPI SCLK) -> MCP3008 pin 10 (CS (Chip Select)) | + | • GPIO 8 (physical pin 24 SPI SCLK) -> MCP3008 pin 10 (CS (Chip Select))** |
- | The anodes of the LEDs are all connected through resistors to the RPi GPIO pins, and the cathodes are all connected to the ground buss. The GPIO pins are 5, 6, 13, 19, 26 which are physical pins 29,31,33,35 and 37. The MCP3008 is connected to the 3.3VDC output of the RPi on pins 16 and 15, and to ground on pins 14 and 9. | + | Potentiomètre |
+ | |||
+ | Nous avons déjà parlé du fait que le RPi n'a pas d' | ||
+ | |||
+ | Pour ce qui concerne le matériel, ce projet est plus compliqué que les deux précédents, | ||
+ | |||
+ | Pour ce projet, il faut 5 LED, 5 résistances de 220 Ω, un potentiomètre 10 K, un circuit de conversion analogique/ | ||
+ | |||
+ | Le MCP3008 est un convertisseur analogique/ | ||
+ | • GPIO 11 (broche physique 23 SPI CE0) -> MCP3008 broche 13 (CLK). | ||
+ | • GPIO 9 (broche physique 21 SPI MISO) -> MCP3008 broche 12 (Dout). | ||
+ | • GPIO 10 (broche physique 19 SPI MOSI) -> MCP3008 brouche 11 (Din). | ||
+ | • GPIO 8 (broche physique 24 SPI SCLK) -> MCP3008 broche 10 (CS (Chip Select)). | ||
+ | |||
+ | **The anodes of the LEDs are all connected through resistors to the RPi GPIO pins, and the cathodes are all connected to the ground buss. The GPIO pins are 5, 6, 13, 19, 26 which are physical pins 29,31,33,35 and 37. The MCP3008 is connected to the 3.3VDC output of the RPi on pins 16 and 15, and to ground on pins 14 and 9. | ||
As I said earlier, the code is pretty simple and straightforward (above). | As I said earlier, the code is pretty simple and straightforward (above). | ||
Ligne 51: | Ligne 95: | ||
The LEDBarGraph class provides a simple way to have a value displayed by a number of LEDs (in our case 5 LEDs, but can be just about any number). By using the “pwm=True” parameter, the LEDs will fade on or off in response to the input value, which can be between -1 and 1. Positive values cause the LEDs to light from left to right, and negative values from right to left. | The LEDBarGraph class provides a simple way to have a value displayed by a number of LEDs (in our case 5 LEDs, but can be just about any number). By using the “pwm=True” parameter, the LEDs will fade on or off in response to the input value, which can be between -1 and 1. Positive values cause the LEDs to light from left to right, and negative values from right to left. | ||
- | Next month we will be starting the Music Box. Until then, enjoy playing with the GPIOZERO library. | + | Next month we will be starting the Music Box. Until then, enjoy playing with the GPIOZERO library.** |
+ | |||
+ | Les anodes des LED sont toutes connectées aux broches GPIO du RPi en passant par des résistances et les cathodes sont toutes connectées au bus de masse. Les broches GPIO sont 5, 6, 13, 19, 26, autrement dit les broches physiques 29, 31, 33, 35 et 37. Le MCP3008 est connecté à la sortie 3,3VDC du RPi sur les broches 16 et 15 et à la masse sur les broches 14 et 9. | ||
+ | |||
+ | Comme j'ai dit plus tôt, le code est assez simple (ci-dessus). | ||
+ | |||
+ | J'ai choisi cet exemple parce que nous utiliserons le MCP3008 dans le projet suivant. À nouveau, nous utilisons la routine signal.pause pour créer une boucle continue jusqu' | ||
+ | |||
+ | La classe LEDBarGraph fournit une façon simple de faire afficher une valeur par de nombreuses LED (dans notre cas, 5 LED, mais à peu près n' | ||
+ | |||
+ | Le mois prochain, nous commencerons la boîte à musique. En attendant, amusez-vous bien avec la bibliothèque GPIOZERO. | ||
issue123/python.1501317808.txt.gz · Dernière modification : 2017/07/29 10:43 de d52fr