issue139:great_cow_basic
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 | ||
issue139:great_cow_basic [2018/12/07 16:46] – d52fr | issue139:great_cow_basic [2018/12/15 09:32] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
In this issue, I will show you how to code subroutines for the WDT to make refactoring of the code a bit easier, and to expand the transmitter with an optical signal for the data transmission and measuring the battery level to indicate when a battery change seems needed. Further, I will show a short program for the personal computer to receive the transmission, | In this issue, I will show you how to code subroutines for the WDT to make refactoring of the code a bit easier, and to expand the transmitter with an optical signal for the data transmission and measuring the battery level to indicate when a battery change seems needed. Further, I will show a short program for the personal computer to receive the transmission, | ||
+ | |||
+ | Dans le FCM n° 138, j'ai montré comment acquérir des informations sur la luminosité ambiante avec une photo-résistance (LDR), comment la transmettre à un dispositif éloigné et comment paramétrer un minuteur de watchdog (surveillance temporelle - WDT) pour économiser l' | ||
+ | |||
+ | Dans ce numéro, je vous montrerai comment coder des sous-routines du WDT pour rendre la réfection du code un peu plus facile et pour compléter l' | ||
**Expanding the sleep time | **Expanding the sleep time | ||
A transmission every 8 seconds would be a large amount of information. In numbers: a day has around 86,400 seconds; if a transmission takes place every 8 seconds, there would be 10,800 transmissions each day. This would be a heavy overhead; the light level we will measure should not change too often - maybe only in some cloudy situations. In the end, there would be too many duplicate values to handle. ** | A transmission every 8 seconds would be a large amount of information. In numbers: a day has around 86,400 seconds; if a transmission takes place every 8 seconds, there would be 10,800 transmissions each day. This would be a heavy overhead; the light level we will measure should not change too often - maybe only in some cloudy situations. In the end, there would be too many duplicate values to handle. ** | ||
+ | |||
+ | Étendre la durée de veille | ||
+ | |||
+ | Une transmission toutes les 8 secondes correspondrait à une grande quantité d' | ||
**So it would be great to have the microcontroller sleep longer than this 8 seconds to minimize the data transfers and to save power. Due to the limitations of the WDT, this can be achieved only with a loop condition. For an overview, see this simplified diagram of the following software. At the very beginning of the program, we define a timeout variable; the device will wake up every 8 s, check if the timeout has occurred first. If not, it decreases the timeout by one and immediately goes to sleep again. This should only take a very little amount of power. The reading of the ADC, the measuring of the battery level, etc, will take place only after the timeout. To determine the timeout, just think of the time frame you want your transmitter to send data. One minute has around 8 wakeups of the device (8 x 8 s = 64 sec. roughly 1 minute). To save some program space, I suggest to stay in the range of a byte value (max. 255). Setting the timeout to 225 will give a time frame of 30 minutes. ** | **So it would be great to have the microcontroller sleep longer than this 8 seconds to minimize the data transfers and to save power. Due to the limitations of the WDT, this can be achieved only with a loop condition. For an overview, see this simplified diagram of the following software. At the very beginning of the program, we define a timeout variable; the device will wake up every 8 s, check if the timeout has occurred first. If not, it decreases the timeout by one and immediately goes to sleep again. This should only take a very little amount of power. The reading of the ADC, the measuring of the battery level, etc, will take place only after the timeout. To determine the timeout, just think of the time frame you want your transmitter to send data. One minute has around 8 wakeups of the device (8 x 8 s = 64 sec. roughly 1 minute). To save some program space, I suggest to stay in the range of a byte value (max. 255). Setting the timeout to 225 will give a time frame of 30 minutes. ** | ||
+ | |||
+ | Aussi, il serait bien que le microcontrôleur reste en veille plus longtemps que 8 secondes pour réduire les transferts de données et économiser l' | ||
+ | |||
**If the timeout occurs, the microcontroller wakes up, activates all of its peripherals and sends the data over the air. After the work is done, the microcontroller goes to sleep again. With this method you reduce the data transfers to around 48 transmissions a day. Hint: For debugging purposes, you would want to set the timeout to a smaller value, maybe 1 to get a transmission every 8 seconds.** | **If the timeout occurs, the microcontroller wakes up, activates all of its peripherals and sends the data over the air. After the work is done, the microcontroller goes to sleep again. With this method you reduce the data transfers to around 48 transmissions a day. Hint: For debugging purposes, you would want to set the timeout to a smaller value, maybe 1 to get a transmission every 8 seconds.** | ||
+ | |||
+ | Si la butée se déclenche, le microcontrôleur se réveille, active tous ses périphériques et émet les données. Une fois ce travail fait, le microcontrôleur retourne en veille. Avec cette méthode, vous réduisez les transferts de données à 48 transmissions par jour. Astuce : pour des besoins de débogage, vous voudrez régler la butée à une plus petite valeur, peut-être 1, pour disposer d'une transmission toutes les 8 secondes. | ||
**Measure the battery level | **Measure the battery level | ||
The ATtiny13a can measure its own battery voltage through the ADC and a voltage divider. Unfortunately, | The ATtiny13a can measure its own battery voltage through the ADC and a voltage divider. Unfortunately, | ||
+ | |||
+ | Mesure du niveau de la batterie | ||
+ | |||
+ | Le ATtiny13a peut mesurer sa propre tension de batterie via l'ADC et un diviseur de tension. Malheureusement, | ||
**Data logging and evaluation | **Data logging and evaluation | ||
To know when a certain light level occurs, the data has to include the actual time and date for further examination. To save some space on the hard disk, we read the data from the serial line and strip the unnecessary or false information. Maybe you have the FreeBasic-Installation from Issue 127 still intact, so you can compile the following yourself. Otherwise take this as an idea to be implemented in the programming language of your choice. ** | To know when a certain light level occurs, the data has to include the actual time and date for further examination. To save some space on the hard disk, we read the data from the serial line and strip the unnecessary or false information. Maybe you have the FreeBasic-Installation from Issue 127 still intact, so you can compile the following yourself. Otherwise take this as an idea to be implemented in the programming language of your choice. ** | ||
+ | |||
+ | Enregistrement des données et évaluation | ||
+ | |||
+ | Pour savoir quand arrive un certain niveau de luminosité, | ||
**Sample results in the serialdata.raw file; shows timestamp, LDR value (brightness), | **Sample results in the serialdata.raw file; shows timestamp, LDR value (brightness), | ||
Ligne 29: | Ligne 50: | ||
13.11.2018, 22: | 13.11.2018, 22: | ||
13.11.2018, 22: | 13.11.2018, 22: | ||
+ | |||
+ | Des échantillons de résultats sont dans le fichier serialdata.raw ; il montre les horodatages, | ||
+ | |||
+ | (Le Vcc, ou plutôt l'ADC, était flottant ici, le circuit n' | ||
+ | |||
+ | 13.11.2018, 22: | ||
+ | 13.11.2018, 22: | ||
+ | 13.11.2018, 22: | ||
+ | 13.11.2018, 22: | ||
+ | 13.11.2018, 22: | ||
+ | 13.11.2018, 22: | ||
**Breadboard circuitry | **Breadboard circuitry | ||
Ligne 35: | Ligne 67: | ||
The transmitter program has 928 Bytes and so the program memory of the ATtiny13a is almost full, but it is a good starting point for your own experiments - maybe you change the LDR and measure temperatures with a negative temperature coefficient thermistor or short: NTC. Or if the code can be sized down, you could try a temperature and humidity sensor, such as a DHT11 or DHT22. As the time got short on this article I haven’t gathered a full day of data - but I will publish it in the github-repo, | The transmitter program has 928 Bytes and so the program memory of the ATtiny13a is almost full, but it is a good starting point for your own experiments - maybe you change the LDR and measure temperatures with a negative temperature coefficient thermistor or short: NTC. Or if the code can be sized down, you could try a temperature and humidity sensor, such as a DHT11 or DHT22. As the time got short on this article I haven’t gathered a full day of data - but I will publish it in the github-repo, | ||
+ | |||
+ | Circuit d' | ||
+ | |||
+ | (Voir en bas de la page précédente.) | ||
+ | |||
+ | Conclusion | ||
+ | |||
+ | Le programme d' | ||
**Sources | **Sources | ||
If you want to download the source instead of copy-pasting it, you can now check it out with git or an SVN client. See goo.gl/ | If you want to download the source instead of copy-pasting it, you can now check it out with git or an SVN client. See goo.gl/ | ||
+ | |||
+ | Sources | ||
+ | |||
+ | Si vous préférez télécharger les sources plutôt que les copier/ | ||
+ | |||
Ligne 44: | Ligne 89: | ||
Microchip AVR AN2447: Measure VCC/Battery http:// | Microchip AVR AN2447: Measure VCC/Battery http:// | ||
+ | |||
+ | Références | ||
+ | |||
+ | Micro-composant AVR AN2447 : Mesure du Vcc ou de la batterie http:// | ||
**Acknowledgement | **Acknowledgement | ||
I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights and valuable hints. And my appreciation to Michael Kennedy from the Full Circle Magazine Editorial Team who proofread and tweaked the FreeBASIC code.** | I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights and valuable hints. And my appreciation to Michael Kennedy from the Full Circle Magazine Editorial Team who proofread and tweaked the FreeBASIC code.** | ||
+ | |||
+ | Remerciements | ||
+ | |||
+ | Je souhaite remercier Evan Venn (Anobium) de l' | ||
issue139/great_cow_basic.1544197560.txt.gz · Dernière modification : 2018/12/07 16:46 de d52fr