Skip to content

Commit b477270

Browse files
committed
feat(mainsailos): add documentation for using Linux RPi as a secondary MCU in Klipper
1 parent 40ff167 commit b477270

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

22.1 KB
Loading
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
html_title: Linux RPi MCU - MainsailOS
3+
description: Learn how to set up your SBC (e.g. Raspberry Pi) as a secondary MCU in Klipper to use GPIOs and buses (I2C, SPI) directly within your printer configuration.
4+
social:
5+
cards_layout_options:
6+
title: Linux RPi MCU
7+
---
8+
9+
# Linux RPi MCU
10+
11+
Your single-board computer (SBC), such as a Raspberry Pi, can be used as a secondary MCU in Klipper. This allows you to
12+
use the GPIOs and buses (I2C, SPI) of your SBC directly in your Klipper configuration. For example to control
13+
additional fans, LEDs, or to read sensors without needing extra hardware.
14+
15+
## Install the Systemd Service
16+
17+
The `klipper-mcu` service must start before Klipper itself. To install and enable it, run:
18+
19+
```bash
20+
cd ~/klipper/
21+
sudo cp ./scripts/klipper-mcu.service /etc/systemd/system/
22+
sudo systemctl enable klipper-mcu.service
23+
```
24+
25+
## Build the Micro-Controller Code
26+
27+
Start by configuring the firmware for the Linux process. Run:
28+
29+
```bash
30+
cd ~/klipper/
31+
make clean
32+
make menuconfig
33+
```
34+
35+
<figure markdown="span">
36+
![make menuconfig](../../images/mainsailos/make-menuconfig-linux-process.png)
37+
<figcaption>make menuconfig</figcaption>
38+
</figure>
39+
40+
In the menu, set **Microcontroller Architecture** to **Linux process**, then press `Q` to exit and press `Y` to save the
41+
configuration.
42+
43+
## Flash the Micro-Controller
44+
45+
To build and install the firmware, run:
46+
47+
```bash
48+
sudo systemctl stop klipper.service
49+
make flash
50+
sudo systemctl start klipper.service
51+
```
52+
53+
!!! tip "Permission Denied Error"
54+
If `klippy.log` reports a "Permission denied" error when connecting to `/tmp/klipper_host_mcu`, add your user to
55+
the `tty` group:
56+
57+
```bash
58+
sudo usermod -a -G tty $USER
59+
```
60+
61+
## Configure the MCU in printer.cfg
62+
63+
Add the following section to your `printer.cfg` to enable your SBC as a secondary MCU:
64+
65+
```ini
66+
[mcu host]
67+
serial: /tmp/klipper_host_mcu
68+
```
69+
70+
After saving, restart Klipper. You can now reference the host MCU pins in your configuration using the `host:` prefix,
71+
for example:
72+
73+
```ini title="Example 1: A led strip controlled by the GPIO20 on the RPi"
74+
[output_pin caselight]
75+
pin: host:gpio20
76+
# You can also write the pin in extended form by specifying
77+
# the reference gpiochip.
78+
#pin: host:gpiochip0/gpio20
79+
```
80+
81+
```ini title="Example 2: Using the i2c bus of the RPi to read a sensor"
82+
[temperature_sensor enclosure_temp]
83+
sensor_type: HTU21D
84+
i2c_mcu: host
85+
i2c_bus: i2c.1
86+
htu21d_hold_master: False
87+
```
88+
89+
## Further Information
90+
91+
For more details and optional features like enabling SPI, I2C, identifying the correct gpiochip, or using hardware
92+
PWM, refer to the official Klipper documentation:
93+
94+
- [RPi Microcontroller](https://www.klipper3d.org/RPi_microcontroller.html){:target="_blank"} — Full guide
95+
- [Optional: Enabling SPI](https://www.klipper3d.org/RPi_microcontroller.html#optional-enabling-spi){:target="_blank"}
96+
- [Optional: Enabling I2C](https://www.klipper3d.org/RPi_microcontroller.html#optional-enabling-i2c){:target="_blank"}
97+
- [Optional: Identify the correct gpiochip](https://www.klipper3d.org/RPi_microcontroller.html#optional-identify-the-correct-gpiochip){:target="_blank"}
98+
- [Optional: Hardware PWM](https://www.klipper3d.org/RPi_microcontroller.html#optional-hardware-pwm){:target="_blank"}

zensical.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ nav = [
137137
{ "FAQ" = [
138138
{ "Change WiFi credentials" = "mainsailos/faq/change-wifi-credentials.md" },
139139
{ "Enable Bluetooth on RPi" = "mainsailos/faq/enable-bluetooth-on-rpi.md" },
140+
{ "Linux RPi MCU" = "mainsailos/faq/linux-rpi-mcu.md" },
140141
]},
141142
]},
142143

0 commit comments

Comments
 (0)