issue120: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 | ||
issue120:python [2017/05/14 10:25] – d52fr | issue120:python [2017/05/16 10:00] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 6: | Ligne 6: | ||
We’ll use the HC-06 Bluetooth module, which you can find on the web for around $3.00 US or less. While this isn’t the best module to use, it will do the job for our projects. When I purchased mine, the HC-06 was much cheaper than the more capable HC-05, but the prices have pretty much evened out. The code and breadboard layout should work for either of them.** | We’ll use the HC-06 Bluetooth module, which you can find on the web for around $3.00 US or less. While this isn’t the best module to use, it will do the job for our projects. When I purchased mine, the HC-06 was much cheaper than the more capable HC-05, but the prices have pretty much evened out. The code and breadboard layout should work for either of them.** | ||
+ | |||
+ | D' | ||
+ | |||
+ | Le mois dernier, je terminais mon article en disant que la solution de Firmata ne fonctionnera qu' | ||
+ | |||
+ | Ce mois-ci, je commencerai par vous montrer comment utiliser un module bluetooth bon marché pour en faire une réalité. | ||
+ | |||
+ | Nous utiliserons le module Bluetooth HC-06, que vous pouvez trouver sur le Web pour environ 3 $, voire moins. Alors que ce n'est pas le meilleur module à utiliser, il conviendra pour nos projets. Quand j'ai acheté le mien, le HC-06 était beaucoup moins cher que le HC-05 plus puissant, mais les prix peuvent s' | ||
**We’ll also be using a DHT22 DIgital Humidity and Temperature module as our sensor. We’ve played with the DHT series of modules before in earlier articles. | **We’ll also be using a DHT22 DIgital Humidity and Temperature module as our sensor. We’ve played with the DHT series of modules before in earlier articles. | ||
Ligne 12: | Ligne 20: | ||
Also, the HC-06 Module needs to be powered at 3.3VDC, NOT 5VDC. If you don’t, the bluetooth module will probably go up in smoke.** | Also, the HC-06 Module needs to be powered at 3.3VDC, NOT 5VDC. If you don’t, the bluetooth module will probably go up in smoke.** | ||
+ | |||
+ | Nous utiliserons aussi un module numérique d' | ||
+ | |||
+ | Sur le diagramme Fritzing de la plaque d' | ||
+ | |||
+ | De plus, le module HC-06 doit être alimenté en 3 V DC. Pas en 5 V DC. Si vous n'y prenez pas garde, le module bluetooth risque probablement de partir en fumée. | ||
**DHT Test Code | **DHT Test Code | ||
Ligne 30: | Ligne 44: | ||
break | break | ||
}** | }** | ||
+ | |||
+ | Code de test du DHT | ||
+ | |||
+ | J'ai utilisé un exemple d' | ||
+ | |||
+ | La déclaration Switch fonctionne comme un paquet de déclarations if… elif… elif… else. Cela ressemble à quelque chose comme ceci : | ||
+ | |||
+ | switch (value) { | ||
+ | case test1: | ||
+ | statements | ||
+ | break; | ||
+ | case test2: | ||
+ | statements | ||
+ | break; | ||
+ | … | ||
+ | default: | ||
+ | break | ||
+ | } | ||
**The statement tests the value with each case in the list, and, if it matches, it runs the statements in that segment until it hits the break statement. You can also have multiple “cases” within the same logic set, as you’ll see below. | **The statement tests the value with each case in the list, and, if it matches, it runs the statements in that segment until it hits the break statement. You can also have multiple “cases” within the same logic set, as you’ll see below. | ||
Ligne 38: | Ligne 70: | ||
Since we are using standard serial to test the DHT sensor, you can use the serial monitor built into the Arduino IDE. Simply send an “H”, “h”, “T” or a “t”.** | Since we are using standard serial to test the DHT sensor, you can use the serial monitor built into the Arduino IDE. Simply send an “H”, “h”, “T” or a “t”.** | ||
+ | |||
+ | La déclaration teste la valeur dans chaque cas de la liste et, si ça correspond, elle lance les déclarations de ce segment jusqu' | ||
+ | |||
+ | Aussi, voici le code de test du capteur DHT (voir à droite). N' | ||
+ | |||
+ | Sur la page suivante, nous pouvons voir la routine handleSerial avec les déclarations des switch case. Dans cet exemple, nous chercherons quatre lettres possibles… « T », « t », « H » et « h ». | ||
+ | |||
+ | Comme nous utilisons le lien série standard pour tester le capteur DHT, vous pouvez utiliser le moniteur série intégré à l'IDE Arduino. Simplement, envoyez un « T », « t », « H » ou « h ». | ||
**Bluetooth test code | **Bluetooth test code | ||
In order for you to be able to use the ultimate project, you’ll need to have a bluetooth device to send and receive data to the Arduino. For the testing phase, I used an app called “Bluetooth Terminal HC-05” on my Android phone, available for free from the Google Play store. | In order for you to be able to use the ultimate project, you’ll need to have a bluetooth device to send and receive data to the Arduino. For the testing phase, I used an app called “Bluetooth Terminal HC-05” on my Android phone, available for free from the Google Play store. | ||
+ | |||
This sketch is one that I was able to get from the Internet. Notice, that I didn’t change the logic from if statements to switch case statements in this case. We will be doing that in the combined project. | This sketch is one that I was able to get from the Internet. Notice, that I didn’t change the logic from if statements to switch case statements in this case. We will be doing that in the combined project. | ||
In the setup function (next page), we use bluetooth.print and bluetooth.println pretty much like we do when we print to serial.** | In the setup function (next page), we use bluetooth.print and bluetooth.println pretty much like we do when we print to serial.** | ||
+ | |||
+ | Code de test du Bluetooth | ||
+ | |||
+ | De façon à ce que vous puissiez utiliser le projet final, vous devrez avoir un dispositif bluetooth pour envoyer et recevoir des données vers/de l' | ||
+ | |||
+ | Cette maquette est une de celles que j'ai pu trouver sur Internet. Notez que je n'ai pas changé la logique des déclarations if en déclarations switch case dans ce cas. Nous le ferons dans un projet combiné. | ||
+ | |||
+ | Dans la fonction de paramétrage (page suivante), nous utilisons bluetooth.print et bluetooth.println d'une façon assez proche de ce que nous faisons quand nous imprimons par le lien série. | ||
**Here in the loop function (see page 22), the only changes I made from the original code was to change the bluetooth printout lines from .print (“1”) and .print (“2”) to .println(“Temp: | **Here in the loop function (see page 22), the only changes I made from the original code was to change the bluetooth printout lines from .print (“1”) and .print (“2”) to .println(“Temp: | ||
Ligne 57: | Ligne 106: | ||
https:// | https:// | ||
+ | |||
+ | Ici dans la fonction loop (voir page 22), les seuls changements que j'ai fait au code d' | ||
+ | |||
+ | Pour le tester, une fois que vous avez appairé et connecté votre projet au téléphone en bluetooth, vous devriez être capable d' | ||
+ | |||
+ | La prochaine fois, nous combinerons les deux programmes et préparerons le paramétrage du RPi pour agir comme hôte. | ||
+ | |||
+ | J'ai téléchargé les deux maquettes sur pastebin : | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ |
issue120/python.1494750325.txt.gz · Dernière modification : 2017/05/14 10:25 de d52fr