Template: WSSP08A Pi Guides
From Waveshare Wiki
We use 2-CH RS485 HAT(should purchase separately) and Raspberry Pi for testing. For more information about how to use the 2-CH RS485 HAT, you can refer to 2-CH RS485 HAT
Hardware connection
Hesman Connector | |
1 | V+(12V~36V) |
2 | A(Change 2) |
3 | V-(GND) |
4() | B(Change 2) |
PIN | Raspberry Pi(BCM) | Description |
VCC | 5V | 3.3V/5V |
GND | GND | GND |
SCLK | P21(SPI1 SCLK) | SPI clock input |
MOSI | P20(SPI1 MOSI) | SPI Data input |
MISO | P19(SPI1 MISO) | SPI Data Output |
CS | P18(SPI1 CS) | SPI chip selection |
IRQ | P24 | Inttrupt pin |
EN1 | P27 | Channel 1(Channel 1) enable pin: High: Send enable; Low: Receive enable |
EN2 | P22 | Channel 2(Channel 2) enable pin: High: Send enable; Low: Receive enable |
Install Driver
- Open a terminal and run the commands:
sudo nano /boot/config.txt #Add the following lines to file. Note that the ini_pin should be same as the actual define. dtoverlay=sc16is752-spi1,int_pin=24 #Reboot sudo reboot
After reboot, The SC16IS752 drive is installed in kernel, you can check the device by command ls /dev:
If the kernel version is 5.4 or obove, the gpiochip3 is recognized as gpiochip2
Install Libraries
- Install wiringPi
sudo apt-get install wiringpi cd /tmp wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v # Check if it is 2.52 version
- Install python2 libraries
sudo apt-get update sudo apt-get install python-pip sudo pip install RPi.GPIO sudo apt-get install python-serial sudo apt-get install python-crcmod
- Install python3 libraries
sudo apt-get update sudo apt-get install python3-pip sudo pip3 install RPi.GPIO sudo apt-get install python3-serial sudo apt-get install python3-crcmod
Testing
- Download and run the demo codes
sudo apt-get install p7zip-full sudo wget https://www.waveshare.com/w/upload/1/1a/WSSP08A_Code.7z sudo 7z x WSSP08A_Code.7z sudo chmod 777 -R WSSP08A_Code cd WSSP08A_Code/
- C example
cd c make clean make sudo ./main
- python example
#python2 cd python cd examples sudo python main.py #python3 cd python cd examples sudo python3 main.py
About the Codes
- The demo codes are made for a situation that only one sensor is connected, it will read data according to the device address and it can be used to modify the device address.
- C codes
#Read the device address (only one device is connected to RS485 bus) uint8_t WSSP08A_get_addr(void) #Modify the address of target device uint8_t WSSP08A_set_addr(uint8_t o_addr, uint8_t n_addr) #Read the data from target device float WSSP08A_get_pressure(uint8_t addr)
- python codes
#Get 16CRC result def crc16Add(self,read): #Read the device address (only one device is connected to RS485 bus) def get_addr(self): #Read the data from target device def get_press(self,addr): #Modify the address of target device def set_addr(self,o_addr,s_addr):