max31865 0.1.7 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/max31865.rb +47 -34
- data/lib/max31865/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69cbff5d02f5701e1b98a9f7b67017facfa78b84455c5200d16ff4ebe925f6c1
|
4
|
+
data.tar.gz: 613d468a902e9b4bc369ae10bcbbec41ecc832900ec934ad2808cba8ce3ce29e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c2bf110fc27a4d63634de577d12d22c41291a57695f98ba46cb75e579f5eb05ead43697ed72a7eceb91eb7c5b81b55385c6ce267fd423ccea901a64491fa2c7
|
7
|
+
data.tar.gz: 7eef1c2d368568968289955f83a6ae314f33fb1eefa7eb94568828db1cf6c1fb260883a6f18aa49ba0fd689b74bbd4bfa397a957dad3f15f00cca78863ed1b9d
|
data/README.md
CHANGED
@@ -26,9 +26,9 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
m = MAX31865.new(chip = 0, type = :k, clock = 2_000_000)
|
28
28
|
|
29
|
-
m.config #
|
29
|
+
m.config # Run once (shutdown resets chip)
|
30
30
|
|
31
|
-
m.read #
|
31
|
+
m.read # RTD Temp (Float in celsius)
|
32
32
|
|
33
33
|
|
34
34
|
## Raspberry v3
|
@@ -60,6 +60,12 @@ and contributors are expected to adhere to the [Contributor Covenant](http://con
|
|
60
60
|
|
61
61
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
62
62
|
|
63
|
-
|
63
|
+
|
64
|
+
## Notes
|
65
|
+
|
66
|
+
For Thermocouples, check out https://github.com/nofxx/MAX31856
|
67
|
+
|
68
|
+
Thanks to https://github.com/hackenbergstefan/MAX31865
|
69
|
+
|
64
70
|
|
65
71
|
Everyone interacting in the MAX31865 project’s codebases and issue trackers is expected to follow the [code of conduct](https://github.com/nofxx/max31865/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/max31865.rb
CHANGED
@@ -5,13 +5,14 @@ require 'pi_piper'
|
|
5
5
|
# MAX31865
|
6
6
|
#
|
7
7
|
# Thanks to https://github.com/steve71/MAX31865/blob/master/max31865.py
|
8
|
+
# https://github.com/hackenbergstefan/MAX31865/blob/master/max31865.py
|
8
9
|
class MAX31865
|
9
|
-
attr_accessor :chip, :clock, :wires, :hz
|
10
|
+
attr_accessor :chip, :clock, :type, :ref, :wires, :hz
|
10
11
|
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# Resistance at 0 degC for 400ohm R_Ref
|
13
|
+
R0 = 100.0
|
14
|
+
|
15
|
+
# Constants for Callendar-Van-Dusen equation
|
15
16
|
A = 0.00390830
|
16
17
|
B = -0.000000577500
|
17
18
|
# C = -4.18301e-12 # for -200 <= T <= 0 (degC)
|
@@ -29,11 +30,12 @@ class MAX31865
|
|
29
30
|
0x80 => 'High threshold limit (Cable fault/open)',
|
30
31
|
0x40 => 'Low threshold limit (Cable fault/short)',
|
31
32
|
0x04 => 'Overvoltage or Undervoltage Error',
|
32
|
-
|
33
|
+
0xff => 'Circuit Fault'
|
33
34
|
}.freeze
|
34
35
|
|
35
|
-
def initialize(chip
|
36
|
-
@chip
|
36
|
+
def initialize(chip: 0, ref: 430.0, clock: 2_000_000)
|
37
|
+
@chip = CHIPS[chip]
|
38
|
+
@ref = ref
|
37
39
|
@clock = clock
|
38
40
|
end
|
39
41
|
|
@@ -80,7 +82,7 @@ class MAX31865
|
|
80
82
|
# 0b11010010 or 0xD2 for continuous auto conversion
|
81
83
|
# at 60Hz (faster conversion)
|
82
84
|
# 0b10110010 = 0xB2
|
83
|
-
def config(byte =
|
85
|
+
def config(byte = 0b11010010)
|
84
86
|
spi_work do |spi|
|
85
87
|
spi.write(0x80, byte)
|
86
88
|
end
|
@@ -99,28 +101,39 @@ class MAX31865
|
|
99
101
|
private
|
100
102
|
|
101
103
|
#
|
102
|
-
# Callendar-Van Dusen
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
104
|
+
# Callendar-Van Dusen equations
|
105
|
+
#
|
106
|
+
# Convert 0 <= raw_temp < 2^l5 to temperature in oC using quadratic polynom:
|
107
|
+
#
|
108
|
+
# R(T)=R(0)(1+A*T+B*T^{2})
|
109
|
+
#
|
110
|
+
# => T = (-A*R(0) + sqrt(A^2 R(0)^2 - 4*B*R(0)*(R(0) - R(T)))) / (2*B*R(0))
|
107
111
|
#
|
108
112
|
# quadratic formula:
|
109
113
|
# for 0 <= T <= 850 (degC)
|
110
114
|
#
|
111
|
-
def
|
112
|
-
temp = -(A * R0)
|
113
|
-
|
114
|
-
temp /=
|
115
|
-
#
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
def quadratic(adc, rtd)
|
116
|
+
temp = -(A * R0)
|
117
|
+
temp += Math.sqrt(A * A * R0 * R0 - 4 * B * R0 * (R0 - rtd))
|
118
|
+
temp /= 2 * B * R0
|
119
|
+
# puts "Callendar-Van Dusen Temp (degC > 0): #{temp}C"
|
120
|
+
temp < 0 ? (adc / 32) - 256 : temp
|
121
|
+
end
|
122
|
+
|
123
|
+
# """
|
124
|
+
# Convert 0 <= raw_temp < 2^15 to temperature in oC using quartic polynom:
|
125
|
+
#
|
126
|
+
# R(T) = R(0)[1+A*T+B*T^{2}+(T-100)C*T^{3}]
|
127
|
+
#
|
128
|
+
# => 0 = R(0)[1 + A*T + B*T^2 - 100*C*T^3 + C*T^4] - R(T)
|
129
|
+
#
|
130
|
+
# Solution is calculated numerically.
|
131
|
+
#
|
132
|
+
def quartic(rtd)
|
133
|
+
temp = rtd * R0 / (2**15 - 1)
|
134
|
+
roots = [C * R0, -100 * R0 * C, B * R0, A * R0, R0 - temp]
|
135
|
+
.map { |n| Math.sqrt(n) }
|
136
|
+
Math.abs(roots[-1])
|
124
137
|
end
|
125
138
|
|
126
139
|
#
|
@@ -129,13 +142,13 @@ class MAX31865
|
|
129
142
|
def read_temp(raw)
|
130
143
|
read_fault(raw[7])
|
131
144
|
rtd_msb, rtd_lsb = raw[1], raw[2]
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
puts "PT100 Resistance: #{rtd} ohms"
|
138
|
-
|
145
|
+
adc = ((rtd_msb << 8) | rtd_lsb) >> 1
|
146
|
+
# puts "RTD ADC Code: #{adc}"
|
147
|
+
# temp_line = (adc / 32.0) - 256.0
|
148
|
+
# puts "Straight Line Approx. Temp: #{temp_line}C"
|
149
|
+
rtd = (adc * ref) / 32_768.0 # PT100 Resistance
|
150
|
+
# puts "PT100 Resistance: #{rtd} ohms"
|
151
|
+
quadratic(adc, rtd)
|
139
152
|
end
|
140
153
|
|
141
154
|
#
|
data/lib/max31865/version.rb
CHANGED