Class: MAX31865

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

Overview

Constant Summary collapse

READ_REG =

Read registers

[0, 8].freeze
R_REF =

Reference Resistor

430.0
R0 =

Resistance at 0 degC for 400ohm R_Ref

100.0
A =
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',
  0x01 => 'RTD Open-Circuit Fault'
}.freeze
VERSION =
'0.1.7'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chip = 0, clock = 2_000_000) ⇒ MAX31865

Returns a new instance of MAX31865.



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

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

Instance Attribute Details

#chipObject

Returns the value of attribute chip.



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

def chip
  @chip
end

#clockObject

Returns the value of attribute clock.



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

def clock
  @clock
end

#hzObject

Returns the value of attribute hz.



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

def hz
  @hz
end

#wiresObject

Returns the value of attribute wires.



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

def wires
  @wires
end

Instance Method Details

#config(byte = 0xB2) ⇒ 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



83
84
85
86
87
88
# File 'lib/max31865.rb', line 83

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

#readObject

Read temperature!



93
94
95
96
97
# File 'lib/max31865.rb', line 93

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

#spi_workObject



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

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