Skip to content

Instantly share code, notes, and snippets.

@mdvorak
Last active June 5, 2025 16:03
Show Gist options
  • Select an option

  • Save mdvorak/2fccca3fa9f76f5a2e11e567797c76d6 to your computer and use it in GitHub Desktop.

Select an option

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.

@ZeBrainlesz
Copy link

Hello i cant get my sensor id .

This is what ls gives me:
sudo ls /sys/bus/w1/devices/ 00-380000000000 00-580000000000 00-d80000000000 w1_bus_master1
And what lsmod gives me.
lsmod | grep w1 w1_gpio_cl 16384 0 w1_therm 28672 0 w1_gpio 16384 0
I cheked the wiring and is good.

@theopensourcerer
Copy link

theopensourcerer commented May 28, 2025

Thanks for the response. I found a solution and thought I’d share it—maybe somebody else wants to try this.
How to Compile the Kernel Headers and w1-gpio-cl

@math-milan You are a star!

I spent ages trying to work out how to compile the module on my BTT CB1. See this ticket: pstolarz/w1-gpio-cl#7

Anyway - I came across your very clear "howto" and it worked first time. Many thanks for taking the time to share.

@FABIOHIPOLITO
Copy link

I'm having the following errors, could you help me?

biqu@BTT-CB1:$ sudo modprobe w1-gpio-cl
modprobe: ERROR: could not insert 'w1_gpio_cl': Exec format error
biqu@BTT-CB1:
$

biqu@BTT-CB1:~$ dmesg
[ 2248.082372] w1_gpio_cl: version magic '5.16.17 SMP mod_unload aarch64' should be '5.16.17-sun50iw9 SMP mod_unload aarch64'
[ 2259.413458] w1_gpio_cl: version magic '5.16.17 SMP mod_unload aarch64' should be '5.16.17-sun50iw9 SMP mod_unload aarch64'

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