Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vitormhenrique/OctoPrint-Enclosure
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormhenrique committed Oct 17, 2021
2 parents d30a3d4 + 84d03b6 commit ae2091c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 57 deletions.
126 changes: 70 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,98 +28,116 @@ Here is a list of possibilities:

Check pictures on thingiverse: http://www.thingiverse.com/thing:2245493

**Software**
## Installation

Install the plugin using the Plugin Manager bundled with OctoPrint, you can search for the Enclosure plugin or just use the url: https://github.com/vitormhenrique/OctoPrint-Enclosure/archive/master.zip.

To control the encosure temperature or get temperature trigged events, you need to install and configure a temperature sensor. This plugin can support DHT11, DHT22, AM2302, DS18B20, SI7021, BME280 and TMP102 temperature sensors.
## Hardware

* For the DHT11, DHT22 and AM2302 follow this steps:
This plugin support many hardware temperature sensors, led, relays, heater...

Here are detailled instructions on how to setup them.

### Temperature sensors

To control the enclosure temperature or get temperature triggered events, you need to install and configure a temperature sensor. This plugin can support DHT11, DHT22, AM2302, DS18B20, SI7021, BME280 and TMP102 temperature sensors.


#### DHT11, DHT22 and AM2302 sensors

Wire the sensor following the wiring diagram on the pictures on thingiverse, you can use any GPIO pin.

For DHT11 and DHT22 sensors, don't forget to connect a 4.7K - 10K resistor from the data pin to VCC. Also, be aware that DHT sensors some times can not work reliably on linux, this is a limitation of reading DHT sensors from Linux--there's no guarantee the program will be given enough priority and time by the Linux kernel to reliably read the sensor. Another common issue is the power supply. you need a constant and good 3.3V, sometimes a underpowered raspberry pi will not have a solid 3.3V power supply, so you could try powering the sensor with 5V and using a level shifter on the read pin.

You need to install Adafruit library to use the temperature sensor on raspberry pi.

Open raspberry pi terminal and type:
Open a raspberry pi terminal and type:

<pre><code>cd ~
```
cd ~
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl
sudo python setup.py install</code></pre>
sudo python setup.py install
```

Note: All libraries need to be installed on raspberry pi system python not octoprint virtual environment.

You can test the library by using:

<pre><code>cd examples
```
cd examples
sudo ./AdafruitDHT.py 2302 4</code></pre>

```
Note that the first argument is the temperature sensor (11, 22, or 2302), and the second argument is the GPIO that the sensor was connected.

* For the DS18B20 sensor:
#### DS18B20 sensor

Follow the wiring diagram on the pictures on thingiverse. The DS18B20 uses "1-wire" communication protocol, DS18B20 only works on GPIO pin number 4 by default. You also need to add OneWire support for your raspberry pi.

Start by adding the following line to /boot/config.txt
Start by adding the following line to `/boot/config.txt`

<pre><code>dtoverlay=w1-gpio</code></pre>
```
dtoverlay=w1-gpio
```

After rebooting, you can check if the OneWire device was found properly with
<pre><code>dmesg | grep w1-gpio</code></pre>
```
dmesg | grep w1-gpio
```

You should see something like
<pre><code>[ 3.030368] w1-gpio onewire@0: gpio pin 4, external pullup pin -1, parasitic power 0</code></pre>
```
[ 3.030368] w1-gpio onewire@0: gpio pin 4, external pullup pin -1, parasitic power 0
```

If you're using the internal pullup resistor, you'll need to enable it manually by running these Python commands. Or, you can simply configure the sensor inside of the Enclosure plugin, which will do this for you.

```python
import RPi.GPIO as GPIO
You should be able to test your sensor by rebooting your system with `sudo reboot`. When the Pi is back up and you're logged in again, type the commands you see below into a terminal window. When you are in the 'devices' directory, the directory starting '28-' may have a different name, so `cd` to the name of whatever directory is there.

PIN=4
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
```

You should be able to test your sensor by rebooting your system with sudo reboot. When the Pi is back up and you're logged in again, type the commands you see below into a terminal window. When you are in the 'devices' directory, the directory starting '28-' may have a different name, so cd to the name of whatever directory is there.

<pre><code>sudo modprobe w1-gpio
sudo modprobe w1-gpio
sudo modprobe w1-therm
cd /sys/bus/w1/devices
ls
cd 28-xxxx (change this to match what serial number pops up)
cat w1_slave</code></pre>
cat w1_slave
```

The response will either have YES or NO at the end of the first line. If it is yes, then the temperature will be at the end of the second line, in 1/000 degrees C.
The response will either have `YES` or `NO` at the end of the first line. If it is `YES`, then the temperature will be at the end of the second line, in 1/000 degrees C.

Copy the serial number, you will need to configure the plugin. Note that for the serial number includes the 28-, for example 28-0000069834ff.
Copy the serial number, you will need to configure the plugin. Note that for the serial number includes the `28-`, for example `28-0000069834ff`.

The DS18B20 needs a pullup resistor on the data pin. On modern Pi models, you can use a resistor built into the Pi, configured in software. To do this, set the "Input Pull Resistor" option to "Input Pullup". If this doesn't work, you need to use a 4.7K to 10K resistor from the data pin to VCC.

* For the SI7021, BME280, TMP102 and MCP9808 sensors
#### SI7021, BME280, TMP102 and MCP9808 sensors

Enable I2C on your raspberry pi, depending on raspi-config version, step by step can be different:

<pre><code>Run sudo raspi-config
Use the down arrow to select 9 Advanced Options
Arrow down to A7 I2C
Select yes when it asks you to enable I2C
Also select yes when it asks about automatically loading the kernel module
Use the right arrow to select the button
Select yes when it asks to reboot
</code></pre>
```
sudo raspi-config
```
* Use the down arrow to select 9 Advanced Options
* Arrow down to A7 I2C
* Select yes when it asks you to enable I2C
* Also select yes when it asks about automatically loading the kernel module
* Use the right arrow to select the button
* Select yes when it asks to reboot

Install some packages (on raspberry pi system python not octoprint virtual environment):

<pre><code>sudo apt-get install i2c-tools python-pip python-smbus</code></pre>
```
sudo apt-get install i2c-tools python-pip python-smbus
```

Find the address of the sensor:

<pre><code>i2cdetect -y 1</code></pre>
```
i2cdetect -y 1
```

* For Neopixel
### Neopixel

If your setup does not have pip install pip:
`sudo apt-get install python-pip`
Expand All @@ -137,40 +155,36 @@ Also backlist the audio kernel:

`sudo nano /etc/modprobe.d/snd-blacklist.conf`

add the `blacklist snd_bcm2835` to the end of the file:

add the `blacklist snd_bcm2835` to the end of the file.

* GPIO
### GPIO

This release uses RPi.GPIO to control IO of raspberry pi, it should install and work automatically. If it doesn't please update your octoprint with the latest release of octopi.
You can use relays / mosfets to control you lights, heater, lockers etc... If you want to control mains voltage I recommend using [PowerSwitch Tail II](http://www.powerswitchtail.com/).

**Hardware**

You can use relays / mosfets to control you lights, heater, lockers etc... If you want to control mains voltage I recommend using PowerSwitch Tail II.

* Relay
### Relay

The relays module that I used couple [SainSmart 2-Channel Relay Module](https://www.amazon.com/gp/product/B0057OC6D8?ie=UTF8&tag=3dpstuff-20&camp=1789&linkCode=xm2&creativeASIN=B0057OC6D8). Those relays are active low, that means that they will turn on when you put LOW on the output of your pin. In order to not fry your Raspberry Pi pay attention on your wiring connection: remove the jumper link and connect 3.3v to VCC, 5V to JD-VCC and Ground to GND.

* Heater
### Heater

For heating my enclosure I got a $15 lasko inside my enclosure. I opened it and added a relay to the mains wire. If you’re uncomfortable soldering or dealing with high voltage, please check out the [PowerSwitch Tail II](http://www.powerswitchtail.com/) . The PowerSwitch Tail II is fully enclosed, making it a lot safer.
For heating my enclosure I got a $15 lasko inside my enclosure. I opened it and added a relay to the mains wire. If you’re uncomfortable soldering or dealing with high voltage, please check out the [PowerSwitch Tail II](http://www.powerswitchtail.com/). It is fully enclosed, making it a lot safer.

**CAUTION: VOLTAGE ON MAINS WIRE CAN KILL YOU, ONLY ATTEMPT TO DO THIS IF YOU KNOW WHAT YOU ARE DOING, AND DO AT YOUR OWN RISK**

**CAUTION 2: THIS HEATER IS NOT INTENDED TO FUNCTION THIS WAY AND IT MIGHT BE A FIRE HAZARD. DO IT AT YOUR OWN RISK**

* Cooler
### Cooler

You can get a [USB Mini Desktop Fan](https://www.amazon.com/gp/product/B00WM7TRTY?ie=UTF8&tag=3dpstuff-20&camp=1789&linkCode=xm2&creativeASIN=B00WM7TRTY) and control it over a relay.

* Filament sensor
### Filament sensor

You have the ability to add a filament sensor to the enclosure, it will automatically pause the print and run a gcode command to change the filament if you run out of filament, I can be any type of filament sensor, the sensor should connect to ground if is set as an "active low" when the filament run out or 3.3v if the sensor is set as "active high" when detected the end of filament, it does not matter if it is normally open or closed, that will only interfere on your wiring. I'm using the following sensor:

http://www.thingiverse.com/thing:1698397

**Configuration**
## Plugin configuration

You need to enable what do you want the plugin to control. Settings from plugin version < 3.6 are not compatible anymore, you will loose all settings after upgrading the plugin.

Expand Down Expand Up @@ -208,24 +222,24 @@ After selecting GPIO for the input type, and selecting output control on the act
Selecting print control on the action type will trigger printer actions when the configured GPIO receives a signal. The actions can be Resume and Pause a print job or Change Filament. You can use the "change filament" action and set up the input GPIO according to your filament sensor, for example, if your filament sensor connects to ground when detects the end of the filament, you should choose PULL UP resistors and detect the event on the falling edge.
You can also add mechanical buttons to pause, resume and change filaments near your printer for convenience.

**Advanced Area**
## Advanced Area

If you want to enable notifications check the following [issue](https://github.com/vitormhenrique/OctoPrint-Enclosure/issues/36)

You can control outputs using a simple [API](https://github.com/vitormhenrique/OctoPrint-Enclosure/wiki/API-Control)

Or use [g-code](https://github.com/vitormhenrique/OctoPrint-Enclosure/wiki/G-CODE-Control) commands

**Tab Order**
### Tab Order

I often use more this plugin than the time-lapse tab, so having the plugin appear before the timelapse is better for me.

You can do this by changing the config.yaml file as instructed on [octoprint documentation ](http://docs.octoprint.org/en/master/configuration/config_yaml.html). Unless defined differently via the command line config.yaml is located at ~/.octoprint.
You can do this by changing the config.yaml file as instructed on [octoprint documentation ](http://docs.octoprint.org/en/master/configuration/config_yaml.html). Unless defined differently via the command line config.yaml is located at `~/.octoprint`.

You just need to add the following section:


<pre><code>appearance:
```
appearance:
components:
order:
tab:
Expand All @@ -234,4 +248,4 @@ You just need to add the following section:
- gcodeviewer
- terminal
- plugin_enclosure
</code></pre>
```
19 changes: 19 additions & 0 deletions octoprint_enclosure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import json
import copy
from smbus2 import SMBus
from .getPiTemp import PiTemp
import struct


Expand Down Expand Up @@ -988,6 +989,9 @@ def get_sensor_data(self, sensor):
temp, hum = self.read_bme280_temp(sensor['temp_sensor_address'])
elif sensor['temp_sensor_type'] == "am2320":
temp, hum = self.read_am2320_temp() # sensor has fixed address
elif sensor['temp_sensor_type'] == "rpi":
temp = self.read_rpi_temp() # rpi CPU Temp
hum = 0
elif sensor['temp_sensor_type'] == "si7021":
temp, hum = self.read_si7021_temp(sensor['temp_sensor_address'], sensor['temp_sensor_i2cbus'])
elif sensor['temp_sensor_type'] == "tmp102":
Expand Down Expand Up @@ -1127,7 +1131,9 @@ def read_bme280_temp(self, address):
stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read()
if self._settings.get(["debug_temperature_log"]) is True:
self._logger.debug("BME280 result: %s", stdout)

temp, hum = stdout.decode("utf-8").split("|")

return (self.to_float(temp.strip()), self.to_float(hum.strip()))
except Exception as ex:
self._logger.info(
Expand Down Expand Up @@ -1155,6 +1161,19 @@ def read_am2320_temp(self):
"Failed to execute python scripts, try disabling use SUDO on advanced section of the plugin.")
self.log_error(ex)
return (0, 0)

def read_rpi_temp(self):
try:
pitemp = PiTemp()
temp = pitemp.getTemp()
if self._settings.get(["debug_temperature_log"]) is True:
self._logger.debug("Pi CPU result: %s", temp)
return temp
except Exception as ex:
self._logger.info(
"Failed to get pi cpu temperature")
self.log_error(ex)
return 0

def read_si7021_temp(self, address, i2cbus):
try:
Expand Down
10 changes: 10 additions & 0 deletions octoprint_enclosure/getPiTemp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from gpiozero import CPUTemperature

import ctypes
import struct
import sys

class PiTemp:
def getTemp(self):
temp = CPUTemperature()
return '{0:0.1f}'.format(temp.temperature)
3 changes: 2 additions & 1 deletion octoprint_enclosure/templates/enclosure_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@
<option value="am2320">AM2320</option>
<option value="tmp102">TMP102</option>
<option value="max31855">MAX31855</option>
<option value="rpi">Raspberry Pi CPU</option>
<option value="mcp9808">MCP9808</option>
<option value="temp_raw_i2c">Raw I2C Temperature</option>
<option value="hum_raw_i2c">Raw I2C Humidity</option>
Expand Down Expand Up @@ -728,7 +729,7 @@
</div>

<!-- /ko -->
<!-- ko ifnot: ($data.temp_sensor_type() == "18b20") || ($data.temp_sensor_type() == "si7021") || ($data.temp_sensor_type() == "bme280") || ($data.temp_sensor_type() == "am2320") || ($data.temp_sensor_type() == "tmp102") || ($data.temp_sensor_type() == "max31855") || ($data.temp_sensor_type() == "mcp9808") || ($data.temp_sensor_type() == "temp_raw_i2c") || ($data.temp_sensor_type() == "hum_raw_i2c") -->
<!-- ko ifnot: ($data.temp_sensor_type() == "rpi") || ($data.temp_sensor_type() == "18b20") || ($data.temp_sensor_type() == "si7021") || ($data.temp_sensor_type() == "bme280") || ($data.temp_sensor_type() == "am2320") || ($data.temp_sensor_type() == "tmp102") || ($data.temp_sensor_type() == "max31855") || ($data.temp_sensor_type() == "mcp9808") || ($data.temp_sensor_type() == "temp_raw_i2c") || ($data.temp_sensor_type() == "hum_raw_i2c") -->
<div class="control-group">
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('Sensor Pin') }}</label>
<div class="controls">
Expand Down

0 comments on commit ae2091c

Please sign in to comment.