Class: MAX31865
- Inherits:
-
Object
- Object
- MAX31865
- Defined in:
- lib/max31865.rb,
lib/max31865/version.rb
Overview
MAX31865
Thanks to github.com/steve71/MAX31865/blob/master/max31865.py
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
-
#chip ⇒ Object
Returns the value of attribute chip.
-
#clock ⇒ Object
Returns the value of attribute clock.
-
#hz ⇒ Object
Returns the value of attribute hz.
-
#wires ⇒ Object
Returns the value of attribute wires.
Instance Method Summary collapse
-
#config(byte = 0xB2) ⇒ Object
Run once config.
-
#initialize(chip = 0, clock = 2_000_000) ⇒ MAX31865
constructor
A new instance of MAX31865.
-
#read ⇒ Object
Read temperature!.
- #spi_work ⇒ Object
Constructor Details
Instance Attribute Details
#chip ⇒ Object
Returns the value of attribute chip.
9 10 11 |
# File 'lib/max31865.rb', line 9 def chip @chip end |
#clock ⇒ Object
Returns the value of attribute clock.
9 10 11 |
# File 'lib/max31865.rb', line 9 def clock @clock end |
#hz ⇒ Object
Returns the value of attribute hz.
9 10 11 |
# File 'lib/max31865.rb', line 9 def hz @hz end |
#wires ⇒ Object
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 |
#read ⇒ Object
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_work ⇒ Object
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 |