SensorConfig stores the serial connection parameters used by the library:
from xkc_kl200_python import SensorConfig, XKC_KL200
config = SensorConfig(
port="/dev/ttyUSB0",
baudrate=9600,
timeout=1.0,
address=0xFFFF,
startup_delay_s=0.1,
)
sensor = XKC_KL200(config=config)The protocol exposes the following baud rates:
2400480096001440019200384005600057600115200128000
change_baud_rate accepts either a baud-rate code (0 to 9) or one of the actual baud-rate values listed above.
address=0xFFFFis the default broadcast-style device address used by the original sensor examples.change_addressonly accepts values from0x0000to0xFFFE.
This setup uses the XKC-KL200 Laser Distance Measurement Sensor. The manufacturer states that this product supports multiple output modes, including UART serial output, and links a separate UART manual for the UART-capable version.
The Raspberry Pi configuration described here uses:
UART1,UART2,UART3, andUART5SPI0for theMCP2515CAN controller- no
UART4
Raspberry Pi documents the uart2, uart3, and uart5 overlays on supported boards in its configuration documentation.
The MCP2515 CAN controller is connected over SPI0. In this Raspberry Pi wiring setup, SPI0 occupies the same pin block needed for UART4, so both are not used together. The active UART selection is therefore:
UART1UART2UART3UART5
For the UART-capable XKC-KL200 family, the wiring used in this setup is:
Brown=VCCBlue=GNDYellow= sensor signal outputBlack= sensorRXD
In practice for Raspberry Pi wiring, this becomes:
Brown->5VBlue->GNDYellow-> Raspberry PiRXBlack-> Raspberry PiTX
The XKC product page lists an operating voltage of DC 5-24V. In this setup:
- sensor power =
5V - sensor ground =
GND - Raspberry Pi UART logic remains
3.3V
The active /boot/firmware/config.txt block is:
[all]
dtoverlay=disable-bt
enable_uart=1
dtoverlay=uart2
dtoverlay=uart3
dtoverlay=uart5Meaning of each line:
enable_uart=1enables serial and UART supportdtoverlay=uart2enablesUART2dtoverlay=uart3enablesUART3dtoverlay=uart5enablesUART5
The active UART mapping is:
UART1->GPIO14 / GPIO15UART2->GPIO0 / GPIO1UART3->GPIO4 / GPIO5UART5->GPIO12 / GPIO13
Some extension HATs do not label these pins as TXD2, RXD2, TXD3, and so on. Instead, they expose the original GPIO labels:
UART1:TXD=TXD1,RXD=RXD1UART2:ID_SD=GPIO0=TXD2,ID_SC=GPIO1=RXD2UART3:IO4=GPIO4=TXD3,IO5=GPIO5=RXD3UART5:IO12=GPIO12=TXD5,IO13=GPIO13=RXD5
Sensor 1 on UART1:
Brown->5VBlue->GNDYellow->RXDBlack->TXD
Sensor 2 on UART2:
Brown->5VBlue->GNDYellow->ID_SCBlack->ID_SD
Sensor 3 on UART3:
Brown->5VBlue->GNDYellow->IO5Black->IO4
Sensor 4 on UART5:
Brown->5VBlue->GNDYellow->IO13Black->IO12
For every sensor:
Brown->5VBlue->GNDYellow-> PiRXBlack-> PiTX
All sensors can share the same power rails:
- all
Brownwires ->5V - all
Bluewires ->GND
The UART signal wires must remain separate for each sensor.
In a four-sensor Raspberry Pi deployment, each sensor can be opened on its own UART device:
- Sensor 1 ->
/dev/ttyAMA0 - Sensor 2 ->
/dev/ttyAMA2 - Sensor 3 ->
/dev/ttyAMA3 - Sensor 4 ->
/dev/ttyAMA5
The sensor sends serial data to the Raspberry Pi over the yellow wire, and the Raspberry Pi sends commands back over the black wire.