added MAX31855 support

This commit is contained in:
Marshall Eubanks
2019-03-06 14:12:44 -05:00
parent e71d81cece
commit e96284873e
3 changed files with 74 additions and 2 deletions

View File

@@ -555,6 +555,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
temp = self.read_tmp102_temp(
sensor['temp_sensor_address'])
hum = 0
elif sensor['temp_sensor_type'] == "max31855":
temp = self.read_max31855_temp(
sensor['temp_sensor_address'])
hum = 0
else:
self._logger.info("temp_sensor_type no match")
temp = None
@@ -708,7 +712,24 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
"Failed to excecute python scripts, try disabling use SUDO on advanced section.")
self.log_error(ex)
return 0
def read_max31855_temp(self, address):
try:
script = os.path.dirname(os.path.realpath(__file__)) + "/max31855.py"
args = ["python", script, str(address)]
if self._settings.get(["debug"]) is True and self._settings.get(["debug_temperature_log"]) is True:
self._logger.info("Temperature MAX31855 cmd: %s", " ".join(args))
proc = Popen(args, stdout=PIPE)
stdout, _ = proc.communicate()
if self._settings.get(["debug"]) is True and self._settings.get(["debug_temperature_log"]) is True:
self._logger.info("MAX31855 result: %s", stdout)
return self.to_float(stdout.strip())
except Exception as ex:
self._logger.info(
"Failed to excecute python scripts, try disabling use SUDO on advanced section.")
self.log_error(ex)
return 0
def handle_pwm_linked_temperature(self):
try:
for pwm_output in list(filter(lambda item: item['output_type'] == 'pwm' and item['pwm_temperature_linked'], self.rpi_outputs)):

View File

@@ -0,0 +1,27 @@
import ctypes
import struct
import sys
import Adafruit_GPIO.SPI as SPI
import Adafruit_MAX31855.MAX31855 as MAX31855
def main():
# Get bus address if provided or use default address
SPI_DEVICE = 0
if len(sys.argv) >= 2:
SPI_DEVICE = int(sys.argv[1], 0)
if not 0 <= SPI_DEVICE <= 1:
raise ValueError("Invalid address value")
# Raspberry Pi hardware SPI configuration.
SPI_PORT = 0
sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
temp = sensor.readTempC()
print('{0:0.1f}'.format(temp))
if __name__ == "__main__":
main()

View File

@@ -536,6 +536,7 @@
<option value="si7021">SI7021</option>
<option value="bme280">BME280</option>
<option value="tmp102">TMP102</option>
<option value="max31855">MAX31855</option>
</select>
<span class="help-inline">
<span class="label label-important">Attention</span> You need to install and configure the necessary libraries for the temperature sensor, check
@@ -579,7 +580,30 @@
</div>
</div>
<!-- /ko -->
<!-- ko ifnot: ($data.temp_sensor_type() == "18b20") || ($data.temp_sensor_type() == "si7021") || ($data.temp_sensor_type() == "bme280") || ($data.temp_sensor_type() == "tmp102") -->
<!-- ko if: ($data.temp_sensor_type() == "max31855") -->
<div class="control-group">
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('Sensor Pin') }}</label>
<div class="controls">
<input type="text" class="input-block-level" value="MISO / SCLK" disabled="true">
<span class="help-inline">GPIO pin for temperature sensor need to connect the sensor to SPI. Serial Clock to GPIO 1 (SCLK) and Master In/Slave Out Data to GPIO
9 (MISO)
</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('Sensor Address (CE Select)') }}</label>
<div class="controls">
<select data-bind="value: temp_sensor_address">
<option value="">Select CE</option>
<option value="0">CE0</option>
<option value="1">CE1</option>
</select>
<span class="help-inline">CE select: CE0 on GPIO 8 or CE1 on GPIO 7</span>
</div>
</div>
<!-- /ko -->
<!-- ko ifnot: ($data.temp_sensor_type() == "18b20") || ($data.temp_sensor_type() == "si7021") || ($data.temp_sensor_type() == "bme280") || ($data.temp_sensor_type() == "tmp102") || ($data.temp_sensor_type() == "max31855") -->
<div class="control-group">
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('Sensor Pin') }}</label>
<div class="controls">