HiPi
Perl Modules for Raspberry Pi
Version 0.72 - released 06 June 2018

HiPi::Interface::TMP102

This module provides an I2C interface to the TMP102 temperature sensor.

Methods

Create a new instance of the class

use HiPi qw( :tmp102 );
use HiPi::Interface::TMP102;
my $tmp = HiPi::Interface::TMP102->new( address => 0x48 );

Read the temperature value from the TMP102

use HiPi qw( :tmp102 );
.....
my $temperature = $tmp->read_temperature

Get or set the extended mode bit from the configuration registers.

If $bool is defined, will set the extended mode bit to that value.

Returns 1 or 0 - the value of the extended mode bit.

Note that if you change extended_mode, the high and low limit values stored in the TMP103 registers are not converted to the new precision level. If you are using the high and low limit values, you must set them again after setting extended mode.

use HiPi qw( :tmp102 );
.....
my $mode = $tmp->extended_mode;
$tmp->extended_mode(1);

Get or set the shutdown mode bit from the configuration registers.

If $bool is defined, will set the shutdown mode bit to that value.

Returns 1 or 0 - the value of the shutdown mode bit.

use HiPi qw( :tmp102 );
.....
my $mode = $tmp->shutdown_mode;
$tmp->shutdown_mode(1);

Read the temperature from the TMP102 using one shot mode if the device is currently in shutdown mode.

use HiPi qw( :tmp102 );
.....
my $temperature = $tmp->one_shot_temperature;

Get or set the the conversion rate configuration registers.

If $rate is defined, will set the conversion to that value.

Returns and accepts as $rate param one of the following constants:

  • TMP102_CR_0_25HZ
  • TMP102_CR_1HZ
  • TMP102_CR_4HZ
  • TMP102_CR_8HZ

use HiPi qw( :tmp102 );
.....
my $crate = $tmp->conversion_rate();
$tmp->conversion_rate(TMP102_CR_4HZ);

Get or set the polarity bit from the configuration registers.

If $bool is defined, will set the polarity bit to that value.

Returns 1 or 0 - the value of the polarity bit.

use HiPi qw( :tmp102 );
.....
my $mode = $tmp->polarity;
$tmp->polarity(1);

Get or set the thermostat mode bit from the configuration registers.

If $bool is defined, will set the thermostat mode bit to that value.

Returns 1 or 0 - the value of the thermostat mode bit.

use HiPi qw( :tmp102 );
.....
my $mode = $tmp->thermostat_mode;
$tmp->thermostat_mode(1);

Read the alert bit from the configuration registers

Returns 1 or 0 - the value of the alert bit.

use HiPi qw( :tmp102 );
.....
my $alert = $tmp->alert;

Get or set the temperature for the high_limit value.

If $temp is defined, will set the high limit to that value.

Note that if you change extended_mode, the high and low limit values stored in the TMP103 registers are not converted to the new precision level. If you are using the high and low limit values, you must set them again after setting extended mode.

use HiPi qw( :tmp102 );
.....
my $limit = $tmp->high_limit;
$tmp->high_limit(80);

Get or set the temperature for the low_limit value.

If $temp is defined, will set the low limit to that value.

Note that if you change extended_mode, the high and low limit values stored in the TMP103 registers are not converted to the new precision level. If you are using the high and low limit values, you must set them again after setting extended mode.

use HiPi qw( :tmp102 );
.....
my $limit = $tmp->low_limit;
$tmp->low_limit(75);

Get or set the the fault queue configuration registers.

If $faults is defined, will set the fault queue to that value.

Returns and accepts as $faults param one of the following constants:

  • TMP102_FAULTS_1
  • TMP102_FAULTS_2
  • TMP102_FAULTS_4
  • TMP102_FAULTS_6

use HiPi qw( :tmp102 );
.....
my $faults = $tmp->fault_queue();
$tmp->dault_queue(TMP102_FAULTS_4);