What's new
VORON Design

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members!

Adding a temperature sensor when you're out of thermistor ports

mallcop

Member
Staff member
Voron Owner
Do you have a V0 or SW, with a SKR Mini? Are you like me and Blargedy, and want to also measure your chamber temp for bragging reasons? Are you annoyed that the SKR Mini doesn't have any good thermistor ports?

Lets fix that, with a DS18B20 digital thermistor, via the Dallas one-wire protocol. These instructions are entirely for a Raspberry Pi. I'm sure other alt-Pi's work, but I have no idea how to make it work.

Supplies:
* DS18B20 digital thermistor. Non-affiliate link: https://smile.amazon.com/HiLetgo-DS18B20-Temperature-Stainless-Waterproof/dp/B00M1PM55K/ref=sr_1_4 . This is not the only one that will work, there are several listings that will show up if you search for "DS18B20" on Amazon or eBay in this form factor. Get the ones with the premade probe, not the bare sensors.

Step 1: Installing the Pi as an MCU in Klipper
All of this will be the instructions used to add the Pi as a secondary MCU in Klipper. If you have already done this (because you used an ADXL, for instance) you can skip to Step 2. These steps are lifted from Klipper's documentation, found at https://www.klipper3d.org/RPi_microcontroller.html .

First, SSH into your Pi. How to do this is outside the scope of this post. Run the following steps one at a time in the terminal:
Code:
sudo service klipper stop
sudo cp "~/klipper/scripts/klipper-mcu-start.sh" /etc/init.d/klipper_mcu
sudo update-rc.d klipper_mcu defaults
cd ~/klipper
make menuconfig      (here, set "Microcontroller Architecture" to "Linux process", save and exit)
make flash
sudo service klipper start

Step 2: Enabling Dallas 1-wire
Add an overlay to the end of your boot config:
Code:
echo "dtoverlay=w1-gpio" | sudo tee -a /boot/config.txt
sudo reboot

Step 3: Python script to enable Raspberry Pi pullup
The DS18B20 needs a pullup to work, and we can use software pullups in the Pi itself. The way I've found to do it is with a one-and-done Python script that executes on startup. SSH back in to the pi, and run the following (copy+paste the whole block, and run it in one shot):
Code:
echo '#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)' > ~/ds18b20.py
chmod +x ~/ds18b20.py
sudo ./ds18b20.py

If there are no errors, run the following command:
sudo crontab -e

Add this line to the end of the file:
@reboot /home/pi/ds18b20.py

Step 4: Prepare the sensor itself
You must power the Pi down before doing this step. You run a real risk of breaking your Pi if you plug things into it while powered on!
Thanks to Blargedy for the pictures! The pins we are using are the following in the GPIO header on the Pi: gpio_pins.png

Crimp 3 Dupont-style connectors onto the wires, making sure the rear wings grip the insulation and the front wings tightly grip the wire itself:
crimped_ends.jpg

Insert the wires into a 1x5 header as shown:
assembled_plug.jpg

Plug the header into your POWERED DOWN Pi as shown (the top blue wires are power in):
installed_pi.jpg

Step 5: Find the DS18B20
Power the machine back on and wait for the Pi to boot. Once it's running again, SSH back in, and run the following command to look for your temperature sensor:
ls /sys/bus/w1/devices/

You'll hopefully see something like:
Code:
pi@fluiddpi:~ $ ls /sys/bus/w1/devices/
28-01191f2eaf2f  w1_bus_master1

The important part is the 28-xxxxxxxxx. That is the DS18B20 sensor on the bus. If you don't have anything that looks like that, something is wrong. Copy the whole ID (mine is "28-01191f2eaf2f", yours will be different), and add this entire section to your printer.cfg:
Code:
[mcu rpi]
serial: /tmp/klipper_host_mcu

[temperature_sensor chamber]
sensor_type: DS18B20
sensor_mcu: rpi
serial_no: 28-01191f2eaf2f     ; you MUST use your own ID here

Do a firmware restart, and your new sensor should show up in your UI:
chamber_sensor.png
 
Last edited:

yenda

New member
Trusted Advisor
Voron Owner
A few comments to complement @mallcop's contribution. 1-wire bus even on raspberry pi can handle several of these probes and it's not hard to connect them.
The connection is shown on the following speedpony scheme.
Screenshot 2022-12-03 at 9.58.58 PM.png
Might look complex, but let's analyze what we see... We see three temp sensors (T1, T2, T3) and they are independently, in parallel, connected to those three pins of raspberry (to be precise, we would say "on the same bus"). There is also lonely looking resistor connected between the power (V+) and signal(S) pin. That resistor is called a "pull-up resistor". While the raspberry pins have an internal pull-up, in my experimentation I've found you will need the external pull-up (and not use the ds18b20.py script).
While in theory, you could solder all together, it might be better to create the following helper board
IMG_4867.jpg
When you turn the board from the other way, you will see it's a bit more advanced soldering but nothing terrible
Screenshot 2022-12-03 at 9.53.06 PM.jpg
You see the connectors are again soldered in parallel on the bus (realized as the three parallel wires). The first goes in the raspberry, the other are used to plug in sensors.
Once you have enabled the 1-wire bus in the raspberry pi (as shown above), you will automatically see all available devices (linux will enumerate them automatically)
pi@mainsailos:~ $ ls /sys/bus/w1/devices/ 28-0300a279b4db 28-0316a2791c28 w1_bus_master1

The two sensors from our image have addresses 28-0300a279b4db and 28-0316a2791c28.
It's easy to display the temperature as well:
pi@mainsailos:~ $ cat /sys/bus/w1/devices/28-0300a279b4db/temperature 21125 pi@mainsailos:~ $ cat /sys/bus/w1/devices/28-0316a2791c28/temperature 20750

To use them in klipper, just create multiple sections
[temperature_sensor chamber] sensor_type: DS18B20 sensor_mcu: rpi serial_no: 28-0300a279b4db ; you MUST use your own ID here [temperature_sensor chamber2] sensor_type: DS18B20 sensor_mcu: rpi serial_no: 28-0316a2791c28 ; you MUST use your own ID here (second ID)
Can be used to measure the temp in the chamber on multiple spots and/or the temp of steppers and/or temp of PSUs... Your choice...
In theory, one 1-wire bus supports up to 63 devices, in reality, you will hit limits much sooner (probably under 10 devices)
 

yenda

New member
Trusted Advisor
Voron Owner
Might be easy to create custom PCB for this, similar to the fan multiplier PCB that are sometimes useful
 

yenda

New member
Trusted Advisor
Voron Owner
One important thing I forgot to add is that these sensors (and the bus itself) are relatively slow, so do not use them to control heaters and other dangerous stuff.
 

Dave

Well-known member
Staff member
Voron Owner
This is great! Another option that adds more controllable channels as well as two thermistor ports is getting a Klipper Expander board. As “old” as it is, the board still makes a lot of sense for stuff like this, and it’s reasonably priced through lots of suppliers.
 

garrettwp

Active member
I run one on my V0 and it’s been working well. Newer boards do have more port options, but the expander is a good solution for those running older boards like the SKR Mini e3 v2.
 

mallcop

Member
Staff member
Voron Owner
Part of my desire for figuring these out is related to the WIP thread I have. The NanoPI Neo is super easy to get, but only has 1 easily-accessible USB port. The Klipper Expander can only talk over USB, so if the USB port is taken up with webcam / Pico+ADXL, you're kind of SOL.
 
Top