Difference between revisions of "RS485-CAN-HAT"

From SB-Components Wiki

 
(3 intermediate revisions by the same user not shown)
Line 60: Line 60:
 
<pre> sudo nano /boot/config.txt </pre>
 
<pre> sudo nano /boot/config.txt </pre>
 
* Add below line to the end of the file.
 
* Add below line to the end of the file.
<pre>dtparam=spi=on
+
<source lang="shell">
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000</pre>
+
dtparam=spi=on
 +
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000
 +
</source>
 
[[File:485-CAN-HAT-config.PNG]]
 
[[File:485-CAN-HAT-config.PNG]]
  
 
* Save this file on both boards and reboot both raspberry pi one by one.
 
* Save this file on both boards and reboot both raspberry pi one by one.
<pre> sudo reboot </pre>
+
<source lang="shell"> sudo reboot </source>
 
*After restart, run the below command to verify the installation by running the below command (Make sure RS485 CAN HAT is connected while booting).
 
*After restart, run the below command to verify the installation by running the below command (Make sure RS485 CAN HAT is connected while booting).
<pre> dmesg | grep -i '\(can\|spi\)' </pre>
+
<source lang="shell"> dmesg | grep -i '\(can\|spi\)' </source>
 
[[File:485-CAN-HAT-install-check.PNG]]
 
[[File:485-CAN-HAT-install-check.PNG]]
  
Line 73: Line 75:
 
* Now connect H and L Terminal of the first HAT to H and L terminal of the second HAT.
 
* 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.
 
* Clone or download Github repository by running below command.
<pre> git clone https://github.com/sbcshop/RS485-CAN-HAT.git </pre>
+
<source lang="shell"> git clone https://github.com/sbcshop/RS485-CAN-HAT.git </source>
 
* Now enter cloned repository by running below command one by one.
 
* Now enter cloned repository by running below command one by one.
<pre>
+
<source lang="shell">
 
cd RS485-CAN-HAT
 
cd RS485-CAN-HAT
 
cd CAN   
 
cd CAN   
</pre>
+
</source>
 
* Now run code on receiver first.  
 
* Now run code on receiver first.  
<pre> sudo python3 can_receive.py </pre>
+
<source lang="shell"> sudo python3 can_receive.py </source>
 
* Now run code on Sender.  
 
* Now run code on Sender.  
<pre> sudo python3 can_send.py </pre>
+
<source lang="shell"> sudo python3 can_send.py </source>
 
</br>
 
</br>
You will get some value with timestamp and id on receiver terminal.
+
You will get some value with timestamp and id on the receiver terminal.
  
 
==== <b> RS485 TEST </b> ====
 
==== <b> RS485 TEST </b> ====
Line 95: Line 97:
 
* Now connect A and B Terminal of the first HAT to A and B terminal of the second HAT.
 
* 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.
 
* Clone or download Github repository by running below command.
<pre> git clone https://github.com/sbcshop/RS485-CAN-HAT.git  </pre>
+
<source lang="shell"> git clone https://github.com/sbcshop/RS485-CAN-HAT.git  </source>
 
* Now enter cloned repository by running below command one by one.
 
* Now enter cloned repository by running below command one by one.
<pre>
+
<source lang="shell">
 
cd RS485-CAN-HAT
 
cd RS485-CAN-HAT
 
cd RS485
 
cd RS485
</pre>   
+
</source>   
 
* Now run code on receiver first.
 
* Now run code on receiver first.
  <pre> sudo python3 485_receive.py </pre>
+
  <source lang="shell"> sudo python3 485_receive.py </source>
 
* Now run code on Sender.
 
* Now run code on Sender.
  <pre> sudo python3 485_send.py  </pre>
+
  <source lang="shell"> sudo python3 485_send.py  </source>
  
You can start getting data on receiver terminal after above steps.
+
You can start getting data on the receiver terminal after the above steps.
  
 
== Resources ==
 
== Resources ==

Latest revision as of 06:19, 8 June 2021

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