issue110: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 | ||
issue110:python [2016/07/10 08:02] – d52fr | issue110:python [2016/07/10 17:59] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
Wiring a single sensor is very easy. Shown right is the diagram.** | Wiring a single sensor is very easy. Shown right is the diagram.** | ||
- | Ce mois-ci, nous utiliserons mon capteur de température favori actuellement : le capteur Dallas Semiconductor DS18B20 One Wire. Il ressemble à un transistor « ordinaire », mais c'est un capteur très précis, beaucoup plus que le DHT11 utilisé le mois dernier. Il ne fait pas l' | + | Ce mois-ci, nous utiliserons mon capteur de température favori actuellement : le capteur Dallas Semiconductor DS18B20 One Wire. Il ressemble à un transistor « ordinaire », mais c'est un capteur très précis, beaucoup plus que le DHT11 utilisé le mois dernier. Il ne fait pas l' |
- | La feuille de spécifications peut être trouvée sur : https:// | + | La feuille de spécifications peut être trouvée sur : https:// |
+ | |||
+ | Le câblage d'un seul capteur est facile. Voir le dessin à droite. | ||
**There are only three connections to the RPi. Ground (sensor pin 1) to RPi pin 6, 3.3v (sensor pin 3) to RPi pin 1, and data (sensor pin 2) to RPI pin 7 (GPIO 4). You need to put a 4.7k resistor between sensor pins 2 and 3 (data and +Voltage). That’s it. If you wish to add more sensors to the project, simply connect them ground to ground, +voltage to +voltage and pin 2 to pin 2 of the “main” sensor. No additional resistors should be needed for a reasonable line length. Next page, right-hand side, is an example of a three sensor project. | **There are only three connections to the RPi. Ground (sensor pin 1) to RPi pin 6, 3.3v (sensor pin 3) to RPi pin 1, and data (sensor pin 2) to RPI pin 7 (GPIO 4). You need to put a 4.7k resistor between sensor pins 2 and 3 (data and +Voltage). That’s it. If you wish to add more sensors to the project, simply connect them ground to ground, +voltage to +voltage and pin 2 to pin 2 of the “main” sensor. No additional resistors should be needed for a reasonable line length. Next page, right-hand side, is an example of a three sensor project. | ||
Ligne 14: | Ligne 16: | ||
One thing you have to do is tell the operating system you want to use kernel support for one-wire devices. If you are using Raspbian Jessie, this is done in raspi-config. If you are using another OS, then you must add the following line to the / | One thing you have to do is tell the operating system you want to use kernel support for one-wire devices. If you are using Raspbian Jessie, this is done in raspi-config. If you are using another OS, then you must add the following line to the / | ||
+ | |||
+ | Il n'y a que trois connexions au RPi. La masse (picot 1 du capteur) vers le picot 6 du RPi, 3,3 V (picot 3 du capteur) vers le picot 1 du RPi, et les données (picot 2 du capteur) vers le picot 7 du RPi (GPIO 4). Vous avez besoin d'une résistance de 4,7 k entre les picots 2 et 3 du capteur (données et alim +). C'est tout. Si vous souhaitez ajouter d' | ||
+ | |||
+ | Le code | ||
+ | |||
+ | Vous devez dire au système d' | ||
**dtoverlay=w1-gpio | **dtoverlay=w1-gpio | ||
Ligne 30: | Ligne 38: | ||
In the device drivers, your sensor should be listed as a series of numbers and letters. In this case, the device is registered as 28-000005e2fdc3. You then need to access the sensor with the cd command, replacing our serial number with your own.** | In the device drivers, your sensor should be listed as a series of numbers and letters. In this case, the device is registered as 28-000005e2fdc3. You then need to access the sensor with the cd command, replacing our serial number with your own.** | ||
+ | |||
+ | dtoverlay=w1-gpio | ||
+ | |||
+ | Les deux commandes suivantes chargent les pilotes du 1-fil et du thermomètre sur GPIO 4. | ||
+ | |||
+ | sudo modprobe w1-gpio | ||
+ | |||
+ | sudo modprobe w1-therm | ||
+ | |||
+ | Puis vous devez modifier le répertoire (cd) pour le répertoire du composant 1-fil et lister (ls) les appareils pour vérifier que votre thermomètre est chargé correctement. | ||
+ | |||
+ | cd / | ||
+ | |||
+ | ls | ||
+ | |||
+ | Dans les pilotes des matériels, votre capteur doit être listé comme une série de chiffres et de lettres. Dans mon cas, le composant est enregistré comme 28-000005e2fdc3. Vous devez ensuite accéder au capteur avec la commande cd, en remplaçant mon numéro de série par le vôtre. | ||
**cd 28-000005e2fdc3 | **cd 28-000005e2fdc3 | ||
Ligne 44: | Ligne 68: | ||
Next page, top right, is how we had to do it in the “old days”, the library that we will actually use.** | Next page, top right, is how we had to do it in the “old days”, the library that we will actually use.** | ||
+ | |||
+ | cd 28-000005e2fdc3 | ||
+ | |||
+ | Le capteur écrit périodiquement dans le fichier w1_slave ; aussi, nous utilisons simplement la commande cat pour le lire. | ||
+ | |||
+ | cat w1_slave | ||
+ | |||
+ | Ceci nous amène aux deux lignes de texte suivantes, avec la sortie t= montrant la température en degrés Celsius. Un point décimal devrait être placé avant les trois derniers digits ; par exemple, la température que nous avons reçue se lit 23.125 degrés Celsius. | ||
+ | |||
+ | 72 01 4b 46 7f ff 0e 10 57 : crc=57 YES | ||
+ | |||
+ | 72 01 4b 46 7f ff 0e 10 57 t=23125 | ||
+ | |||
+ | À la page suivante, en haut à droite, vous pouvez voir comment il aurait fallu faire « jadis », la bibliothèque que nous allons utiliser réellement. | ||
**Timo Furrer has provided a wonderful library for us to use on the RPi written in pure Python. You can get it at https:// | **Timo Furrer has provided a wonderful library for us to use on the RPi written in pure Python. You can get it at https:// | ||
Ligne 54: | Ligne 92: | ||
As I mentioned above, you can have more than one sensor on the same data line. So here is the code to make a single call to get the temp readings from all sensors in the system…** | As I mentioned above, you can have more than one sensor on the same data line. So here is the code to make a single call to get the temp readings from all sensors in the system…** | ||
+ | |||
+ | Timo Furrer nous a fourni une bibliothèque fantastique, | ||
+ | |||
+ | La beauté de cette bibliothèque vient de ce qu' | ||
+ | |||
+ | Voyez le code « d' | ||
+ | |||
+ | Seulement 7 lignes de code sont nécessaires ici. Les lignes qui sont commentées vous permettent de voir les autres façons d' | ||
+ | |||
+ | Comme indiqué plus haut, vous pouvez avoir plus d'un capteur sur la même ligne de données. Aussi, voici le code pour un appel unique qui récupère les valeurs de température de tous les capteurs du système. | ||
**from w1thermsensor import W1ThermSensor | **from w1thermsensor import W1ThermSensor | ||
Ligne 70: | Ligne 118: | ||
temperature_in_celsius = sensor.get_temperature()** | temperature_in_celsius = sensor.get_temperature()** | ||
+ | |||
+ | from w1thermsensor import W1ThermSensor | ||
+ | |||
+ | for sensor in W1ThermSensor.get_available_sensors(): | ||
+ | |||
+ | print(" | ||
+ | | ||
+ | Bien sûr, vous voudrez faire plus d'un appel de données ; modifiez donc le code ci-dessus de la façon que vous souhaitez. | ||
+ | |||
+ | Si vous voulez faire appel à un capteur en particulier, | ||
+ | |||
+ | from w1thermsensor import W1ThermSensor | ||
+ | |||
+ | sensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, | ||
+ | |||
+ | temperature_in_celsius = sensor.get_temperature() | ||
**So, you can see, by using Timo‘s library, we can basically go from 27 lines of code to 3 (for a single call). That’s wonderful. | **So, you can see, by using Timo‘s library, we can basically go from 27 lines of code to 3 (for a single call). That’s wonderful. | ||
Ligne 76: | Ligne 140: | ||
Until then, enjoy checking out the temperatures around your office/ | Until then, enjoy checking out the temperatures around your office/ | ||
+ | |||
+ | Ainsi, vous pouvez voir qu'en utilisant la bibliothèque de Timo Furrer vous réduisez votre code de 27 lignes à 3 (pour un seul appel). C'est merveilleux ! | ||
+ | |||
+ | Je voulais vous montrer comment utiliser l' | ||
+ | |||
+ | En attendant, amusez-vous à vérifier la température de votre bureau/ |
issue110/python.1468130549.txt.gz · Dernière modification : 2016/07/10 08:02 de d52fr