Example Code for Raspberry pi(I2C)-High Precision Positioning
Last revision 2026/01/29
The article guides readers through setting up Raspberry Pi for high precision positioning using I2C, detailing hardware and software preparations, wiring diagrams, and code execution for GNSS RTK integration.
Hardware preparation
- Raspberry Pi 4B
- DFR0566 Raspberry Pi 4B/3B+ IO Expansion Board
- RTK High-Precision Positioning Kit-4G
Software Preparation
- Raspberry Pi Imager
- [DFRobot_RTK_4G](- DFRobot_RTK_4G)
- CORS Account (Choose an appropriate platform as needed)
I2C Tutorial
Wiring Diagram
| Raspberry pi | PIN | GNSS-RTK | PIN |
|---|---|---|---|
| Raspberry pi | + | GNSS-RTK | VCC(RED) |
| Raspberry pi | - | GNSS-RTK | GND(BLACK) |
| Raspberry pi | C | GNSS-RTK | SCL(BLUE) |
| Raspberry pi | D | GNSS-RTK | SDA(GREEN) |
Before use, confirm the I2C rate is 400k. Configure as follows:
command1: sudo vi /boot/firmware/config.txt Modify configuration file

If dtparam=i2c_arm=on already exists, just add ,i2c_arm_baudrate=400000 to the same line.
command2: sudo reboot Reboot Raspberry Pi after saving changes to take effect
Download the library file and run it. The default is I2C mode
Move the hardware mode switch to the I2C mode. Note: When toggling the DIP switch, the device is powered on. Please power cycle the device after switching for the change to take effect.

-
Create directory and get library file
command1:cd ~
command2:cd Desktop
command3:mkdir df -
Create folder
command4:cd df -
Switch to folder
command5:git clone https://github.com/DFRobot/DFRobot_RTK_4G.git -
Get library file
command6:cd DFRobot_RTK_4G/python/raspberrypi/examples -
Switch to example file
command7:sudo python3 get_gnss.py
Was this article helpful?
