Tedd OKANO
/
TempSensor_LM75B
Embed:
(wiki syntax)
Show/hide line numbers
TempSensor_LM75B_test.cpp
00001 /* 00002 * I2C digital temperature sensor "LM75B" library test app 00003 * 00004 * LM75B is an I2C based digital temperature sensor 00005 * http://www.nxp.com/pip/LM75B_2.html 00006 * 00007 * Expecting to use the pins 9 and 10 for I2C bus 00008 * these pins should be pulled-up properly. 00009 * 00010 * The temperature read out will be shown on terminal on the PC screen. 00011 * 00012 * In this demo code, two LM75B devices can be driven. 00013 * These two devices should have different I2C address setting 00014 * using its address pins (LM75B's A0 to A2 (pins 5 to 7)). 00015 * One LM75B should have all those pins tied to GND. 00016 * And another should have the pin A0(pin7) pulled-up. 00017 * 00018 * From the software, those devices can be accessed by I2C addresses 00019 * "0x90" and "0x92". 00020 * It will not be as "0x90" and "0x91" because the address has 00021 * 7 bit only and stuffed to left. So the "A0" setting become 0xX2. 00022 * The LSB does not care because it will be set by I2C libraly when 00023 * it transfer the data for read and write. 00024 * 00025 * This code is new version that can handle the LM75B are the objects. 00026 * 00027 * Copyright (c) 2010 Tedd OKANO 00028 * Released under the MIT License: http://mbed.org/license/mit 00029 * 00030 * revision 1.0 16-Jan-2010 a. 1st release 00031 * revision 1.1 23-Jan-2010 a. class name has been changed from LM75B to TempSensor_LM75B 00032 * b. copyright notice added 00033 */ 00034 00035 #include "mbed.h" 00036 #include "TempSensor_LM75B.h" 00037 00038 Serial pc(USBTX, USBRX); // tx, rx 00039 00040 I2C i2c( p9, p10 ); // sda, scl 00041 00042 TempSensor_LM75B thermo_sensor_0( &i2c ); // sensor_0 using with default I2C address "0x90". 00043 TempSensor_LM75B thermo_sensor_1( &i2c, 0x92 ); // sensor_1 gaved I2C address since that address pin A0=HIGH. 00044 00045 int main() { 00046 int i = 0; 00047 00048 while (1) { 00049 pc.printf( " (%d) sensor_0= %4.1f, sensor_1= %4.1f(degree-C)\n", i++, (float)thermo_sensor_0, (float)thermo_sensor_1 ); 00050 wait( 1 ); 00051 } 00052 } 00053
Generated on Wed Jul 27 2022 19:50:07 by 1.7.2