issue99:automatic_chicken_feeder
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 | ||
issue99:automatic_chicken_feeder [2015/08/12 15:24] – d52fr | issue99:automatic_chicken_feeder [2015/08/15 15:06] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 26: | Ligne 26: | ||
This is to grab the time from the RTC (Real Time Clock). The RTC has a battery on board so it keeps the time even when the Arduino (and RTC board) is powered down. After that comes an if statement to see if the grab was successful.** | This is to grab the time from the RTC (Real Time Clock). The RTC has a battery on board so it keeps the time even when the Arduino (and RTC board) is powered down. After that comes an if statement to see if the grab was successful.** | ||
+ | |||
+ | Le mois dernier, j'ai présenté le contexte et donné la disposition de mon nourrisseur automatique de poulets avec Arduino. Ce mois-ci, je vous montre le code qui tourne dessus. | ||
+ | |||
+ | Récupérer le code | ||
+ | |||
+ | Vous devez d' | ||
+ | |||
+ | Le code | ||
+ | |||
+ | Des lignes 8 à 61, ce sont toutes les procédures pour le détecteur DHT11 (température). Je n'irai pas jusqu' | ||
+ | |||
+ | Des lignes 62 à 68, ce sont tous les include pour les différentes bibliothèques nécessaires. Chaque ligne a un commentaire qui dit à quoi sert chaque bibliothèque. | ||
+ | |||
+ | A la ligne 81, commencent les bons morceaux. | ||
+ | |||
+ | UTFT myGLCD(QD_TFT180A, | ||
+ | |||
+ | Cette ligne est pour l' | ||
+ | |||
+ | Ensuite viennent quelques réglages de valeurs diverses dont j'ai besoin après. | ||
+ | |||
+ | Setup() | ||
+ | |||
+ | Après quelques commandes myGLCD (que nous avons déjà vues), nous avons : | ||
+ | |||
+ | setSyncProvider(RTC.get); | ||
+ | |||
+ | C'est pour récupérer le temps du RTC (Real Time Clock : horloge en temps réel). Le RTC a une batterie sur le circuit de façon à conserver l' | ||
** | ** | ||
Ligne 48: | Ligne 76: | ||
myGLCD.setColor(0, | myGLCD.setColor(0, | ||
- | myGLCD.printNumI((float)DHT11.temperature, | + | < |
myGLCD.print("' | myGLCD.print("' | ||
- | myGLCD.printNumI((float)DHT11.humidity, | + | < |
myGLCD.print(" | myGLCD.print(" | ||
** | ** | ||
+ | |||
+ | Alarm.alarmRepeat(9, | ||
+ | |||
+ | Alarm.alarmRepeat(11, | ||
+ | |||
+ | Les commandes Alarm.alarmRepeat sont journalières. Ainsi, dans le cas ci-dessus, l'« alarme » se déclenchera chaque jour à 9 h et 11 h du matin précisément. Le format 9,00,0 fait référence à l' | ||
+ | |||
+ | Dans mon code, j'ai plusieurs alarmes journalières. | ||
+ | |||
+ | Maintenant que j'ai indiqué à Arduino quand je veux des alarmes, je règle mon servomoteur et précise le mode des picots pour mon bouton manuel et ma LED verte (qui s' | ||
+ | |||
+ | Loop() | ||
+ | |||
+ | En premier, dans la boucle, nous sautons à la procédure digitalClickDisplay() qui présentera l' | ||
+ | |||
+ | Aux lignes 131 à 148, nous commençons à imprimer la température du DHT11 sur la liaison série aussi. À nouveau, avant la mise en place de l' | ||
+ | |||
+ | À la ligne 150 commencent les sorties vers l' | ||
+ | |||
+ | myGLCD.setColor(0, | ||
+ | |||
+ | < | ||
+ | |||
+ | myGLCD.print("' | ||
+ | |||
+ | < | ||
+ | |||
+ | myGLCD.print(" | ||
**The code above is setting the colour to yellow, printing the temperature, | **The code above is setting the colour to yellow, printing the temperature, | ||
Ligne 87: | Ligne 143: | ||
The lines above are for setting an orangey colour then printing the next alarm (again, +1 hr). | The lines above are for setting an orangey colour then printing the next alarm (again, +1 hr). | ||
** | ** | ||
+ | |||
+ | Le code ci-dessus règle la couleur en jaune, imprime la température, | ||
+ | |||
+ | Pour les lignes 158 à 164, c'est la même idée avec un texte blanc, mais pour le niveau de luminosité de la photorésistance (LDR - light-dependent resistor). | ||
+ | |||
+ | myGLCD.printNumI(hour()+1, | ||
+ | |||
+ | myGLCD.print(":", | ||
+ | |||
+ | myGLCD.printNumI(minute(), | ||
+ | |||
+ | myGLCD.print(":", | ||
+ | |||
+ | myGLCD.printNumI(second(), | ||
+ | |||
+ | Ces lignes (ci-dessus) impriment l' | ||
+ | |||
+ | myGLCD.setColor(0, | ||
+ | |||
+ | myGLCD.printNumI(hour(Alarm.getNextTrigger())+1, | ||
+ | |||
+ | myGLCD.print(":", | ||
+ | |||
+ | myGLCD.printNumI(minute(Alarm.getNextTrigger()), | ||
+ | |||
+ | myGLCD.print(":", | ||
+ | |||
+ | myGLCD.printNumI(second(Alarm.getNextTrigger()), | ||
+ | |||
+ | Les lignes ci-dessus règlent une couleur orangée, puis impriment la prochaine heure d' | ||
**Lines 186 to 219 are commented out and were used when I originally used a small font. I kept this chunk of code in there in case the big font didn’t work out and I had to revert back. | **Lines 186 to 219 are commented out and were used when I originally used a small font. I kept this chunk of code in there in case the big font didn’t work out and I had to revert back. | ||
Ligne 108: | Ligne 194: | ||
Lastly, we have a one-second delay.** | Lastly, we have a one-second delay.** | ||
+ | |||
+ | Les lignes 186 à 219 sont commentées ; elles étaient utilisées au début quand j' | ||
+ | |||
+ | button=digitalRead(4); | ||
+ | |||
+ | Maintenant, nous vérifions s'il y a eu une pression sur le bouton pour une alimentation manuelle. | ||
+ | |||
+ | if (button==HIGH) | ||
+ | { | ||
+ | digitalWrite(greenLED, | ||
+ | |||
+ | Serial.println(" | ||
+ | | ||
+ | dispense(opened, | ||
+ | digitalWrite(greenLED, | ||
+ | |||
+ | } | ||
+ | |||
+ | Si on a appuyé sur le bouton (il passe à l' | ||
+ | |||
+ | Enfin, nous avons un délai d'une seconde. | ||
**Jumping down to line 279 we see the RTCAlarm() procedure. In here we do a confirmation print to the serial, light the LED, jump to the dispense() procedure, and return to turn off the LED. | **Jumping down to line 279 we see the RTCAlarm() procedure. In here we do a confirmation print to the serial, light the LED, jump to the dispense() procedure, and return to turn off the LED. | ||
Ligne 132: | Ligne 239: | ||
For sheer amusement, have a look through the eight revisions on my GitHub Gist page and you’ll see it evolve through time.** | For sheer amusement, have a look through the eight revisions on my GitHub Gist page and you’ll see it evolve through time.** | ||
+ | |||
+ | En descendant à la ligne 279, nous voyons la procédure RTCAlarm(). Ici, nous avons une impression de confirmation de l' | ||
+ | |||
+ | A la ligne 238, c'est la procédure dispense(). C'est l' | ||
+ | |||
+ | myServo.write(opened); | ||
+ | |||
+ | myGLCD.setColor(0, | ||
+ | |||
+ | myGLCD.print(" | ||
+ | |||
+ | delay(2000); | ||
+ | |||
+ | myServo.write(closed); | ||
+ | |||
+ | myGLCD.setColor(0, | ||
+ | |||
+ | myGLCD.fillRect(0, | ||
+ | |||
+ | Ici, nous faisons tourner le servomoteur en avant (« opened » a été défini au début du code ; c'est l' | ||
+ | |||
+ | C'est vraiment le code le plus difficile sur lequel j'ai travaillé et il n'est pas parfait. Plus de travail aurait pu être fait pour afficher l' | ||
+ | |||
+ | Pour le pur plaisir, regardez les huit révisions sur ma page Github Gist et en vous verrez son évolution dans le temps. | ||
+ |
issue99/automatic_chicken_feeder.1439385867.txt.gz · Dernière modification : 2015/08/12 15:24 de d52fr