commit f68987aaaaa0608941a58f66a2776f14e7764ea4 Author: James Devine Date: Sat Jun 18 12:43:09 2016 +0200 diff --git a/ArduinoDueInternalTemp b/ArduinoDueInternalTemp new file mode 100644 index 0000000..6d2d53f --- /dev/null +++ b/ArduinoDueInternalTemp @@ -0,0 +1,41 @@ +//read the temperature of the integrated sensor on the Arduino DUE + +float trans = 3.3/4096; +float offset = 0.8; +float factor = 0.00256; +int fixtemp = 27; + +void setup() { + Serial.begin(9600); +} + +void loop() { + float treal = fixtemp + (( trans * temperatur() ) - offset ) / factor; + Serial.println(treal); + delay(10); +} + +uint32_t temperatur() { + uint32_t ulValue = 0; + uint32_t ulChannel; + + // Enable the corresponding channel + adc_enable_channel(ADC, ADC_TEMPERATURE_SENSOR); + + // Enable the temperature sensor + adc_enable_ts(ADC); + + // Start the ADC + adc_start(ADC); + + // Wait for end of conversion + while ((adc_get_status(ADC) & ADC_ISR_DRDY) != ADC_ISR_DRDY); + + // Read the value + ulValue = adc_get_latest_value(ADC); + + // Disable the corresponding channel + adc_disable_channel(ADC, ADC_TEMPERATURE_SENSOR); + + return ulValue; +} \ No newline at end of file