-
-
Notifications
You must be signed in to change notification settings - Fork 2
UART Connection
USB is the most common way of communication between our Raspberry Pi and the Mainboard of the 3D Printer but there is another possibility. It is possible to connect the Mainboard of the 3D Printer with the Raspberry directly via UART using a couple of wires. This will allow us to integrate the Raspberry inside the printer and have the connection cable running inside the printer instead of using the external USB Connection.
- 3 Wires to connect the Mainboard to the Raspberry GPIO pins
- Connectors
To allow the Raspberry Pi to communicate with the Mainboard we need to enable the UART communication. To do so connect in ssh with your Pi and digit the following command:
sudo raspi-config
You should see now a configuration interface like the following one in which you have to select Interfacing Options
After you have to select the Serial
option
Now you will be asked for the login shell to be accessible over Serial, select No shown as follows
And as last question press yes when asked to enable the Serial port
Reboot the Pi to apply the changes.
To put it simply The Raspberry Pi have two UART Protocols built-in: PL011 UART
and mini UART
.
We want to use the first one with our serial connection because it has better performance so we need to check that this protocol is assigned to the GPIO pins instead of being used for Bluetooth as per default.
If we run the following command
ls -l /dev
And we look for serial0
and serial1
we should find something like this:
In this case, serial0
is representing our GPIO UART connection and serial1
is our Bluetooth serial connection.
ttyS0
is the mini UART
protocol and ttyAMA0
is the PL011 UART
protocol.
As we can notice from the image above our serial0
is mapped to ttyS0
so we need to change this setting too.
To swap the UART ports, open file config.txt as shown below:
sudo nano /boot/config.txt
After this add one of the following settings in the configuration file if you are using a Raspberry Pi 3:
dtoverlay = pi3-miniuart-bt
or
dtoverlay = pi3-disable-bt
or if you are using a Raspberry Pi 4 the following one
enable_uart=1
dtoverlay=disable-bt
Save with Ctrl+O
and reboot your Pi.
After the reboot, run again the following command to check the mapping of our UART Protocols:
ls -l /dev
If you see an output like the following one it means that you successfully assigned the right protocol to the GPIO Pins UART connection:
Note: Is also possible that you find the UART Protocol correctly configured from the beginning. If you find that the output of the
ls -l /dev
is like the one shown above you are already good to go.
More details about the Raspberry Pi 3 UART protocol can be found here
This step is straightforward as we just need to update our printer.cfg configuration file with the following settings for the mcu
[mcu]
# Previously was serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
serial: /dev/ttyAMA0
restart_method: command
For this step, we need 3 wires to connect the Raspberry with the Motherboard of the printer. In general, is recommended to have the shorter possible cables but, in case you need to place the Raspberry far away from the printer, is possible to use shield cables. This is because a long cable is more prone to suffer from interference that can cause errors of communication between the Raspberry and the Printer.
I strongly recommend to use some good quality USB cable, cut it and replace the USB connectors with some female Dupont ones.
These are the parts that we need:
Now let's start with the preparation of the connection for the Raspberry side.
This is the pinout of a Raspberry Pi
We need to use pins 6, 8 and 10 so in this case since the pins are aligned I suggest preparing a Dupont connector with at least 3 slots like the following one:
I also suggest using black wire as the ground one so it will be easier to understand how to plug the connector to the Raspberry Pi later on.
Now is time to connect the Raspberry to the Printer Motherboard and for this step you need to locate the TX and RX pins inside your motherboard.
We need to connect the TX of the Raspberry Pi with the RX of the Motherboard and the RX of the Raspberry Pi with the TX of the Motherboard. We will also need to connect the ground pin of the Raspberry Pi with the ground pin of the Motherboard.
For our Creality Ender 3 S1 stock motherboard the pins that we need are located inside the display connector so in this case we just need the pinout of this cable instead of the pinout of the entire motherboard.
Prepare your cable cutting it to be as short as possible and as Dupont connector, I suggest using the single pin ones.
Route your cable to the motherboard as shown:
And connect the pins to the motherboard display connector as shown:
Done!
We have one last step, update the printer motherboard firmware to be able to communicate via serial communication instead of USB.
To prepare the firmware correctly use update the configuration using the make menuconfig
command and change the following settings:
- Select "Enable extra low-level configuration options"
- Serial (on USART2 PA3/PA2)
Now we just need to build the firmware, flash it and enjoy your printer!