Tedd OKANO
/
TempSensor_LM75B
TempSensor_LM75B_test.cpp@0:b1a5601983d4, 2010-01-23 (annotated)
- Committer:
- okano
- Date:
- Sat Jan 23 13:45:00 2010 +0000
- Revision:
- 0:b1a5601983d4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:b1a5601983d4 | 1 | /* |
okano | 0:b1a5601983d4 | 2 | * I2C digital temperature sensor "LM75B" library test app |
okano | 0:b1a5601983d4 | 3 | * |
okano | 0:b1a5601983d4 | 4 | * LM75B is an I2C based digital temperature sensor |
okano | 0:b1a5601983d4 | 5 | * http://www.nxp.com/pip/LM75B_2.html |
okano | 0:b1a5601983d4 | 6 | * |
okano | 0:b1a5601983d4 | 7 | * Expecting to use the pins 9 and 10 for I2C bus |
okano | 0:b1a5601983d4 | 8 | * these pins should be pulled-up properly. |
okano | 0:b1a5601983d4 | 9 | * |
okano | 0:b1a5601983d4 | 10 | * The temperature read out will be shown on terminal on the PC screen. |
okano | 0:b1a5601983d4 | 11 | * |
okano | 0:b1a5601983d4 | 12 | * In this demo code, two LM75B devices can be driven. |
okano | 0:b1a5601983d4 | 13 | * These two devices should have different I2C address setting |
okano | 0:b1a5601983d4 | 14 | * using its address pins (LM75B's A0 to A2 (pins 5 to 7)). |
okano | 0:b1a5601983d4 | 15 | * One LM75B should have all those pins tied to GND. |
okano | 0:b1a5601983d4 | 16 | * And another should have the pin A0(pin7) pulled-up. |
okano | 0:b1a5601983d4 | 17 | * |
okano | 0:b1a5601983d4 | 18 | * From the software, those devices can be accessed by I2C addresses |
okano | 0:b1a5601983d4 | 19 | * "0x90" and "0x92". |
okano | 0:b1a5601983d4 | 20 | * It will not be as "0x90" and "0x91" because the address has |
okano | 0:b1a5601983d4 | 21 | * 7 bit only and stuffed to left. So the "A0" setting become 0xX2. |
okano | 0:b1a5601983d4 | 22 | * The LSB does not care because it will be set by I2C libraly when |
okano | 0:b1a5601983d4 | 23 | * it transfer the data for read and write. |
okano | 0:b1a5601983d4 | 24 | * |
okano | 0:b1a5601983d4 | 25 | * This code is new version that can handle the LM75B are the objects. |
okano | 0:b1a5601983d4 | 26 | * |
okano | 0:b1a5601983d4 | 27 | * Copyright (c) 2010 Tedd OKANO |
okano | 0:b1a5601983d4 | 28 | * Released under the MIT License: http://mbed.org/license/mit |
okano | 0:b1a5601983d4 | 29 | * |
okano | 0:b1a5601983d4 | 30 | * revision 1.0 16-Jan-2010 a. 1st release |
okano | 0:b1a5601983d4 | 31 | * revision 1.1 23-Jan-2010 a. class name has been changed from LM75B to TempSensor_LM75B |
okano | 0:b1a5601983d4 | 32 | * b. copyright notice added |
okano | 0:b1a5601983d4 | 33 | */ |
okano | 0:b1a5601983d4 | 34 | |
okano | 0:b1a5601983d4 | 35 | #include "mbed.h" |
okano | 0:b1a5601983d4 | 36 | #include "TempSensor_LM75B.h" |
okano | 0:b1a5601983d4 | 37 | |
okano | 0:b1a5601983d4 | 38 | Serial pc(USBTX, USBRX); // tx, rx |
okano | 0:b1a5601983d4 | 39 | |
okano | 0:b1a5601983d4 | 40 | I2C i2c( p9, p10 ); // sda, scl |
okano | 0:b1a5601983d4 | 41 | |
okano | 0:b1a5601983d4 | 42 | TempSensor_LM75B thermo_sensor_0( &i2c ); // sensor_0 using with default I2C address "0x90". |
okano | 0:b1a5601983d4 | 43 | TempSensor_LM75B thermo_sensor_1( &i2c, 0x92 ); // sensor_1 gaved I2C address since that address pin A0=HIGH. |
okano | 0:b1a5601983d4 | 44 | |
okano | 0:b1a5601983d4 | 45 | int main() { |
okano | 0:b1a5601983d4 | 46 | int i = 0; |
okano | 0:b1a5601983d4 | 47 | |
okano | 0:b1a5601983d4 | 48 | while (1) { |
okano | 0:b1a5601983d4 | 49 | pc.printf( " (%d) sensor_0= %4.1f, sensor_1= %4.1f(degree-C)\n", i++, (float)thermo_sensor_0, (float)thermo_sensor_1 ); |
okano | 0:b1a5601983d4 | 50 | wait( 1 ); |
okano | 0:b1a5601983d4 | 51 | } |
okano | 0:b1a5601983d4 | 52 | } |
okano | 0:b1a5601983d4 | 53 |