sudo apt update
sudo apt install picocom -y
By default, the Raspberry Pi 3 Model B (and Zero 2 W) assigns ttyS0 to GPIO14:15 while ttyAMA0 serves the Bluetooth module. As the mini UART is not a full featured UART, you may want to use ttyAMA0 on GPIO14:15 instead as it is a full featured UART. Fortunately, there are a couple of device tree overlays that will accomplish this.
pi3-miniuart-bt
: This overlay flip flops the UARTs by assigning ttyAMA0 to GPIO14:15 while assigning ttyS0 to the Bluetooth module.pi3-disable-bt
: This overlay assigns ttyAMA0 to GPIO14:15 while disabling Bluetooth altogether.
In general, the Mini-UART has one big pitfall. It doesn't have its own clock source, so the UART bitrate depends on the CPU clock. Which means you have to set a fixed CPU clock for reliable communication.
This guide will use pi3-disable-bt
to ensure compatibility with Marlin uart.
# FILE /boot/config.txt
dtoverlay=pi3-disable-bt
# ...
[all]
enable_uart=1
Reboot the PI to apply configuration.
sudo reboot now
Once rebooted, check the configuration. /dev/ttyAMA0 should now be assigned to /dev/ttyS0.
pi@raspberry:~ $ ls -l /dev | grep ttyAMA0 && ls -l /dev | grep ttyS0
lrwxrwxrwx 1 root root 7 Jul 10 14:35 serial0 -> ttyAMA0
crw-rw---- 1 root dialout 204, 64 Jul 10 14:35 ttyAMA0
lrwxrwxrwx 1 root root 5 Jul 10 14:35 serial1 -> ttyS0
crw-rw---- 1 root dialout 4, 64 Jul 10 14:35 ttyS0
Grant permissions to ports for pi
user.
sudo usermod -a -G dialout pi
sudo usermod -a -G tty pi
Test permissions and marlin connection
picocom /dev/ttyAMA0 -b 115200 --imap lfcrlf --echo
Send command M115
to marlin to test the connection.
Some 3D printing host applications require a ttyUSBXX port ID. To alias the serial port, you need to add a udev
rule. Here we will alias ttyAMA[X]
to ttyUSB[X]
. Note, this could interfere with USB devices. In our case we are not using any so there is no issue.
Find the block for ttyAMA0, and in the SYMLINK
section, add ttyUSB%c
inside the quotes, with a space after serial%c
.
sudo nano /etc/udev/rules.d/99-com.rules
# FILE: /etc/udev/rules.d/99-com.rules
KERNEL=="ttyAMA0", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
if cmp -s $$ALIASES/uart0 $$ALIASES/serial0; then \
echo 0;\
elif cmp -s $$ALIASES/uart0 $$ALIASES/serial1; then \
echo 1; \
else \
exit 1; \
fi\
'", SYMLINK+="serial%c ttyUSB%c"
# Add new symlink here ^
You can reload the udev rules with following command to test. However, your application will probably require a reboot to pick up the new port.
sudo udevadm control --reload-rules && sudo udevadm trigger