issue99:automatic_chicken_feeder
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue99:automatic_chicken_feeder [2015/08/01 18:04] – créée auntiee | issue99:automatic_chicken_feeder [2015/08/15 15:06] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Last month I discussed the background and gave the layout for my Arduino powered automatic chicken feeder. This month we’ll discuss the code that it runs. | + | **Last month I discussed the background and gave the layout for my Arduino powered automatic chicken feeder. This month we’ll discuss the code that it runs. |
Grab The Code | Grab The Code | ||
Ligne 25: | Ligne 25: | ||
setSyncProvider(RTC.get); | setSyncProvider(RTC.get); | ||
- | 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' | ||
+ | |||
+ | ** | ||
Alarm.alarmRepeat(9, | Alarm.alarmRepeat(9, | ||
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(" | ||
+ | ** | ||
- | The code above is setting the colour to yellow, printing the temperature, | + | 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, | ||
Lines 158 to 164 are the same idea with white text, but for the light level from the LDR. | Lines 158 to 164 are the same idea with white text, but for the light level from the LDR. | ||
Ligne 85: | Ligne 142: | ||
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). | ||
+ | ** | ||
- | 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. | + | 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. | ||
button=digitalRead(4); | button=digitalRead(4); | ||
Ligne 105: | Ligne 193: | ||
If the button is pressed (it goes HIGH) then we light the green LED, print a confirmation to the serial, jump to a procedure called dispense(), then turn the LED off. | If the button is pressed (it goes HIGH) then we light the green LED, print a confirmation to the serial, jump to a procedure called dispense(), then turn the LED off. | ||
- | Lastly, we have a one-second delay. | + | Lastly, we have a one-second delay.** |
- | 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. | + | 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. | ||
Line 238 is the dispense() procedure. This is the main crux of the machine. It dispenses the grain for the chickens. | Line 238 is the dispense() procedure. This is the main crux of the machine. It dispenses the grain for the chickens. | ||
Ligne 129: | Ligne 238: | ||
It’s definitely the most difficult code I’ve worked on and it’s not perfect. More work could have been done in displaying the time. It’s a bit botched, but to write further code would have taken me over the limit for the Nano I used. | It’s definitely the most difficult code I’ve worked on and it’s not perfect. More work could have been done in displaying the time. It’s a bit botched, but to write further code would have taken me over the limit for the Nano I used. | ||
- | 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.1438445099.txt.gz · Dernière modification : 2015/08/01 18:04 de auntiee