Class: MAX31865

Inherits:
Object
  • Object
show all
Defined in:
lib/max31865.rb,
lib/max31865/version.rb

Overview

Constant Summary collapse

R0 =

Resistance at 0 degC for 400ohm R_Ref

100.0
A =

Constants for Callendar-Van-Dusen equation

0.00390830
B =
-0.000000577500
# C = -4.18301e-12 # for -200 <= T <= 0 (degC)
C =

C = -4.18301e-12 # for -200 <= T <= 0 (degC)

-0.00000000000418301
# C = 0 # for 0 <= T <= 850 (degC)
CHIPS =

C = 0 # for 0 <= T <= 850 (degC)

{
  0 => PiPiper::Spi::CHIP_SELECT_0,
  1 => PiPiper::Spi::CHIP_SELECT_1,
  2 => PiPiper::Spi::CHIP_SELECT_BOTH,
  3 => PiPiper::Spi::CHIP_SELECT_NONE
}.freeze
FAULTS =
{
  0x80 => 'High threshold limit (Cable fault/open)',
  0x40 => 'Low threshold limit (Cable fault/short)',
  0x04 => 'Overvoltage or Undervoltage Error',
  0xff => 'Circuit Fault'
}.freeze
VERSION =
'0.1.9'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chip: 0, ref: 430.0, clock: 2_000_000) ⇒ MAX31865

Returns a new instance of MAX31865.



36
37
38
39
40
# File 'lib/max31865.rb', line 36

def initialize(chip: 0, ref: 430.0, clock: 2_000_000)
  @chip  = CHIPS[chip]
  @ref   = ref
  @clock = clock
end

Instance Attribute Details

#chipObject

Returns the value of attribute chip.



10
11
12
# File 'lib/max31865.rb', line 10

def chip
  @chip
end

#clockObject

Returns the value of attribute clock.



10
11
12
# File 'lib/max31865.rb', line 10

def clock
  @clock
end

#hzObject

Returns the value of attribute hz.



10
11
12
# File 'lib/max31865.rb', line 10

def hz
  @hz
end

#refObject

Returns the value of attribute ref.



10
11
12
# File 'lib/max31865.rb', line 10

def ref
  @ref
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/max31865.rb', line 10

def type
  @type
end

#wiresObject

Returns the value of attribute wires.



10
11
12
# File 'lib/max31865.rb', line 10

def wires
  @wires
end

Instance Method Details

#config(byte = 0b11010010) ⇒ Object

Run once config

Optionally set samples

0x8x to specify ‘write register value’ 0xx0 to specify ‘configuration register’

Config Register


bit 7 : Vbias -> 1 (ON) bit 6 : Conversion Mode -> 0 (MANUAL) bit 5 : 1-shot ->1 (ON) bit 4 : 3-wire select -> 1 (3 wire config) bit 3-2: fault detection cycle -> 0 (none) bit 1 : fault status clear -> 1 (clear any fault) bit 0 : 50/60 Hz filter select -> 0 (60Hz)

0b11010010 or 0xD2 for continuous auto conversion at 60Hz (faster conversion) 0b10110010 = 0xB2



85
86
87
88
89
90
# File 'lib/max31865.rb', line 85

def config(byte = 0b11010010)
  spi_work do |spi|
    spi.write(0x80, byte)
  end
  sleep 0.2 # give it 200ms for conversion
end

#readObject

Read temperature!



95
96
97
98
99
# File 'lib/max31865.rb', line 95

def read
  spi_work do |spi|
    read_temp(spi.write(Array.new(8, 0x01)))
  end
end

#spi_workObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/max31865.rb', line 42

def spi_work
  PiPiper::Spi.begin do |spi|
    # Set cpol, cpha
    PiPiper::Spi.set_mode(1, 1)

    # Setup the chip select behavior
    spi.chip_select_active_low(true)

    # Set the bit order to MSB
    spi.bit_order PiPiper::Spi::MSBFIRST

    # Set the clock divider to get a clock speed of 2MHz
    spi.clock clock

    spi.chip_select(chip) do
      yield spi
    end
  end
end