Difference between revisions of "RS485-CAN-HAT"

From SB-Components Wiki

(Created page with "<div class="row"> <div class="large-8 column"> == RS485 CAN HAT == RS485 CAN HAT is a multi node communication module, to communicate with devices in a long-range, designed...")
 
 
(30 intermediate revisions by the same user not shown)
Line 10: Line 10:
 
* Long-Distance Communication via RS485/CAN functions
 
* Long-Distance Communication via RS485/CAN functions
  
</br>
 
 
=== Specifications ===
 
=== Specifications ===
 
* Operating voltage: 3.3V
 
* Operating voltage: 3.3V
Line 34: Line 33:
 
<tr><td>CS</td><td>GPIO 8</td><td>SPI chip selection</td></tr>
 
<tr><td>CS</td><td>GPIO 8</td><td>SPI chip selection</td></tr>
 
<tr><td>INT</td><td>GPIO 25</td><td>Interrupt</td></tr>
 
<tr><td>INT</td><td>GPIO 25</td><td>Interrupt</td></tr>
<tr><td>RXD</td><td>GPIO 14</td><td>RS485 UART receive</td></tr>
+
<tr><td>RXD</td><td>GPIO 15</td><td>RS485 UART receive</td></tr>
<tr><td>TXD</td><td>GPIO 15</td><td>RS485 UART transmit</td></tr>
+
<tr><td>TXD</td><td>GPIO 14</td><td>RS485 UART transmit</td></tr>
<tr><td>RSE</td><td>GPIO 4</td><td>RS485 TX/RX control (auto control by default)</td></tr>
+
<tr><td>RSE</td><td>GPIO 4</td><td>RS485 TX/RX control Line (Currently in auto mode)</td></tr>
  
 
</table>
 
</table>
  
 
== Installation ==
 
== Installation ==
==== Python ====
+
=== Python ===
* Stack PiRelay-V2 HAT on Raspberry Pi 40 Pin GPIO header.
 
* Make sure all four jumpers are connected.
 
* Open Terminal and clone/download the repository by typing below command in terminal:
 
  
<pre> git clone https://github.com/sbcshop/PiRelay-V2 </pre>
+
==== 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.
  
* Your code will be downloaded to '/home/pi' directory. Use 'ls' command to check the list of directories and 'cd' command to enter directory.
+
<source lang="shell">
<pre> cd PiRelay-V2 </pre>
+
sudo apt-get install python-pip
* 'test.py' is example code for PiRelay-V2. Run test file and play with PiRelay-V2 by running below python command.
+
sudo pip3 install python-can
<pre> python3 test.py </pre>
+
</source>
 +
</br>
 +
==== <b> CAN TEST </b> ====
 +
===== Required Hardware =====
 +
* Raspberry Pi x 2
 +
* RS485 CAN HAT x 2
  
* You can also use any other GPIO of Raspberry Pi by removing the jumpers and connecting relay pin directly to the Raspberry Pi GPIO header using jumper cables or wire.
+
===== 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]]
 +
 
 +
* 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]]
 +
 
 +
===== 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> GPIO 4 Relay Not working Fix </b>
+
==== <b> RS485 TEST </b> ====
 +
===== Required Hardware =====
 +
* Raspberry Pi x 2
 +
* RS485 CAN HAT x 2
  
* Click on <b> Start button >> Preferences >> Raspberry Pi Configuration</b>, Then click on Interfaces Tab and make sure 1-Wire is disabled.  
+
===== Code Test =====
* Click on OK button then reboot Raspberry pi.
+
* 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.
 +
<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 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>
  
https://github.com/sbcshop/PiRelay-V2/raw/main/Images/Relay4Fix.PNG
+
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