issue109:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue109:python [2016/06/13 20:53] – d52fr | issue109:python [2016/06/15 14:45] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
As I was laying last week, waiting for some surgery, I was thinking that if someone were to come up to me and ask directly why I’m doing this, what my answer would be. Before the wonderful chemicals they pumped into my body to make the process less horrible, I realized that the REAL reason is multi-part. First, is to create excitement in “non-programmers” when doing things that seemingly could not be done without a ton of training. Secondly, is to show that the newer technology, like the Raspberry Pi and the Arduino, is not beyond the ken of the “general joe” out there, but that anyone can do things that have real world applications (hence the title of our series). That having been said, making LEDs blink is only the same kind of project for the hardware world as the “Hello World” program is in the programming realm. You have to take small steps before you move to the big race. Believe me, we will be doing some amazing things with all those little parts, whatsits and thingamabobs.** | As I was laying last week, waiting for some surgery, I was thinking that if someone were to come up to me and ask directly why I’m doing this, what my answer would be. Before the wonderful chemicals they pumped into my body to make the process less horrible, I realized that the REAL reason is multi-part. First, is to create excitement in “non-programmers” when doing things that seemingly could not be done without a ton of training. Secondly, is to show that the newer technology, like the Raspberry Pi and the Arduino, is not beyond the ken of the “general joe” out there, but that anyone can do things that have real world applications (hence the title of our series). That having been said, making LEDs blink is only the same kind of project for the hardware world as the “Hello World” program is in the programming realm. You have to take small steps before you move to the big race. Believe me, we will be doing some amazing things with all those little parts, whatsits and thingamabobs.** | ||
- | Le mois dernier, je vous suggérais de vous procurer un certain nombre de pièces et si vous avez été capable de les avoir, j' | + | Le mois dernier, je vous suggérais de vous procurer un certain nombre de pièces et si vous avez été capable de les avoir, j' |
- | Alors que j' | + | Alors que j' |
**This month, we will be using the DHT11 Basic Temperature/ | **This month, we will be using the DHT11 Basic Temperature/ | ||
Enough about the future. Let’s start with this month' | Enough about the future. Let’s start with this month' | ||
+ | |||
+ | Ce mois-ci, nous utiliserons le capteur de température/ | ||
+ | |||
+ | C'est assez pour le futur. Commençons notre projet du mois. | ||
**The DHT11 is the least expensive sibling of a series of temperature and humidity sensor sets. The DHT11 has a temperature range from 0⁰ to 50⁰ C with ±2⁰ C accuracy (32⁰ to 122⁰ F, ±3.6⁰F) and a humidity range from 20-90%RH ±5%. You can see that it’s not the most accurate sensor on the market; there is a DHT22 that is more accurate and has a wider range (-40⁰ to 80⁰ C temp range) but about twice as expensive. | **The DHT11 is the least expensive sibling of a series of temperature and humidity sensor sets. The DHT11 has a temperature range from 0⁰ to 50⁰ C with ±2⁰ C accuracy (32⁰ to 122⁰ F, ±3.6⁰F) and a humidity range from 20-90%RH ±5%. You can see that it’s not the most accurate sensor on the market; there is a DHT22 that is more accurate and has a wider range (-40⁰ to 80⁰ C temp range) but about twice as expensive. | ||
Ligne 16: | Ligne 20: | ||
Whenever you want to work with a new sensor, you should get a spec sheet (data sheet). A simple web search should turn up a number of results. Try to get something directly from the manufacturer if at all possible. For the DHT11, a good place to get one of the various data sheets available is http:// | Whenever you want to work with a new sensor, you should get a spec sheet (data sheet). A simple web search should turn up a number of results. Try to get something directly from the manufacturer if at all possible. For the DHT11, a good place to get one of the various data sheets available is http:// | ||
+ | |||
+ | Le DHT11 est l' | ||
+ | |||
+ | C'est une drôle de pièce. Un boîtier plastique rectangulaire bleu avec des trous et quelque chose de brillant à l' | ||
+ | |||
+ | Chaque fois que vous voulez travailler avec un nouveau capteur, vous devrez prendre la feuille de spécifications (la « data sheet »). Une simple recherche sur le Web devrait retourner un bon nom de résultats. Essayez de trouver quelque chose venant directement du fabricant si c'est possible. Pour le DHT11, un bon endroit pour se procurer une des nombreuses data sheets disponibles est http:// | ||
**You might already be asking, why do I need this? There’s a bunch of information that, unless you have a PhD in Physics or something, you’ll never need. Well, that is true, but there is a lot of information that IS relevant and can potentially keep you from blowing up either the sensor, the controller, or your work bench. In this case, we find that the DC operating voltage is between 3 to 5 volts and it pulls about 0.5mA during “normal” conditions (section 6). We also find that this is a rather slow device and that we should not try to pull data more than once per second. Basically we’ll keep it around once every five seconds in our testing program, which is way more than we’ll need in reality. Another thing: if the cable that sends the data from the sensor to the microcontroller (our RPi) is less than 20 meters, we should have about a 5K ohm resistor between the data line and the local power supply (at the sensor) as a pull-up. One last thing (I’m going to stop here, but there’s much more): Pin 1 is positive voltage, Pin 2 is the data pin, and Pin 4 is the ground pin. This gives us pretty much everything we need to know to safely connect this to our RPi. Below is the wiring diagram for a “raw” DHT11 sensor WITHOUT a breakout board. If you have a sensor with a breakout board, see my discussion below the diagram.** | **You might already be asking, why do I need this? There’s a bunch of information that, unless you have a PhD in Physics or something, you’ll never need. Well, that is true, but there is a lot of information that IS relevant and can potentially keep you from blowing up either the sensor, the controller, or your work bench. In this case, we find that the DC operating voltage is between 3 to 5 volts and it pulls about 0.5mA during “normal” conditions (section 6). We also find that this is a rather slow device and that we should not try to pull data more than once per second. Basically we’ll keep it around once every five seconds in our testing program, which is way more than we’ll need in reality. Another thing: if the cable that sends the data from the sensor to the microcontroller (our RPi) is less than 20 meters, we should have about a 5K ohm resistor between the data line and the local power supply (at the sensor) as a pull-up. One last thing (I’m going to stop here, but there’s much more): Pin 1 is positive voltage, Pin 2 is the data pin, and Pin 4 is the ground pin. This gives us pretty much everything we need to know to safely connect this to our RPi. Below is the wiring diagram for a “raw” DHT11 sensor WITHOUT a breakout board. If you have a sensor with a breakout board, see my discussion below the diagram.** | ||
+ | |||
+ | Vous devrez déjà vous demander : pourquoi en ai-je besoin ? C'est un ensemble d' | ||
**Notice that I said earlier that a 5K resistor was needed as a pull-up. If you are going to use 3.3 VDC as a power source (RPi pin 1), then a 5K resistor works pretty well. If, however, you are going to use 5 VDC as shown in the diagram, use a 10K resistor. | **Notice that I said earlier that a 5K resistor was needed as a pull-up. If you are going to use 3.3 VDC as a power source (RPi pin 1), then a 5K resistor works pretty well. If, however, you are going to use 5 VDC as shown in the diagram, use a 10K resistor. | ||
Ligne 24: | Ligne 36: | ||
If you have a DHT11 on a breakout board, you will likely have only 3 output pins on it. I have two sensors from different vendors, and (go figure) both have a different pinout. One is laid out [Data] [Positive Voltage] [Ground] and is marked “S -”. The other is [Ground] [Data] [Positive Voltage] and is marked as such. Hopefully, yours has some sort of pinout definition printed on it. If not, you can use a multimeter to trace the ground pin and voltage pin directly from the sensor to the breakout pin. You can usually guess that if there are three output pins on the breakout board and you know ground and positive voltage, then the other SHOULD be the data pin.** | If you have a DHT11 on a breakout board, you will likely have only 3 output pins on it. I have two sensors from different vendors, and (go figure) both have a different pinout. One is laid out [Data] [Positive Voltage] [Ground] and is marked “S -”. The other is [Ground] [Data] [Positive Voltage] and is marked as such. Hopefully, yours has some sort of pinout definition printed on it. If not, you can use a multimeter to trace the ground pin and voltage pin directly from the sensor to the breakout pin. You can usually guess that if there are three output pins on the breakout board and you know ground and positive voltage, then the other SHOULD be the data pin.** | ||
+ | |||
+ | Notez que j'ai dit avant qu'il y avait besoin d'une résistance de tirage de 5kΩ. Si vous utilisez une alimentation de 3,3 V DC (le picot 1 du RPi), alors la résistance de 5kΩ marche bien. Cependant, si vous choisissez 5 V DC, comme sur le schéma, utilisez une résistance de 10kΩ. | ||
+ | |||
+ | Vous pouvez voir que c'est plutôt simple, juste trois fils et une résistance. Pour notre projet simpliste, cependant, n' | ||
+ | |||
+ | Si votre DHT11 est sur circuit, vous devriez avoir au moins 3 picots. J'ai deux capteurs de marchands différents et (allez savoir pourquoi) ils ont une disposition des picots différente. Sur l'un je trouve [Data] (données) [Positive Voltage] (alim +) [Ground] (alim -) et c'est marqué « S - ». Pour l' | ||
**Now our program code. | **Now our program code. | ||
Ligne 40: | Ligne 58: | ||
Ignore any errors that state a package is already installed.** | Ignore any errors that state a package is already installed.** | ||
+ | |||
+ | Maintenant, notre code de programme. | ||
+ | |||
+ | Pour une mise en route rapide, nous utiliserons du code fourni par des gens sur Adafruit.com - ils fournissent une bibliothèque fonctionnant avec le DHT11. (Ils trouvent que d' | ||
+ | |||
+ | Dans votre répertoire « /home/pi », lancez les commandes suivantes : | ||
+ | |||
+ | git clone https:// | ||
+ | |||
+ | cd Adafruit_Python_DHT | ||
+ | |||
+ | sudo apt-get update | ||
+ | |||
+ | sudo apt-get install build-essential python-dev python-openssl | ||
+ | |||
+ | Ignorez toutes les erreurs qui font état d'un paquet déjà installé. | ||
**Next, install the library by running: | **Next, install the library by running: | ||
Ligne 55: | Ligne 89: | ||
Here we define that the sensor is connected to GPIO pin 4 and then we wait 3 seconds for things to settle and be ready to work.** | Here we define that the sensor is connected to GPIO pin 4 and then we wait 3 seconds for things to settle and be ready to work.** | ||
+ | |||
+ | Ensuite, installez la bibliothèque en lançant : | ||
+ | |||
+ | sudo python setup.py install | ||
+ | |||
+ | Une fois que tout est fait, vous pouvez passer à notre code exemple. | ||
+ | |||
+ | Ci-dessus, voici mon échantillon de code modifié, « emprunté » au code exemple d' | ||
+ | |||
+ | Tout ce qui est au-dessus pourrait être réduit à trois lignes de code. Les deux déclarations d' | ||
+ | |||
+ | pin = 4 | ||
+ | sleep(3) | ||
+ | |||
+ | Ici, nous définissons que le capteur est connecté au picot 4 du GPIO et que nous attendons 3 secondes pour que tout s' | ||
**We use a simple loop (next page, top right) to grab the values for humidity and temp over and over. I never got the knack of relating Celsius to “real” temperatures, | **We use a simple loop (next page, top right) to grab the values for humidity and temp over and over. I never got the knack of relating Celsius to “real” temperatures, | ||
Ligne 65: | Ligne 114: | ||
Have a good time and I’ll see you next month.** | Have a good time and I’ll see you next month.** | ||
+ | |||
+ | Nous utilisons une simple boucle (page suivante, en haut à droite) pour récupérer les valeurs d' | ||
+ | |||
+ | Maintenant (page suivante, en bas à droite), nous vérifions que les valeurs de température et d' | ||
+ | |||
+ | Je dois admettre que, quand je lance le programme avec un certain capteur, j' | ||
+ | |||
+ | Bon, c'est tout pour ce mois-ci. Souvenez-vous que, la prochaine fois, nous utiliserons le capteur de température de Dallas ; soyez prêt. | ||
+ | |||
+ | Amusez-vous bien et au mois prochain. | ||
issue109/python.1465844037.txt.gz · Dernière modification : 2016/06/13 20:53 de d52fr