Skip to content

Instantly share code, notes, and snippets.

@pingud98
Created June 18, 2016 10:43
Show Gist options
  • Save pingud98/5b2a6c10a02f19406fd0cc70f80e2b30 to your computer and use it in GitHub Desktop.
Save pingud98/5b2a6c10a02f19406fd0cc70f80e2b30 to your computer and use it in GitHub Desktop.
//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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment