RS485-CAN-HAT

From SB-Components Wiki

Revision as of 06:19, 8 June 2021 by Sbcshop (talk | contribs) (→‎Code Test)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

RS485 CAN HAT

RS485 CAN HAT is a multi node communication module, to communicate with devices in a long-range, designed dedicatedly for Raspberry Pi with an operating voltage of 3.3 V, CAN controller MCP2515 via SPI interface, onboard transceiver SN65HVD230 that is controlled via UART. It is built to support automatic TX/RX control without programming. It performs half-duplex communication and it has an onboard transceiver SP3485.

Features

  • Onboard TVS (Transient Voltage Suppressor),lightning-proof & anti-electrostatic
  • Standard Raspberry Pi 40 Pins GPIO Extension Headers
  • Half-duplex Communication
  • Long-Distance Communication via RS485/CAN functions

Specifications

  • Operating voltage: 3.3V
  • CAN transceiver: SN65HVD230
  • RS485 transceiver: SP3485
  • CAN controller: MCP2515
  • Communication Protocol - RS485 and CAN
RS485 CAN HAT
Buy it From : Click Here

Pinout

Board PINRaspberry Pi GPIO (BCM)DESCRIPTION
3V33V33.3V Power
GNDGNDGround
SCKGPIO 11SPI clock input
MOSIGPIO 10SPI data input
MISOGPIO 9SPI data output
CSGPIO 8SPI chip selection
INTGPIO 25Interrupt
RXDGPIO 15RS485 UART receive
TXDGPIO 14RS485 UART transmit
RSEGPIO 4RS485 TX/RX control Line (Currently in auto mode)

Installation

Python

Library Installation

Before running this board you have install required libraries for RS485 CAN HAT.

  • For Python3, install these two libraries by running below command on the terminal.
sudo apt-get install python-pip
sudo pip3 install python-can


CAN TEST

Required Hardware
  • Raspberry Pi x 2
  • RS485 CAN HAT x 2
Setup
  • Stack RS485 CAN HAT on GPIO header of both Raspberry Pi, and modify the boot/config.txt file.
 sudo nano /boot/config.txt 
  • Add below line to the end of the file.
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000

485-CAN-HAT-config.PNG

  • Save this file on both boards and reboot both raspberry pi one by one.
sudo reboot
  • After restart, run the below command to verify the installation by running the below command (Make sure RS485 CAN HAT is connected while booting).
dmesg | grep -i '\(can\|spi\)'

485-CAN-HAT-install-check.PNG

Code Test
  • Now connect H and L Terminal of the first HAT to H and L terminal of the second HAT.
  • Clone or download Github repository by running below command.
git clone https://github.com/sbcshop/RS485-CAN-HAT.git
  • Now enter cloned repository by running below command one by one.
cd RS485-CAN-HAT
cd CAN
  • Now run code on receiver first.
sudo python3 can_receive.py
  • Now run code on Sender.
sudo python3 can_send.py


You will get some value with timestamp and id on the receiver terminal.

RS485 TEST

Required Hardware
  • Raspberry Pi x 2
  • RS485 CAN HAT x 2
Code Test
  • Stack RS485 CAN HAT on GPIO header of both Raspberry Pi.
  • Now connect A and B Terminal of the first HAT to A and B terminal of the second HAT.
  • Clone or download Github repository by running below command.
git clone https://github.com/sbcshop/RS485-CAN-HAT.git
  • Now enter cloned repository by running below command one by one.
cd RS485-CAN-HAT
cd RS485
  • Now run code on receiver first.
sudo python3 485_receive.py
  • Now run code on Sender.
sudo python3 485_send.py

You can start getting data on the receiver terminal after the above steps.

Resources