Using CAN in the BalenaOS
1 Test Environment
1.1 Hardware
ED-CM4SEN
1.2 Software
The deivce has installed BalenaOS, you can find it on balena-cloud, and the device status is online.
2 Steps to Use
2.1 Download Repository
Cloning repository
git clone https://github.com/edatec/balena-ubuntu-cantest.git
2.2 Dashboard
2.2.1 Add dtoverlay
Download ed-mcp2515.dtbo
and copy it to /mnt/boot/overlays/
folder
Download link:dtbo
2.2.2 Setting
Disable SPI
Add dtoverlys:
Content of the setting:
# CM4 SEN
"vc4-kms-v3d","spi6-1cs,cs0_pin=18,cs0_spidev=disabled","ed-mcp2515,spi6-0,oscillator=16000000,interrupt=7"
# CM4 HMI/IPC263x
"vc4-kms-v3d","spi6-2cs,cs0_spidev=disable,cs1_pin=17,cs1_spidev=disable","ed-mcp2515,spi6-0,oscillator=16000000,interrupt=15",”ed-mcp2515,spi6-1,oscillator=16000000,interrupt=14”
2.2.3 Adding release
Log in to balenaCloud,then you can find the 'Release,click' 'Add release'。
2.2.3.1 With balenaCLI
Download the test repository
git clone https://github.com/edatec/balena-ubuntu-cantest.git
Push the repository to release, replace <>
with your username
balena login && balena push <your-username>/test
2.2.3.2 With Git
Download the test repository
git clone https://github.com/edatec/balena-ubuntu-cantest.git
Push the repository to release, replace <>
with your username and your fleet
git remote add balena your-username@git.balena-cloud.com:<your-username>/<your-fleet>.git
git push balena master
2.3 Connect to device
Log in to the appliance and run the following command to check the status of docker:
balena ps -a
My container named test_9634932_3161183_e96bb9d369e78534cde4f510662923e828cfc2e3
,please replace it with the name of your real container:
balena exec -t test_9634932_3161183_e96bb9d369e78534cde4f510662923e828cfc2e3 \
sh -c "apt update"
# Install can-utils
balena exec -t test_9634932_3161183_e96bb9d369e78534cde4f510662923e828cfc2e3 \
sh -c "apt install -y iproute2 can-utils"
# Set the bitrate of can0
balena exec -t test_9634932_3161183_e96bb9d369e78534cde4f510662923e828cfc2e3 \
sh -c "ip link set can0 type can bitrate 500000"
# Enable can0
balena exec -t test_9634932_3161183_e96bb9d369e78534cde4f510662923e828cfc2e3 \
sh -c "ip link set can0 up"
# Send 1122334455667788 by can0
balena exec -t test_9634932_3161183_e96bb9d369e78534cde4f510662923e828cfc2e3 \
sh -c "cansend can0 123#1122334455667788"
# Dump data by can0
balena exec -t test_9634932_3161183_e96bb9d369e78534cde4f510662923e828cfc2e3 \
sh -c "candump can0"