Modifications

Sauter à la navigation Sauter à la recherche
969 octets ajoutés ,  30 novembre 2014 à 19:31
Ligne 23 : Ligne 23 :  
Notice how we are powering the sensor from 3.3V* pin instead of the regular 3.3V. This is because the 3.3V* pin gives out a (LC) clean filtered voltage, ideal for analog applications like these. If the readings you get are noisy or inconsistent, add a 0.01uF (10nF) ceramic capacitor between the analog input pin (in this case, A7) and GND as shown in the set up. Ideally, the sensor should be placed away from the Core so that the heat dissipated by the Core does not affect the temperature readings.
 
Notice how we are powering the sensor from 3.3V* pin instead of the regular 3.3V. This is because the 3.3V* pin gives out a (LC) clean filtered voltage, ideal for analog applications like these. If the readings you get are noisy or inconsistent, add a 0.01uF (10nF) ceramic capacitor between the analog input pin (in this case, A7) and GND as shown in the set up. Ideally, the sensor should be placed away from the Core so that the heat dissipated by the Core does not affect the temperature readings.
    +
== Le code ==
 +
Voici le code proposé par Spark que nous avons traduit pour faciliter la compréhension.
 +
 +
<nowiki>// -----------------
 +
// Read temperature
 +
// -----------------
 +
 +
// Create a variable that will store the temperature value
 +
double temperature = 0.0;
 +
 +
void setup()
 +
{
 +
  // Register a Spark variable here
 +
  Spark.variable("temperature", &temperature, DOUBLE);
 +
 +
  // Connect the temperature sensor to A7 and configure it
 +
  // to be an input
 +
  pinMode(A7, INPUT);
 +
}
 +
 +
void loop()
 +
{
 +
  int reading = 0;
 +
  double voltage = 0.0;
 +
 +
  // Keep reading the sensor value so when we make an API
 +
  // call to read its value, we have the latest one
 +
  reading = analogRead(A7);
 +
 +
  // The returned value from the Core is going to be in the range from 0 to 4095
 +
  // Calculate the voltage from the sensor reading
 +
  voltage = (reading * 3.3) / 4095;
 +
 +
  // Calculate the temperature and update our static variable
 +
  temperature = (voltage - 0.5) * 100;
 +
}</nowiki>
   −
Source: [http://docs.spark.io/examples/#measuring-the-temperature docs.spark.io/examples/#measuring-the-temperature]
   
{{Spark-Core-Hacking-TRAILER}}
 
{{Spark-Core-Hacking-TRAILER}}
 +
 +
<small>Source: [http://docs.spark.io/examples/#measuring-the-temperature docs.spark.io/examples/#measuring-the-temperature]</small>
29 837

modifications

Menu de navigation