Rock Monitoring  V 1.0
PCT2075.cpp
Go to the documentation of this file.
1 #include "PCT2075.h"
6 {
7 
8 }
12 void PCT2075::init(uint8_t slaveAddr)
13 {
14  switch (slaveAddr)
15  {
16  case 0:
17  {
18  i2cSlaveAddr = 0x48; // with pins SA0=0, SA1=0
19  }
20  break;
21  case 1:
22  {
23  i2cSlaveAddr = 0x49; // with pins SA0=1, SA1=0
24  }
25  break;
26  case 2:
27  {
28  i2cSlaveAddr = 0x4A; // with pins SA0=0, SA1=1
29  }
30  break;
31  case 3:
32  {
33  i2cSlaveAddr = 0x4B; // with pins SA0=1, SA1=1
34  }
35  break;
36  default:
37  {
38  //i2c slave address not set
39  }
40  }
41 
42  uint8_t databyte;
43 
44  // write 0000 0000 = 0x00 to temperature sensor control register 1 to place it in active mode
45  databyte = 0x00; //active mode
46  Wire.writeBytes( i2cSlaveAddr, 0x01, &databyte,(uint8_t) 1);
47 
48 }
49 
55 uint8_t PCT2075::getTemp(int8_t & Temp)
56 {
57 uint8_t databyte;
58 
59  uint8_t Buffer[2]; // read buffer
60 
61  if (Wire.readBytes(i2cSlaveAddr, PCT2075_TEMP, Buffer, 1) == 1)
62  {
63  // Temp = ((Buffer[0] << 8) | Buffer[1])>>5; //Temperature reading 2 Bytes
64  Temp = Buffer[0]; //Temperature reading 1 Byte
65  }
66  else
67  {
68  USB.print(F("I2C error"));
69  return RETURN_ERROR;
70  }
71  return RETURN_OK;
72 }
73 
77 {
78  uint8_t databyte;
79 
80  // write 0000 0001 = 0x01 to temperature sensor control register 1, to place it in shutdown mode
81  databyte = 0x01; //active mode
82  Wire.writeBytes( i2cSlaveAddr, 0x01, &databyte,(uint8_t) 1);
83 }
#define RETURN_ERROR
Definition: Constants.h:4
#define RETURN_OK
Definition: Constants.h:9
uint8_t i2cSlaveAddr
Definition: PCT2075.h:40
#define PCT2075_TEMP
Definition: PCT2075.h:8
PCT2075()
Definition: PCT2075.cpp:5
void goToSleep()
This method sets the Temperature Sensor in shutdown mode.
Definition: PCT2075.cpp:76
void init(uint8_t slaveAddr)
This method initializes the temperature sensor PCT2075.
Definition: PCT2075.cpp:12
uint8_t getTemp(int8_t &Temp)
This method gets the temperatur value of the temperature sensor PCT2075.
Definition: PCT2075.cpp:55