Skip to content

Instantly share code, notes, and snippets.

@mdvorak
Last active May 27, 2024 09:48
Show Gist options
  • Save mdvorak/2fccca3fa9f76f5a2e11e567797c76d6 to your computer and use it in GitHub Desktop.
Save mdvorak/2fccca3fa9f76f5a2e11e567797c76d6 to your computer and use it in GitHub Desktop.
DS18B20 on BigTreeTech Pi

DS18B20 on BigTreeTech Pi v1.2

BTT Pi uses AllWinner H616 CPU, and on https://github.com/bigtreetech/CB1 system, w1-gpio kernel module does not work.

However, there is an excellent custom module https://github.com/pstolarz/w1-gpio-cl

The following steps were tested on CB1 v2.3.3.

Wiring

DS18B20 Pinout
BTT Pi GPIO

Connect sensor VCC pin to 3.3V, GND to GND (obviously), and signal pin to selected GPIO. I used PC7, since it corresponds to the default w1 pin location on the Raspberry Pi header.
Don't forget to add a pull-up resistor between 3.3V and the signal pin. A 4.7 kOhm resistor is the recommended value.

NEVER connect anything while the printer is powered on!

I did not try parasitic power mode, and I don't recommend it. Klipper will shut down on subsequent read errors, and it might ruin your prints randomly. I did not have any problems with the standard 3-wire connection yet.

Compilation on CB1 system

The easiest way is to compile it directly on the device. The official guide needed to be modified slightly.

  1. sudo apt-get install build-essential bc bison flex libssl-dev
  2. sudo apt-get install linux-headers-current-sun50iw9
  3. git clone https://github.com/pstolarz/w1-gpio-cl.git
  4. cd w1-gpio-cl
  5. ln -s /lib/modules/`uname -r`/build/include/linux w1
  6. make
  7. sudo make install

DKMS

Optionally, you can install it using DKMS

sudo dkms add .
sudo dkms install w1-gpio-cl/1.2.2

where 1.2.1 is the latest w1-gpio-cl release version.

Installation

For details, read the original README.

Pin Selection

The w1-gpio-cl module does not accept pin names; instead, it needs pin index. To list all available pins, run

sudo cat /sys/kernel/debug/pinctrl/300b000.pinctrl/pinmux-pins

Find your preferred pin (note that some pins might not work). I used PC7

pin 71 (PC7): UNCLAIMED

Now you can configure module options

echo 'options w1-gpio-cl m1="gdt:71"' | sudo tee /etc/modprobe.d/w1-gpio-cl.conf

Test Config

Try loading the module manually

sudo modprobe w1-gpio-cl

Verify that the module is loaded

lsmod | grep w1

You should see something like

w1_therm               28672  0
w1_gpio_cl             16384  0

You can verify the output of the dmesg for errors.

Automatic Loading

To load the module during boot, run

echo 'w1-gpio-cl' | sudo tee /etc/modules-load.d/w1-gpio-cl.conf

Reboot and verify that the module is properly loaded and working.

Configuration

See https://www.klipper3d.org/Config_Reference.html#ds18b20-temperature-sensor

Find out connected sensor addresses

sudo ls /sys/bus/w1/devices/

You will see output like

28-011319f769fe  w1_bus_master1

With that address, add a Klipper config section like this

[temperature_sensor my_sensor]
sensor_type: DS18B20
serial_no: 28-011319f769fe
sensor_mcu: CB1

Note that sensor_mcu must be set to the host, which is CB1 by default.

After restarting Klipper, your new temperature sensor should appear in the Mainsail/Fluidd UI automatically.

@mdvorak
Copy link
Author

mdvorak commented Apr 30, 2024

It does not seem like sw issue, so check the hw.

@jonathjon
Copy link

Just tried another single sensor. Same thing, not getting anything. Took that same sensor and hooked it up to a D1 Mini with ESP Home and I get an address from it and temp readings. Sensor is good. So its a SW issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment