Difference between revisions of "RS485-CAN-HAT"

From SB-Components Wiki

 
(21 intermediate revisions by the same user not shown)
Line 46: Line 46:
 
* For Python3, install these two libraries by running below command on the terminal.
 
* For Python3, install these two libraries by running below command on the terminal.
  
<pre> sudo apt-get install python-pip </pre>
+
<source lang="shell">
 +
sudo apt-get install python-pip
 +
sudo pip3 install python-can
 +
</source>
 +
</br>
 +
==== <b> CAN TEST </b> ====
 +
===== 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.
 +
<pre> sudo nano /boot/config.txt </pre>
 +
* Add below line to the end of the file.
 +
<source lang="shell">
 +
dtparam=spi=on
 +
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000
 +
</source>
 +
[[File:485-CAN-HAT-config.PNG]]
  
<pre> sudo pip3 install python-can </pre>
+
* Save this file on both boards and reboot both raspberry pi one by one.
 +
<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).
 +
<source lang="shell"> dmesg | grep -i '\(can\|spi\)' </source>
 +
[[File:485-CAN-HAT-install-check.PNG]]
  
==== CAN TEST ====
+
===== 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.
 +
<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.
 +
<source lang="shell">
 +
cd RS485-CAN-HAT
 +
cd CAN 
 +
</source>
 +
* Now run code on receiver first.
 +
<source lang="shell"> sudo python3 can_receive.py </source>
 +
* Now run code on Sender.
 +
<source lang="shell"> sudo python3 can_send.py </source>
 +
</br>
 +
You will get some value with timestamp and id on the receiver terminal.
 +
 
 +
==== <b> RS485 TEST </b> ====
 
===== Required Hardware =====
 
===== Required Hardware =====
 
* Raspberry Pi x 2
 
* Raspberry Pi x 2
 
* RS485 CAN HAT x 2
 
* RS485 CAN HAT x 2
  
===== Setup =====
+
===== Code Test =====
*Stack RS485 CAN HAT on GPIO header of Raspberry Pi, and modify the boot/config.txt file.
+
* Stack RS485 CAN HAT on GPIO header of both Raspberry Pi.
<pre> sudo nano /boot/config.txt </pre>
+
* Now connect A and B Terminal of the first HAT to A and B terminal of the second HAT.
* Add below line to the end of the file, then save it .
+
* Clone or download Github repository by running below command.
<pre>dtparam=spi=on
+
<source lang="shell"> git clone https://github.com/sbcshop/RS485-CAN-HAT.git  </source>
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000</pre>
+
* Now enter cloned repository by running below command one by one.
 +
<source lang="shell">
 +
cd RS485-CAN-HAT
 +
cd RS485
 +
</source> 
 +
* Now run code on receiver first.
 +
<source lang="shell"> sudo python3 485_receive.py </source>
 +
* Now run code on Sender.
 +
<source lang="shell"> sudo python3 485_send.py  </source>
 +
 
 +
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