Translate

Saturday, February 29, 2020

3D Printing - Adding enclosure temperature sensor

Another article related to OctoPrint.


Having around some DHT-22 sensors used on the fHelper MQTT project and seen a direct support of them for OctoPrint, I decided to use them to measure temperature and humidity of the enclosure, handled by OctoPrint.
In this article the steps to add the sensor to the System.

The idea is to have OctoPrint capable to monitor the enclosure temperature.
It is assumed OctoPrint running over a Raspberry Pi.

Hardware

OctoPrint can support different sensors for the temperature.
Among them the DHT-22, a sensor I did use for another project, so I have some of them around.

Here a quick schematic to connect the sensor to the Raspberry Pi running OctoPrint.

Actually used a 10k pull up resistor.
Schematic done using EasyEda

After connecting the sensor to the Raspberry, time to set up OctoPrint.
We are using the GPIO 4 on the Raspberry Pi.
This is a possible PCB for mounting the sensor :


Here's  a couple of pictures of the prototype.
Note that I did use a Raspberry Pi 0 breadboard adapter to build the prototype in order to leave more open around the heatsink.
And yes, they are expensive but I wanted something fast and safe.
I'll do some PCBs later (like the one illustrated above) using EasyEda.


The breadboard used is normally for a Raspberry Pi 0, I did choose that to leave open around the heatsink.
Be sure to mechanical block it with two screws so that is not moving when connecting the cables.
The two pin connector is for the Emergency Stop pushbutton (see other article).

The sensor used is actually an AM2302, not a DHT-22, but they are basically the same.
Just use the correct one in the settings, pinout and characteristics are the same.

Test the hardware

Before to proceed is necessary to be sure the hardware is working properly.
To do so :

  • verify with a multimeter BEFORE to power up, that all the connections are correct
  • power on the Raspberry but not attach yet the sensor
    • verify with a multimeter that the voltage on the connectors are what is expected
  • connect the sensor

Raspbian 

As indicated in the OctoPrint enclosure instructions, is necessary to have installed on the Raspbian some libraries to handle the sensor.
I copy them here for reference.


Open a terminal and login to the Raspberry Pi.
Then :
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
Note: All libraries need to be installed on Raspbian

Test the library and the hardware :
cd examples
sudo ./AdafruitDHT.py 22 4
The first argument of the test Python code is the sensor (22 for the DHT-22), the second argument is the GPIO pin, in our case : GPIO 4.

If the test is OK, is possible to proceed to activate the OctoPrint Enclosure Plugin.

This an example of working sensor :

pi@octopi:~ $ cd Adafruit_Python_DHT/examples/
pi@octopi:~/Adafruit_Python_DHT/examples $ ls
AdafruitDHT.py  google_spreadsheet.py  simpletest.py
pi@octopi:~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 2302 4 
[sudo] password for pi: 
Temp=25.7*  Humidity=25.5%
pi@octopi:~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 2302 4 
Temp=26.3*  Humidity=25.0%
pi@octopi:~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 2302 4 

Temp=26.2*  Humidity=24.9%

Enclosure Plugin

Once having the hardware installed and tested, let work on the OctoPrint Enclosure Plugin.

To mange the sensor, the enclosure plugin will be used (see also on Thingiverse), so first thing to do is to install it on OctoPrint.
Then some customizations are necessary.
Let see step by step what to do.

  • Go on the OctoPrint page and select Settings 
  • On the Plugin section, at the end (maybe is needed to scroll down) will be the Enclosure Plugin.
    Click on that
  • On the right will be possible to create an output setting or an input setting

  • Click on the button Add Inputs in the Raspberry PI Inputs section
  • Fill up the fields :
    • assign a name (I used "Temperature")
    • Select Temperature Sensor as Input Type
    • Change the type on sensor reading (AM2302)
    • Input IO number : 4

Save.

Returning on the main view of OctoPrint the enclosure temperature should be displayed when clicking on the added symbol on navbar or clicking on the extra menu.



Troubleshooting

It is possible sometime to see strange readings.
This is because reading these sensors directly form a Linux based machine, without specific settings, can create problems during the read, losing data.
And, like my case, the reading returns always zero so some troubleshooting is required.

The first thing to do is to go on the Plugin github page and see if there is a section called "troublehooting".
Yes, it is !

Reading about the DHT sensors there is a note that exactly describe my problem.
The sensor is working outside OctoPrint plugin but not inside.
The solution is to go in the Advanced section of settings and disable the "sudo" access.
Done .. and ..

The OctoPrint Enclosure plugin happily reading the temperature and humidy from the sensor.

What next ?

Now that the everything is working, the next steps will be :

  • design PCBs for sensors and hat for Raspberry
  • design an enclosure for the sensor
  • design an enclosure for the Raspberry Pi
  • install everything in the enclosure ... well AFTER the enclosure will be built :)



No comments:

Post a Comment