Read the temperaure in celsius degrees each two seconds and display the value on the serial port.

Dependencies:   Hotboards_temp mbed

Committer:
Hotboards
Date:
Tue Mar 22 22:19:40 2016 +0000
Revision:
0:f1fb5b7d66a9
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Hotboards 0:f1fb5b7d66a9 1 /*
Hotboards 0:f1fb5b7d66a9 2 Hotboards temp Library - reading temperature
Hotboards 0:f1fb5b7d66a9 3 Read the temperaure in celsius degrees each two seconds and display
Hotboards 0:f1fb5b7d66a9 4 the value on the serial port.
Hotboards 0:f1fb5b7d66a9 5 The circuit
Hotboards 0:f1fb5b7d66a9 6 * VDD --> 3.3v
Hotboards 0:f1fb5b7d66a9 7 * SDA --> PB_9
Hotboards 0:f1fb5b7d66a9 8 * SCL --> PB_8
Hotboards 0:f1fb5b7d66a9 9 * GND --> GND
Hotboards 0:f1fb5b7d66a9 10 Library and example created by Diego from Hotboards
Hotboards 0:f1fb5b7d66a9 11 Ported to mbed by Pedro from Hotboards
Hotboards 0:f1fb5b7d66a9 12 This example code is in the public domain.
Hotboards 0:f1fb5b7d66a9 13 */
Hotboards 0:f1fb5b7d66a9 14 #include "mbed.h"
Hotboards 0:f1fb5b7d66a9 15 #include "Hotboards_temp.h"
Hotboards 0:f1fb5b7d66a9 16
Hotboards 0:f1fb5b7d66a9 17 // new instance of serial port
Hotboards 0:f1fb5b7d66a9 18 Serial pc(USBTX, USBRX);
Hotboards 0:f1fb5b7d66a9 19 //I2C instance for the library
Hotboards 0:f1fb5b7d66a9 20 I2C device( I2C_SDA, I2C_SCL );
Hotboards 0:f1fb5b7d66a9 21 // instance a sensor with address number 7 (none of the jumpers on the board is short circuted)
Hotboards 0:f1fb5b7d66a9 22 // and also 0.5 celsius degrees resolution
Hotboards 0:f1fb5b7d66a9 23 Hotboards_temp sensor( device, Sensor_7);
Hotboards 0:f1fb5b7d66a9 24
Hotboards 0:f1fb5b7d66a9 25
Hotboards 0:f1fb5b7d66a9 26 int main( void )
Hotboards 0:f1fb5b7d66a9 27 {
Hotboards 0:f1fb5b7d66a9 28 // sensor init
Hotboards 0:f1fb5b7d66a9 29 sensor.init();
Hotboards 0:f1fb5b7d66a9 30
Hotboards 0:f1fb5b7d66a9 31 while(1)
Hotboards 0:f1fb5b7d66a9 32 {
Hotboards 0:f1fb5b7d66a9 33 // read temperature in celcius degrees
Hotboards 0:f1fb5b7d66a9 34 float temp = sensor.read();
Hotboards 0:f1fb5b7d66a9 35 // print it to the serial port
Hotboards 0:f1fb5b7d66a9 36 pc.printf("Temperature: %3.1f C\r\n",temp);
Hotboards 0:f1fb5b7d66a9 37 // take the next value after 2 sec (just to not read too often)
Hotboards 0:f1fb5b7d66a9 38 wait(1);
Hotboards 0:f1fb5b7d66a9 39 }
Hotboards 0:f1fb5b7d66a9 40 }
Hotboards 0:f1fb5b7d66a9 41
Hotboards 0:f1fb5b7d66a9 42