| Ligne 60 : |
Ligne 60 : |
| | However, by default, the Arduino's {{fname|analogRead()}} use a 10 bit coding. So the range of possible value return by {{fname|analogRead()}} is 0 to 1024 (for 0 to 3.3v). This means that the accuracy of reading is 3.3 / 1024 = 0.0032 Volts, so 3.2 mV. | | However, by default, the Arduino's {{fname|analogRead()}} use a 10 bit coding. So the range of possible value return by {{fname|analogRead()}} is 0 to 1024 (for 0 to 3.3v). This means that the accuracy of reading is 3.3 / 1024 = 0.0032 Volts, so 3.2 mV. |
| | | | |
| − | As the M0 does have an Analog-to-digital converter with a precision of 12 bits, we could also use the {{fname|analogReadResolution( 12 )}} to upgrade the {{fname|analogRead()}} resolution to 12 bits. In such case, the range of possible value return by {{fname|analogRead()}} is 0 to 4095 (for 0 to 3.3v). This means that the accuracy of reading is 3.3 / 4095 = 0.000805 Volts, so 0.805 mV. | + | As the M0 does have an ADC (''Analog-to-Digital Converter'') with a precision of 12 bits, we could also use the {{fname|analogReadResolution( 12 )}} to upgrade the {{fname|analogRead()}} resolution to 12 bits. In such case, the range of possible value return by {{fname|analogRead()}} is 0 to 4095 (for 0 to 3.3v). As we have a real 12bit ADC, we can rely on that accuracy (it is not a 10 bits ADC storing the data into a 12 bits integer). |
| | + | with 12bits we have an reading accuracy of 3.3 / 4095 = 0.000805 Volts, so 0.805 mV. |
| | | | |
| | === Low resolution reading === | | === Low resolution reading === |
| Ligne 67 : |
Ligne 68 : |
| | === High resolution reading === | | === High resolution reading === |
| | | | |
| − | /* ---------------------------------------------
| + | <syntaxhighlight lang="c"> |
| − | * | Code d'exemple du kit d'expérimentation
| + | // where is wired the TMP36 |
| − | * | Arduino
| + | const int temperaturePin = A3; // analogue input |
| − | * | CIRC-10 .: Température :.
| |
| − | * ---------------------------------------------
| |
| − | * Un programme simple qui affiche la température
| |
| − | * actuelle dans la fenêtre de monitoring/débogage
| |
| − | */
| |
| − | | |
| − | // Variable pour broche du TMP36
| |
| − | const int temperaturePin = A3; // entrée analogique | |
| − | // sur laquelle la broche Vout du TMP36 est
| |
| − | // connectée. La résolution est 10mv/degré
| |
| − | // centigrade avec 500 mV de décalage/offset
| |
| − | // pour permettre la lecture de température
| |
| − | // négative.
| |
| | | | |
| | + | // Executed once when starting the microcontroler |
| | void setup() { | | void setup() { |
| − | Serial.begin(9600); // Démarrer la connexion série avec l'ordinateur. | + | // start serial connexion with the computer |
| − | // Pour voir le le résultat, ouvrez le « moniteur série », le
| + | Serial.begin(9600); |
| − | // dernier bouton dans la barre d'outil.
| + | // Upgrade the ADC resolution from 10 to 12 bits. |
| − | // (celui qui ressemble à une boite ayant une antenne).
| |
| | analogReadResolution( 12 ); | | analogReadResolution( 12 ); |
| | } | | } |
| | | | |
| − | void loop() { // s'exécute encore et encore | + | // Executed again and again |
| − | // Acquérir la tension lue sur le senseur de température. | + | void loop() { |
| | + | // read the voltage of TMP36 |
| | float voltage = getVoltage(temperaturePin); | | float voltage = getVoltage(temperaturePin); |
| | Serial.print( "Voltage : " ); | | Serial.print( "Voltage : " ); |
| | Serial.print( voltage ); | | Serial.print( voltage ); |
| | Serial.println( " Volts" ); | | Serial.println( " Volts" ); |
| − | // conversion de 10mV par degré avec un décalage (offset) de 500 mV. | + | // convert voltage to temperature |
| − | // Degrés = ((tension - 500mV) fois 100) | + | // Degrees = (voltage - 500mV) multiplied by 100 |
| | float temperature = (voltage - .5) *100; | | float temperature = (voltage - .5) *100; |
| | Serial.print( "Temperature: " ); | | Serial.print( "Temperature: " ); |
| − | Serial.print(temperature); //affiche résultat | + | Serial.print(temperature); |
| | Serial.println( " °C" ); | | Serial.println( " °C" ); |
| | Serial.println( " " ); | | Serial.println( " " ); |
| − | delay(1000); // Attendre une seconde. | + | delay(1000); // wait 1 second |
| | } | | } |
| | | | |
| | /* | | /* |
| − | * getVoltage() - retourne la tension d'une entrée analogique identifiée par 'pin' | + | * getVoltage() - return the voltage of an analog pin |
| | */ | | */ |
| | float getVoltage(int pin){ | | float getVoltage(int pin){ |
| − | // Convertir valeur digital de 0 à 4095 vers une valeur entre 0 et 3.3 volts. | + | // Convert digital value between 0 & 4095 to |
| − | // (chaque unité lue vaut ~ 3.3 / 4095 = 0.805 millivolts | + | // voltage between 0 & 3.3 volts. |
| − | Serial.println( analogRead(pin) );
| + | // (each unit equal 3.3 / 4095 = 0.805 millivolts) |
| | return (analogRead(pin) * .000805); | | return (analogRead(pin) * .000805); |
| | } | | } |
| | + | </syntaxhighlight> |
| | | | |
| | {{ENG-CANSAT-TRAILER}} | | {{ENG-CANSAT-TRAILER}} |