Difference between revisions of "RS485 CAN HAT"
Line 1: | Line 1: | ||
<div class="wiki-pages jet-green-color"> | <div class="wiki-pages jet-green-color"> | ||
{{Infobox item | {{Infobox item | ||
+ | |name=[[RS485 CAN HAT]] | ||
+ | |name2=[[RS485 CAN HAT (B)]] | ||
+ | |brief=Raspberry Pi small size and low cost RS485 CAN expansion board | ||
+ | |brief2=Raspberry Pi Isolated RS485 CAN Expansion Board | ||
|img=[[File:RS485-CAN-HAT-1.jpg|300px|{{Amazon_nolink|default={{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}|url=link=https://www.waveshare.com/rs485-can-hat.htm}} | RS485 CAN HAT]] | |img=[[File:RS485-CAN-HAT-1.jpg|300px|{{Amazon_nolink|default={{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}|url=link=https://www.waveshare.com/rs485-can-hat.htm}} | RS485 CAN HAT]] | ||
+ | |img2=[[File:RS485 CAN HAT (B).jpg|300px|{{Amazon_nolink|default={{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}|url=link=https://www.waveshare.com/rs485_can_hat_(b).htm}}]] | ||
|caption=RS485 CAN HAT for Raspberry Pi | |caption=RS485 CAN HAT for Raspberry Pi | ||
|brand=Waveshare | |brand=Waveshare |
Revision as of 02:50, 15 October 2022
| ||
| ||
Introduction
The RS485 CAN HAT will enables your Pi to communicate with other devices stably in long-distance via RS485/CAN functions.
More |
Note:
There are two versions. The only difference betweem these version are the crystal. The old one use 8M and the line added to config.txt file should be:
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25,spimaxfrequency=1000000
The new one use 12M crystal and the line should be
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000
Resources
Documents
Demo code
Datasheet
3D Drawing
FAQ
- The current version is 12M, you can view the front of the module:
Then the corresponding command in config.txt is:
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000
- If you have an old version, there should be an 8M crystal oscillator, as shown below:
Then the corresponding command in config.txt is:
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25,spimaxfrequency=1000000
Open the Raspberry Pi terminal and enter the following command to access the configuration screen:
sudo raspi-config Select Interfacing Options -> Serial to turn off shell access and turn on the hardware serial port
Raspberry Pi 2B/zero, the user serial device number is ttyAMA0; you can use the following command line to confirm that serial0 is the selected serial device number, as follows:
ls -l /dev/serial*
- For Raspberry Pi 3B/2B/Zero, the serial port is typically used for Bluetooth. When you comment out this setting, it defaults to S0. However, Raspberry Pi 4 does not have this statement by default.
#dtoverlay=pi3-miniuart-bt
And then reboot the Raspberry Pi:
sudo reboot
{{{5}}}
- Make sure the baud rates on both sides are the same;
- The fixed frame ID is set in the demo: 0X123, please set the sending and receiving CAN ID of the other end of your CAN to be x0123;
- Determine the hardware version of the Raspberry Pi, if it is the Raspberry Pi ZERO/3B, the serial port in the program needs to be modified to /dev/ttyAMA0;
- Check whether the serial communication of the Raspberry Pi has enabled flow control;
- Determine whether A and B of 485 correspond to the controlled 485 devices A and B one by one;
- You can use the USB to 485 devices to communicate with the RS485 CAN HAT first to ensure that there is no problem with the settings of the Raspberry Pi;
- Check the setting of odd and even bit parity of serial communication parameters.
- Mainstream Ubuntu system config.txt files are usually in the /boot/firmware folder
- Or use the SD card of the Raspberry Pi to read and change the config.txt file under the computer (or other hosts that can recognize the SD card) through the card reader.
The sensor may send hex data (sometimes it is necessary to send hex data to the sensor to request data), follow the steps below to send and receive hex data:
wget https://files.waveshare.com/upload/0/00/RS485-CAN-HAT-For-Hex.zip unzip RS485-CAN-HAT-For-Hex.zip sudo chmod 777 RS485-CAN-HAT-For-Hex.zip cd RS485-CAN-HAT-For-Hex #Receive Hex sudo python3 RS485-CAN-HAT-send-hex.py #Send Hex sudo python3 RS485-CAN-HAT-receive-hex\.py
If it means that the output part of data processing becomes slower, it should help to improve the performance of the upper computer; you can also consider clearing the cache before each read to read only the latest data for processing.
{{{5}}}
Can be used without connecting to the GND, connected to the GND signal may be more stable, connected to GND to obtain better performance, reliability, and anti-interference ability, and long-distance communication. Hence, it is recommended to connect the GND.
{{{5}}}
After entering "myenv", you can install the corresponding Python library again. In the "myenv" environment, all commands are executed without "sudo".
sudo apt install python3-venv python3 -m venv myenv &&source myenv/bin/activate source myenv/bin/activate pip install requests
{{{5}}}
- The CAN rate of the host and the slave should be the same.
- Both ends of the 120 ohm balancing resistors are turned on.
- The frame ID of the transmitter should correspond to the filter ID of the receiver.
{{{5}}}
Support
If you require technical support, please go to the Support page and open a ticket.