![](/media/cache/profiles/6c18d13e9a2e04855a83a6ce1a9117fe.jpg.50x50_q85.jpg)
Measures the temperature by using a Microchip MCP9700A analog thermometer. Result is printed to standard output.
05_analog_thermometer
Measures the temperature by using a Microchip MCP9700A analog thermometer (parameteres: 10 mV/C, 500 mV offset, VCC= 2.3-5.5V). The result is printed to standard output.
Hardware requirements:
- FRDM-KL25Z board
- MCP9700A analog thermometer connected to the A0 (PTB0) analog input
main.cpp@0:d5f4c581840b, 2015-11-18 (annotated)
- Committer:
- icserny
- Date:
- Wed Nov 18 15:31:37 2015 +0000
- Revision:
- 0:d5f4c581840b
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
icserny | 0:d5f4c581840b | 1 | /** 05_analog_thermometer |
icserny | 0:d5f4c581840b | 2 | * Measeures the temperature by using a Microchip MCP9700A |
icserny | 0:d5f4c581840b | 3 | * analog thermometer (parameteres: 10 mV/C, 500 mV offset, VCC= 2.3-5.5V) |
icserny | 0:d5f4c581840b | 4 | * Result is printed to standard output. |
icserny | 0:d5f4c581840b | 5 | * |
icserny | 0:d5f4c581840b | 6 | * Hardware requirements: |
icserny | 0:d5f4c581840b | 7 | * - FRDM-KL25Z board |
icserny | 0:d5f4c581840b | 8 | * - MCP9700A analog thermometer connected to A0 (PTB0) |
icserny | 0:d5f4c581840b | 9 | */ |
icserny | 0:d5f4c581840b | 10 | |
icserny | 0:d5f4c581840b | 11 | #include "mbed.h" |
icserny | 0:d5f4c581840b | 12 | |
icserny | 0:d5f4c581840b | 13 | AnalogIn ain(A0); // Analog input at PTB0 |
icserny | 0:d5f4c581840b | 14 | |
icserny | 0:d5f4c581840b | 15 | int main() |
icserny | 0:d5f4c581840b | 16 | { |
icserny | 0:d5f4c581840b | 17 | printf("\r\n05_analog_thermometer program\r\n"); |
icserny | 0:d5f4c581840b | 18 | while(1) { |
icserny | 0:d5f4c581840b | 19 | uint16_t raw = ain.read_u16(); // read raw 16-bit data |
icserny | 0:d5f4c581840b | 20 | float voltage = ain.read()*3300; // read voltage in millivolts |
icserny | 0:d5f4c581840b | 21 | float tempC = (voltage -500)/10; // tempereature in Celsius |
icserny | 0:d5f4c581840b | 22 | printf("ADC: 0x%04X voltage: %5.0f temp: %5.1f C\r\n",raw,voltage,tempC); |
icserny | 0:d5f4c581840b | 23 | wait(2); |
icserny | 0:d5f4c581840b | 24 | } |
icserny | 0:d5f4c581840b | 25 | } |