Hello world code for PCT2075 and LM75B component class library. The PCT2075 is a temperature-to-digital converter featuring +/-1 degree-C accuracy over -25 degree-C to +100 degree-C range. It uses an on-chip band gap temperature sensor and Sigma-Delta A-to-D conversion technique with an overtemperature detection output that is a drop-in replacement for other LM75 series thermal sensors.

Dependencies:   PCT2075 mbed

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Thu Mar 05 06:15:11 2015 +0000
Parent:
1:5398b0799e20
Commit message:
Initial version

Changed in this revision

PCT2075.lib Show annotated file Show diff for this revision Revisions of this file
PCT2075/PCT2075.cpp Show diff for this revision Revisions of this file
PCT2075/PCT2075.h Show diff for this revision Revisions of this file
PCT2075/base_class/I2CTempSensor.cpp Show diff for this revision Revisions of this file
PCT2075/base_class/I2CTempSensor.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5398b0799e20 -r edd678dcf504 PCT2075.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCT2075.lib	Thu Mar 05 06:15:11 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/okano/code/PCT2075/#0cdfb3ea5969
diff -r 5398b0799e20 -r edd678dcf504 PCT2075/PCT2075.cpp
--- a/PCT2075/PCT2075.cpp	Fri Feb 27 12:35:30 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-#include    "I2CTempSensor.h"
-#include    "PCT2075.h"
-
-PCT2075::PCT2075( PinName i2c_sda, PinName i2c_scl, char i2c_address ) 
-    : I2CTempSensor( i2c_sda, i2c_scl, i2c_address )
-{
-    init();
-}
-
-PCT2075::PCT2075( I2C &i2c_obj, char i2c_address )
-    : I2CTempSensor( i2c_obj, i2c_address )
-{
-    init();
-}
-
-PCT2075::~PCT2075()
-{
-}
-
-float PCT2075::read( void )
-{
-    typedef I2CTempSensor base;
-
-    return( base::read16() / 256.0 );
-}
-
-PCT2075::operator float( void )
-{
-    return( read() );
-}
diff -r 5398b0799e20 -r edd678dcf504 PCT2075/PCT2075.h
--- a/PCT2075/PCT2075.h	Fri Feb 27 12:35:30 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-/** PCT2075 and LM75B component class library
- *  PCT2075 と LM75B 用のコンポーネント・クラス・ライブラリです
- *
- *  This is new NXP PCT2075 and classic LM75B component class library
- *  This works for both PCT2075 and LM75B
- *
- *  @author  Tedd OKANO
- *  @version 1.0
- *  @date    28-Feb-2015
- *
- *  For the details of PCT2075 and LM75B..
- *  PCT2075 and LM75Bの詳細は..
- *      http://i2c_sda.nxp.com/documents/data_sheet/PCT2075.pdf
- *      http://i2c_sda.nxp.com/documents/data_sheet/LM75B.pdf
- */
-
-#ifndef MBED_PCT2075_H
-#define MBED_PCT2075_H
-
-#include    "mbed.h"
-#include    "I2CTempSensor.h"
-
-/** PCT2075 class library クラスライブラリ
- *
- *  クラスライブラリは非常にシンプルなインターフェースを提供します
- *
- *  コード例:
- *  @code
- *  #include "mbed.h"
- *  #include "I2CTempSensor.h"
- *
- *  I2CTempSensor  temp0( p28, p27 );
- *
- *  I2C         i2c( p28, p27 );
- *  I2CTempSensor  temp1( i2c );
- *
- *
- *  int main()
- *  {
- *      float   t0;
- *      float   t1;
- *
- *      i2c.frequency( 400 * 1000 );
- *
- *      while(1) {
- *          t0   = temp0;
- *          t1   = temp1;
- *          printf( "temp = %7.3f, %7.3f\r\n", t0, t1 );
- *          wait( 1 );
- *      }
- *  }
- *  @endcode
- */
-class PCT2075 : I2CTempSensor
-{
-public:
-    /** I2Cピンとスレーブアドレスを指定し,インスタンスを作成します
-     *
-     * @param i2c_sda       I2C-bus i2c_sdaピン
-     * @param i2c_scl       I2C-bus i2c_sclピン
-     * @param i2c_address   (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90)
-     */
-    PCT2075( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS );
-
-    /** I2Cオブジェクトとスレーブアドレスを指定し,インスタンスを作成します
-     *
-     * @param i2c_obj I2C オブジェクト (インスタンス)
-     * @param i2c_address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90)
-     */
-    PCT2075( I2C &i2c_obj, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS );
-
-    /** デストラクタ
-     */
-    virtual ~PCT2075();
-
-    /** 温度の読み出し
-     *
-     *  @return 摂氏温度を返します(float型)
-     */
-    virtual float   read( void );
-
-    /** 温度の読み出し
-     *
-     *  @return オブジェクトが読みだした値を返すようにしています
-     */
-    virtual operator float( void );
-
-private:
-    /** デフォルト・スレーブアドレス */
-    enum {
-        DEFAULT_I2C_SLAVE_ADDRESS   = 0x90
-    };
-};
-
-#endif  //  MBED_PCT2075_H
-
diff -r 5398b0799e20 -r edd678dcf504 PCT2075/base_class/I2CTempSensor.cpp
--- a/PCT2075/base_class/I2CTempSensor.cpp	Fri Feb 27 12:35:30 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#include "I2CTempSensor.h"
-
-I2CTempSensor::I2CTempSensor( PinName i2c_sda, PinName i2c_scl, char address ) 
-    : i2c_p( new I2C( i2c_sda, i2c_scl ) ), i2c( *i2c_p ), adr( address )
-{
-    init();
-}
-
-I2CTempSensor::I2CTempSensor( I2C &i2c_obj, char address )
-    : i2c_p( NULL ), i2c( i2c_obj ), adr( address )
-{
-    init();
-}
-
-I2CTempSensor::~I2CTempSensor()
-{
-    if ( NULL != i2c_p )
-        delete  i2c_p;
-}
-
-void I2CTempSensor::init( void )
-{
-    char    command[ 2 ];
-
-    command[ 0 ]    = LM75B_Conf;
-    command[ 1 ]    = 0x00;
-
-    i2c.write( adr, command, 2 );
-}
-
-short I2CTempSensor::read16( void )
-{
-    char    command[ 2 ];
-
-    command[ 0 ]    = LM75B_Temp;
-
-    i2c.write( adr, command, 1 );  // Send command string
-    i2c.read(  adr, command, 2 );  // read two bytes data
-
-    return ( (command[ 0 ] << 8)| command[1] );
-}
diff -r 5398b0799e20 -r edd678dcf504 PCT2075/base_class/I2CTempSensor.h
--- a/PCT2075/base_class/I2CTempSensor.h	Fri Feb 27 12:35:30 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-/** PCT2075 and LM75B component class library
- *  PCT2075 と LM75B 用のコンポーネント・クラス・ライブラリです
- *
- *  This is new NXP PCT2075 and classic LM75B component class library
- *  This works for both PCT2075 and LM75B
- *
- *  @author  Tedd OKANO
- *  @version 1.0
- *  @date    28-Feb-2015
- *
- *  For the details of PCT2075 and LM75B..
- *  PCT2075 and LM75Bの詳細は..
- *      http://www.nxp.com/documents/data_sheet/PCT2075.pdf
- *      http://www.nxp.com/documents/data_sheet/LM75B.pdf
- */
-
-#ifndef MBED_I2CTempSensor_H
-#define MBED_I2CTempSensor_H
-
-#include "mbed.h"
-
-/** I2CTempSensor class library クラスライブラリ
- *
- *  This class is an abstract class. So no instance can be made.
- *  このクラスは抽象クラスなのでインスタンスを作成することはできません
- *  クラスライブラリは非常にシンプルなインターフェースを提供します
- */
-
-class I2CTempSensor
-{
-public:
-    virtual float   read( void )    = 0;
-    virtual operator float( void )  = 0;
-
-protected:
-
-    /** LM75Bのレジスタ名とアドレス */
-    enum command_reg    {
-        LM75B_Temp  = 0x00,
-        LM75B_Conf,
-        LM75B_Thyst,
-        LM75B_Tos
-    };
-
-    /** I2Cピンとスレーブアドレスを指定し,インスタンスを作成します
-     *
-     * @param i2c_sda I2C-bus i2c_sdaピン
-     * @param i2c_scl I2C-bus i2c_sclピン
-     * @param address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90)
-     */
-    I2CTempSensor( PinName i2c_sda, PinName i2c_scl, char address );
-
-    /** I2Cオブジェクトとスレーブアドレスを指定し,インスタンスを作成します
-     *
-     * @param i2c_obj I2C オブジェクト (インスタンス)
-     * @param address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90)
-     */
-    I2CTempSensor( I2C &i2c_obj, char address );
-
-    /** デストラクタ
-     */
-    ~I2CTempSensor();
-
-    /** 初期化
-     */
-    void    init( void );
-
-    /** 温度の読み出し
-     *
-     *  @return 摂氏温度を返します(float型)
-     */
-    short   read16( void );
-
-private:
-    I2C     *i2c_p;
-    I2C     &i2c;
-    char    adr;
-};
-
-#endif  //  MBED_I2CTempSensor_H
-
diff -r 5398b0799e20 -r edd678dcf504 main.cpp
--- a/main.cpp	Fri Feb 27 12:35:30 2015 +0000
+++ b/main.cpp	Thu Mar 05 06:15:11 2015 +0000
@@ -1,25 +1,16 @@
-/** Hello code for "test_LM75B" */
+/** Hello code for "PCT2075" and "LM75B" */
 
 #include "mbed.h"
 #include "PCT2075.h"
-
-PCT2075  temp0( p28, p27 );
+//#include "LM75B.h"
 
-I2C         i2c( p28, p27 );
-PCT2075  temp1( i2c );
-
+PCT2075 temp_sensor( p28, p27 );
+//LM75B temp_sensor( p28, p27 );
 
 int main()
 {
-    float   t0;
-    float   t1;
-
-    i2c.frequency( 400 * 1000 );
-
     while(1) {
-        t0   = temp0;
-        t1   = temp1;
-        printf( "temp = %7.3f, %7.3f\r\n", t0, t1 );
+        printf( "temp = %7.3f\r\n", (float)temp_sensor );
         wait( 1 );
     }
 }