Raspberry Pi · configuration
TF03 with Raspberry Pi CAN / RS485 / Modbus / UART / I/O: integration and configuration guide
Setup, connection, configuration and code guidance for TF03 with Raspberry Pi. The original files are available in Materials and downloads. Documented interface: CAN, RS485 / Modbus, UART, I/O.
Applicable setup
TF03 · Raspberry Pi · CAN, RS485 / Modbus, UART, I/O
Technical instructions and steps
Interfacing TF03-485 Single Point LiDAR with Raspberry Pi HAT
Written by: Ibrahim (FAE)
TF03-485 Interfacing with RasPi HAT Benewake (Beijing) Co. Ltd.This article explains how to interface Benewake TF03-485 single point LiDAR with Raspberry Pi 485-CAN HAT. The HAT is compatible with Raspberry Pi Zero/Zero W/ZeroWH/2B/3B/3B+/4B. The following assumptions are made while writing this article:
1. The end-user has Raspberry Pi single board computer and 485-CAN HAT 1
(manufactured by Waveshare). I have added four different links from where 485-CAN HAT can be purchased 2. Benewake TF03-485 single point LiDAR in hands 3. Raspbian operating system. At the time of writing this article the version 2021-03-04- raspios-buster-armhf2 was tested 4. All the necessary cables and 5V power supply. TF03-485 industrial version supports wide voltage range 5-24V 5. The default interface mode of LiDAR is 485 so we don’t need any prior settings 6. Any editor for writing and modifying the script (VS Code is recommended) 7. UART port is enabled: I. Start raspi-config(in terminal type): sudo raspi-config. II. Select option 3 - Interface Options. III. Select option P6 - Serial Port. IV. At the prompt “Would you like a login shell to be accessible over serial”? answer is 'No' V. At the prompt “Would you like the serial port hardware to be enabled”? answer is 'Yes' VI. Exit raspi-config and don’t reboot at this moment VII. [Configure Raspberry Pi system file]: Open /boot/config.txt (using any text editor can be used like gedit, vim, nano etc.) in terminal and add the following line: : enable_uart=1 For Raspberry Pi 3B comment out: #dtoverlay=pi3-miniuart-bt and reboot the Pi for changes to take effect.
1 https://www.waveshare.com/product/raspberry-pi/rs485-can-hat.htm https://www.ebay.com/itm/263753270299 https://www.cytron.io/p-rs485-can-hat-for-raspberry-pi https://botland.store/raspberry-pi-hat-connection/12532-rs485-can-hat-overlay-for-raspberry-pi-waveshare- 14882-5904422319502.html 2 https://downloads.raspberrypi.org/raspiosarmhf/images/raspiosarmhf-2021-03-25/2021-03-04-raspios- buster-armhf.zip
2|Page
TF03-485 Interfacing with RasPi HAT Benewake (Beijing) Co. Ltd.Pin configuration of 485-CAN HAT:
We are only interested in two pins of HAT which are A and B as only these two pins are needed for 485 communication. The HAT can directly be inserted into 40-pin header of Raspberry Pi. In this tutorial we are not discussing other pins. The following image shows 485 pins marked in red:
Figure 1: Pinouts
Schematic diagram: The connection diagram for interfacing TF03 LiDAR to HAT and using a separate power supply is given below:
Figure 2: Connection Diagram
3|Page
TF03-485 Interfacing with RasPi HAT Benewake (Beijing) Co. Ltd.For exact details about LiDAR current rating and your supply capacity, please refer to their respective data-sheets. It should be noted that if you are using the same power supply for LiDAR and Raspberry Pi + HAT, then your supply should be able to provide enough current to all these devices otherwise some parts may behave abnormally.
Default 485 Communication Parameters of TF03: According to the data-sheet of TF03 LiDAR the parameters of 485 communication:
Figure 3: 485 Communication
So 485 communication in code script is established based on this information. The baud rate and other parameters must match on two sides (HAT and LiDAR) otherwise communication cannot be established.
Cable and Connector Selection: All Benewake Single Points LiDARs have either 4-pin or 7pin (for TF03) Molex connector, so the required mating connector is JST socket 1.25mm. Please refer to the link3. You can choose either 4-pin or 7-pin depending upon the LiDAR that you have. On the HAT side will need male- DuPont connector or any other suitable male connector that can be inserted into HAT:
3 https://www.aliexpress.com/i/4000580232835.html
4|Page
TF03-485 Interfacing with RasPi HAT Benewake (Beijing) Co. Ltd.Figure 4: Male DuPont cable
Table III: Data format (for TF03 Series)
Setting Development Environment: 1. [Installing BCM2835]: in terminal type the following commands step by step:
$ wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz $ tar zxvf bcm2835-1.60.tar.gz $ cd bcm2835-1.60/ $ sudo ./configure $ sudo make && sudo make check && sudo make install
5|Page
TF03-485 Interfacing with RasPi HAT Benewake (Beijing) Co. Ltd.2. [Installing Python libraries]: Type the following commands.
$ sudo pip3 install pillow $ sudo pip3 install numpy $ sudo apt-get install libopenjp2-7 $ sudo apt install libtiff $ sudo apt install libtiff5 $ sudo apt-get install libatlas-base-dev I. [For Python2]: $ sudo apt-get update $ sudo apt-get install python-pip $ sudo pip install RPi.GPIO $ sudo pip install smbus II. [For Python3]: $ sudo apt-get update $ sudo apt-get install python3-pip $ sudo pip3 install RPi.GPIO $ sudo pip3 install smbus
3. [Installing WiringPi Library]:
$ sudo apt-get install wiringpi $ wget https://project-downloads.drogon.net/wiringpi-latest.deb $ sudo dpkg -i wiringpi-latest.deb $ gpio -v Note: The 2.52 version will appear (in my case it appeared). If it does not appear, it means there is an installation error 4. [Installing Serial Library]: $ sudo apt-get install python-serial 5. After all the libraries are installed, restart the Raspberry Pi: sudo reboot 6. [Downloading example code4 and grant permission]:
$ sudo chmod 777 -R Python-code-folder/
If everything is successful and there is no issue with connection, and system settings etc. then you should be able to run the code and see the data being printed to the terminal.
For Python2:
$ sudo python TF03-485.py
4 https://github.com/ibrahimqazi/TF03-485-Python-code-for-485-CAN-HAT
6|Page
TF03-485 Interfacing with RasPi HAT Benewake (Beijing) Co. Ltd.For Python3:
$ sudo python3 TF03-485.py
7|Page
TF03-485 Interfacing with RasPi HAT Benewake (Beijing) Co. Ltd.If the 485 communication is not normal, please debug step by step:
1. Confirm whether it is disabled to log in to the Raspberry Pi shell from serial;
2. Determine the hardware version of the Raspberry Pi. If it is Raspberry Pi ZERO/3B, the serial port in the program needs to be modified to /dev/ttyAMA0; 3. Determine whether A and B of 485 correspond to A and B of 485 device under one-to-one correspondence; 4. You can use the USB to 485 device to communicate with the RS485 CAN HAT first to ensure that there is no problem with the Raspberry Pi setting;
8|Page
Use and verification
The technical content follows the readable source material. Confirm the product hardware revision, flight-stack or software version, and field safety boundary against the original material and current platform documentation.
Materials and downloads
- Interfacing TF03-485 Single Point LiDAR · English source (PDF)Complete inquiry to download
