issue136:great_cow_basic
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue136:great_cow_basic [2018/09/05 08:13] – créée d52fr | issue136:great_cow_basic [2018/09/23 11:54] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | In FCM#129, I showed you how to use the analog-to-digital conversion (ADC) with a potentiometer, | + | **In FCM#129, I showed you how to use the analog-to-digital conversion (ADC) with a potentiometer, |
- | Light dependent resistor | + | Dans le FCM n° 129, j’ai montré comment utiliser la conversion analogique-numérique (ADC - Analog-Digital Conversion) avec un potentiomètre, |
- | A LDR, or photocell, is a light-controlled variable resistor. The resistance decreases with increasing light intensity. Hence you may use it to develop light-dependent | + | **Light |
- | LDR and the Analog Digital Conversion | + | A LDR, or photocell, is a light-controlled variable resistor. The resistance decreases with increasing light intensity. Hence you may use it to develop light-dependent applications to react to changes of the light intensity or the difference between light and dark conditions. In the dark, the LDR has a resistance of many megaohms; when the LDR is in the light, the resistance drops to a few hundred ohms. LDRs are available in different sizes (such as LED, e.g, 3 or 5 mm), and with different electrical resistances. Always review the datasheet, which contains |
- | To use the ADC, we need to know how to connect a LDR to the microcontroller – which seems simple – like any other resistor. But here comes the tricky part: you need a voltage divider to connect it to get useful readings. Therefore, we need some theory before we can operate the LDR correctly. Using Ohms Law, the current which flows through a conductor between two points is directly proportional to the voltage across the two points. To calculate the voltage dividers values, you can use this equation. If we would use resistors with a fixed value of 100 Ohm for resistance, we could set Vin = 5 V, R1 as 100 Ohm and R2 as 100 Ohm and would have a fixed Vout of 2.5 Volts. Next, we assume R1 to be our LDR and assume further it's dark and the LDR has gained its highest resistance of 1 MOhm - then Vout would be 0.45 V. On the other hand, if we set the LDR as R2 and leave R1 at 100 Ohm the voltage would be 4.55 V. As you can see, knowing on which side the LDR resides is important to interpret the measured values. So, first you have to decide where the LDR resides in your circuit. After considering the placement of the LDR, the ADC has to be connected between R1 and R2. The schematic of the circuit looks a bit like a twisted L with a joint to the right side. In the diagram, the Vout would be the connection to the ADC channel on the microcontroller. | + | Photo-résistance |
- | Over the air data transmission | + | Une LDR ou cellule photo-électrique, |
+ | |||
+ | **LDR and the Analog Digital Conversion | ||
+ | |||
+ | To use the ADC, we need to know how to connect a LDR to the microcontroller – which seems simple – like any other resistor. But here comes the tricky part: you need a voltage divider to connect it to get useful readings. Therefore, we need some theory before we can operate the LDR correctly. Using Ohms Law, the current which flows through a conductor between two points is directly proportional to the voltage across the two points. To calculate the voltage dividers values, you can use this equation. If we would use resistors with a fixed value of 100 Ohm for resistance, we could set Vin = 5 V, R1 as 100 Ohm and R2 as 100 Ohm and would have a fixed Vout of 2.5 Volts. Next, we assume R1 to be our LDR and assume further it's dark and the LDR has gained its highest resistance of 1 MOhm - then Vout would be 0.45 V. On the other hand, if we set the LDR as R2 and leave R1 at 100 Ohm the voltage would be 4.55 V. As you can see, knowing on which side the LDR resides is important to interpret the measured values. So, first you have to decide where the LDR resides in your circuit. After considering the placement of the LDR, the ADC has to be connected between R1 and R2. The schematic of the circuit looks a bit like a twisted L with a joint to the right side. In the diagram, the Vout would be the connection to the ADC channel on the microcontroller.** | ||
+ | |||
+ | Photo-résistance et conversion analogique-numérique | ||
+ | |||
+ | Pour utiliser l’ADC, nous avons besoin de savoir comment connecter la LDR au microcontrôleur - ce qui semble simple - comme tout autre résistance. Mais voici la partie compliquée : | ||
+ | |||
+ | **Over the air data transmission | ||
For the first experiments, | For the first experiments, | ||
- | Then, as a further development, | + | Then, as a further development, |
- | For more important data, it is recommended to use other transfer methods. But, the simplicity with this hardware was intriguing: Just 3 Pins for a wireless data transfer, Vcc, GND and a DATA pin on both the transmitter and the receiver. Another point is the power consumption, | + | Transmission sans fil |
- | So, how to create a simple solution to this problem? I asked myself why not use a plain serial connection? | + | Pour les premiers essais, je mesure des modifications de la valeur de la LDR en connectant le microcontrôleur et la LDR avec un adaptateur série pour voir comment les valeurs changent quand la quantité de lumière varie. |
- | Transmission software | + | Ensuite, comme développement ultérieur, il est intéressant de vérifier le niveau de la lumière hors de la maison, pour avoir une idée s’il fait sombre ou non. Pour récupérer les données depuis l’extérieur, |
+ | |||
+ | **For more important data, it is recommended to use other transfer methods. But, the simplicity with this hardware was intriguing: Just 3 Pins for a wireless data transfer, Vcc, GND and a DATA pin on both the transmitter and the receiver. Another point is the power consumption, | ||
+ | |||
+ | So, how to create a simple solution to this problem? I asked myself why not use a plain serial connection? | ||
+ | |||
+ | Pour des données plus importantes, | ||
+ | |||
+ | Aussi, comment créer un solution simple à ce problème ? Je me suis demandé pourquoi ne pas utiliser une simple liaison série ? Ceci pourrait sans doute faire le boulot facilement. Après quelques recherches, il semble que cette idée est déjà sortie et a été étudiée avant, comme j’en ai trouvé la preuve dans certains projets Instructables (voir les liens ci-dessous pour plus d’informations) et cette idée était faisable. | ||
+ | |||
+ | **Transmission software | ||
Using the plain serial connection has another advantage. You do not need major changes to the setup from the early articles I have published in this series. The same program code to send data to the USB serial converter can be used, you would only interchange the connections between the USB serial converter and the transmitter. The following code might look familiar, because the ADC readings of a potentiometer and a LDR are similar, the only changes to the code was to rename the variable from POTI to LDR (code on next page, top right). | Using the plain serial connection has another advantage. You do not need major changes to the setup from the early articles I have published in this series. The same program code to send data to the USB serial converter can be used, you would only interchange the connections between the USB serial converter and the transmitter. The following code might look familiar, because the ADC readings of a potentiometer and a LDR are similar, the only changes to the code was to rename the variable from POTI to LDR (code on next page, top right). | ||
- | Put an USB serial adapter with the RX-Line to the TX-Pin of the ATtiny13a, and start your terminal software to see what's going on there. At my site, during writing and testing the software, the surrounding light gives values around 66 - 71, after holding the camera light of my smartphone over the LDR the value increases to a maximum of 216. | + | Put an USB serial adapter with the RX-Line to the TX-Pin of the ATtiny13a, and start your terminal software to see what's going on there. At my site, during writing and testing the software, the surrounding light gives values around 66 - 71, after holding the camera light of my smartphone over the LDR the value increases to a maximum of 216.** |
- | Trial and Error | + | Logiciel de transmission |
+ | |||
+ | L’utilisation d’une simple connexion série a un autre avantage. Vous n’avez pas besoin de faire de grands changements dans le paramétrage réalisé à partir des articles précédents publiés dans cette série. Le même code de programme pour l’envoi de données au convertisseur série USB peut être utilisé ; vous n’aurez qu’à intervertir les connexions entre le convertisseur série USB et l’émetteur. Le code suivant peut vous sembler familier, car les lectures d’un potentiomètre et d’une LDR avec l’ADC sont similaires ; | ||
+ | |||
+ | Mettez un adaptateur série USB avec la sortie RX sur la borne TX de l’ATtiny13a et lancez votre logiciel de terminal pour voir ce que se passe. Chez moi, pendant l’écriture et le test du logiciel, la lumière ambiante donnait des valeurs entre 66 et 71 ; en tenant le projecteur de l’appareil photo de mon smartphone sur la LDR, les valeurs montaient jusqu’à 216, au maximum. | ||
+ | |||
+ | **Trial and Error | ||
After replacing the wires and heading over to air transmission, | After replacing the wires and heading over to air transmission, | ||
- | The next test configuration was to set the Sender device 1m from the Receiver device. As it turned out, the characteristics of the receiver could not handle the constant data stream the software sent to it every second. The surrounding noise pollutes the data stream. To improve the reception reliability, | + | The next test configuration was to set the Sender device 1m from the Receiver device. As it turned out, the characteristics of the receiver could not handle the constant data stream the software sent to it every second. The surrounding noise pollutes the data stream. To improve the reception reliability, |
+ | |||
+ | Tâtonnements | ||
+ | |||
+ | Après remplacement de la liaison filaire par une transmission sans fil, les résultats ont paru très étranges. C’était le résultat d’une installation rapide ; cependant, après soudure des antennes (env. 17 cm) de l’émetteur et du récepteur, les résultats de transmission se sont améliorés. Avec une distance de 40 cm pour la « transmission sans fil », la qualité était acceptable. La plupart des articles de référence que j’ai trouvés suggèrent d’envoyer les données plusieurs fois plutôt qu’une. Et, au premier test, montré ci-dessous, ceci fut prouvé par un test empirique (montré en bas à droite). | ||
+ | |||
+ | La configuration du test suivant était d’installer le dispositif émetteur à 1 m de distance du dispositif récepteur. En fait, les caractéristiques du récepteur ne permettaient pas de gérer le flux constant de données que le logiciel lui envoyait toutes les secondes. Le bruit ambiant pollue le flux des données. Pour améliorer la fiabilité de la réception, le logiciel doit être écrit en gardant en tête les caractéristiques du matériel ; | ||
- | Experimentation with Byte transmitted as preambles, as suggested in the research articles, were not of sufficient quality for the readability of the console output. The results were even the same if given a value as 0xFA or given a simple ‘dot’ as preamble. So, I added dots as pre- and postamble. The results on the console for the short range of 40cm to 1m looked promising and the data received was read as in the snippet below. | + | **Experimentation with Byte transmitted as preambles, as suggested in the research articles, were not of sufficient quality for the readability of the console output. The results were even the same if given a value as 0xFA or given a simple ‘dot’ as preamble. So, I added dots as pre- and postamble. The results on the console for the short range of 40cm to 1m looked promising and the data received was read as in the snippet below. |
After setting the Sender device to another room (~ 3m and a wall between), the results looked promising the first seconds, but after a while the data got unreadable. Even in the same room (~ 3m, but no walls) left unusable data on the console as in this other snippet (top right) | After setting the Sender device to another room (~ 3m and a wall between), the results looked promising the first seconds, but after a while the data got unreadable. Even in the same room (~ 3m, but no walls) left unusable data on the console as in this other snippet (top right) | ||
- | So something was faulty in my code which gave poor results. After careful examination with the timings, the times the LDR values are sent and the last Byte value (Ser1Send 0b00000000) it seems that this last Byte value was too much. After deleting this line and recompiling it, the results (bottom right) were much better. | + | So something was faulty in my code which gave poor results. After careful examination with the timings, the times the LDR values are sent and the last Byte value (Ser1Send 0b00000000) it seems that this last Byte value was too much. After deleting this line and recompiling it, the results (bottom right) were much better.** |
+ | Une expérience d’envoi de « Byte » (octet) comme préambule, comme suggéré dans des articles de ma recherche, ne fut pas d’une qualité suffisante pour une bonne lecture de la sortie sur la console. Les résultats étaient les mêmes, que le préambule ait une valeur OxFA ou un simple « point ». Aussi, j’ai ajouté des points en préambule et en conclusion. Les résultats sur la console pour une distance entre 40 cm et 1 m parraissaient prometteurs et les donées reçues étaient lues comme dans l’encart ci-dessous. | ||
+ | Après avoir placé le dispositif émetteur dans une autre pièce (environ 3 m et un mur de séparation), | ||
- | Breadboard circuitry | + | Ainsi, mon code contenait quelque chose d' |
- | To test the software, you might connect the Receiver directly to a USB to serial converter, connect 5V to Vcc, the RX to the DATA pin (only one of them, not both at the same time), and GND to GND. The transmitter device and the LDR should be connected to the ATtiny13a as seen below. | + | **Breadboard circuitry |
- | Conclusion | + | To test the software, you might connect the Receiver directly to a USB to serial converter, connect 5V to Vcc, the RX to the DATA pin (only one of them, not both at the same time), and GND to GND. The transmitter device and the LDR should be connected to the ATtiny13a as seen below. ** |
+ | |||
+ | Circuit de la plaque d’essai | ||
+ | |||
+ | Pour tester le logiciel, vous pourriez connecter le récepteur directement au convertisseur série USB, connecter le 5V au Vcc, le Rx à la borne DATA (une seule, pas les deux en même temps) et GND à GND. Le dispositif transmetteur et la LDR devront être connectés à l’ATtiny13a comme montré ci-dessous. | ||
+ | |||
+ | **Conclusion | ||
The software serial solution from Great Cow BASIC did the job as expected. But, to get reliable results from the over-the-air connection was much more work than I had expected. Testing this little Transmitter outside was out of scope for this time due to my tight time budget. But, for a battery powered solution, I would implement some kind of power saving on the transmitter because sending data every 8 seconds without switching it off would soak up the energy of the most powerful battery soon. The compiled binary has 772 Bytes, so there is some space left to implement maybe a solution with a watchdog timer and a power saving routine can be added. | The software serial solution from Great Cow BASIC did the job as expected. But, to get reliable results from the over-the-air connection was much more work than I had expected. Testing this little Transmitter outside was out of scope for this time due to my tight time budget. But, for a battery powered solution, I would implement some kind of power saving on the transmitter because sending data every 8 seconds without switching it off would soak up the energy of the most powerful battery soon. The compiled binary has 772 Bytes, so there is some space left to implement maybe a solution with a watchdog timer and a power saving routine can be added. | ||
- | On the hardware side, I maybe would change the receiver on the long run as there might be better solutions for this. Other receivers which were mentioned to work better and are not really more expensive than the used one are “RXB6”, “RXB8”, “RXB12”. If I would buy new hardware, I would maybe test another receiver as it seems that the used one is the one with the poorest reception you can get. The transmitter works fine and seems to have no better candidate. | + | On the hardware side, I maybe would change the receiver on the long run as there might be better solutions for this. Other receivers which were mentioned to work better and are not really more expensive than the used one are “RXB6”, “RXB8”, “RXB12”. If I would buy new hardware, I would maybe test another receiver as it seems that the used one is the one with the poorest reception you can get. The transmitter works fine and seems to have no better candidate. |
- | For more reliable data transfers, it could be a good idea to implement another algorithm and receive the data first through another microcontroller, | + | Conclusion |
- | Essentially, | + | La solution de logiciel série pour Great Cow BASIC a fait le travail comme prévu. Mais, pour obtenir des résultats fiables avec une transmission |
- | Sources | + | Côté matériel, à long terme, je changerais probablement le récepteur, car il pourrait y avoir de meilleures solutions. Les autres récepteurs qui ont été notés comme fonctionnant mieux sans être beaucoup plus chers que celui utilisé sont les « RXB6 », « RXB8 », « RXB12 ». Au cas où j’achèterais du nouveau matériel, je testerais peut-être un autre récepteur, car il semble que celui utilisé est celui qui a la plus mauvaise réception possible. Le transmetteur fonctionne bien et semble ne pas avoir de concurrent meilleur. |
- | If you want to download | + | **For more reliable data transfers, it could be a good idea to implement another algorithm and receive |
- | References | + | Essentially, |
+ | |||
+ | Pour des transferts de données plus fiables, ce serait peut-être une bonne idée d’implémenter un autre algorithme et de recevoir d’abord les données via un autre microcontrôleur ; | ||
+ | |||
+ | En gros, ça marche. Le Tiny13a peut supporter une LDR et une transmission de données sans fil. | ||
+ | |||
+ | **Sources | ||
+ | |||
+ | If you want to download the sources instead of copy-pasting it, you can now check it out with git or an SVN client. Have a look at https:// | ||
+ | |||
+ | Sources | ||
+ | |||
+ | Si vous voulez télécharger les sources plutôt que de les copier/ | ||
+ | |||
+ | **References | ||
Good introduction on voltage divider circuits https:// | Good introduction on voltage divider circuits https:// | ||
Ligne 67: | Ligne 121: | ||
Simple transmit over 433 Mhz modules, using the USART - part 2 https:// | Simple transmit over 433 Mhz modules, using the USART - part 2 https:// | ||
- | Tips for enhancement of the use of the 433 Mhz modules and a suggestion for a own transfer protocol http:// | + | Tips for enhancement of the use of the 433 Mhz modules and a suggestion for a own transfer protocol http:// |
+ | |||
+ | Références | ||
+ | |||
+ | Une bonne introduction aux circuits diviseurs de tension : https:// | ||
+ | |||
+ | Une explication à propos de la bibliothèque virtualwire pour les récepteurs et transmetteurs 433 / 315 MHz : https:// | ||
+ | |||
+ | Une transmission simple avec des modules 433 MHz, utilisant l’USART - partie 1 : https:// | ||
+ | |||
+ | Une transmission simple avec des modules 433 MHz, utilisant l’USART - partie 2 : https:// | ||
+ | |||
+ | Astuces pour l’amélioration de l’usage des modules 433 MHz et une suggestion pour son propre protocole de transfert : | ||
+ | |||
+ | **Acknowledgement | ||
- | Acknowledgement | + | I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights and valuable hints.** |
- | I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights and valuable hints. | + | Remerciements |
+ | Je souhaite remercier Evan Venn (Anobium) de l’équipe Great Cow BASIC pour ses idées et ses précieuses indications. |
issue136/great_cow_basic.1536127980.txt.gz · Dernière modification : 2018/09/05 08:13 de d52fr