Notes from installation of ethercat on Raspberry Pi 4

More
27 Mar 2021 13:56 - 06 Apr 2021 06:14 #203806 by Hakan
I just put my notes here from the install of ethercat on the Raspberry Pi 4 B, 4 MB,
if anyone is interested to install ethercat on the Rpi4.
It starts from an empty SD card and will turn the Rpi4 into an ethercat master on eth0
and makes ethercat available in linuxcnc including a basic test.
I have tested to follow the notes a few times and it *should* work without further modifications.
There are no choices to make or questions to answer, more than the occasional "Y" for Yes, continue.


Prepare SD-card, here is how to do it on another linux computer with sd-card reader
Download www.linuxcnc.org/iso/linuxcnc-2.8.1-pi4.zip
Unzip to 2021-01-20-linuxcnc-pi4.img
# Write to SD-card, check at the end of ”sudo dmesg” for the name, mine was called /dev/sdj
sudo dd if=2021-01-20-linuxcnc-pi4.img of=/dev/sdj bs=1M

# Mount the sd-disk, mine was called /dev/sdj
# Add /boot/ssh and fill in /boot/wpa_supplicant.conf for wireless access
sudo bash
mount/dev/sdj1 /mnt/a; cd /mnt/a
touch ssh

cat > wpa_supplicant.conf <<_EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=SE
network={
ssid="WLAN"
psk="password"
}
_EOF

# You need to modify country, ssid and psk in the wpa_supplicant.conf for your situation.
cd; umount /mnt/a

# Take the sd-card to the Rpi4 and boot it

Upgrade linux
# Log in on the Rpi4
# Check for a SMP PREEMPT RT kernel, and upgrade to the latest of everything
uname -a
sudo apt update
sudo apt upgrade
sudo reboot

# The system is now ready to run linuxcnc
# Or go ahead and install ethercat support.
# There are two packages needed for ethercat in linuxcnc: etherlabmaster and linuxcnc-ethercat
# Both need to be downloaded, compiled and installed

Prepare for ethercat build
# Need linux kernel header files. Look for the kernel version, here it is xxx-4.19.71-xxx
uname -a
apt-cache search 4.19.71
sudo apt install linux-headers-4.19.71-rt24-v7l

# Install development tools that are needed
sudo apt install mercurial build-essential automake tree dkms bison flex

Etherlabmaster
git clone github.com/icshwi/etherlabmaster
cd etherlabmaster
make init
echo "ENABLE_CYCLES = NO" > configure/CONFIG_OPTIONS.local
make build
make install
echo "ETHERCAT_MASTER0=eth0" > ethercatmaster.local
make dkms_add
make dkms_build
make dkms_install
make setup

# It is a pain to have the include files and libraries installed in /opt/etherlab/ , make an ugly fix (until
# someone comes up with a better method)
sudo mkdir -p /usr/include/linuxcnc
sudo ln -s /opt/etherlab/include/*.h /usr/include/linuxcnc/
sudo ln -s /opt/etherlab/lib/lib* /usr/lib/
# There WILL be build errors later on if this (or something smarter) is omitted

# Reboot
sudo reboot

# Log in again, ethercat should now be running on eth0
pi@linuxcnc:~ $ ethercat master
Master0
Phase: Idle
Active: no
Slaves: 3
Ethernet devices:
Main: dc:a6:32:05:7e:65 (attached)
Link: UP
Tx frames: 3990
Tx bytes: 239560
Rx frames: 3989
Rx bytes: 239500
Tx errors: 0
Tx frame rate [1/s]: 48 51 41
Tx rate [KByte/s]: 2.8 3.0 2.4
Rx frame rate [1/s]: 48 51 41
Rx rate [KByte/s]: 2.8 3.0 2.4
Common:
Tx frames: 3990
Tx bytes: 239560
Rx frames: 3989
Rx bytes: 239500
Lost frames: 0
Tx frame rate [1/s]: 48 51 41
Tx rate [KByte/s]: 2.8 3.0 2.4
Rx frame rate [1/s]: 48 51 41
Rx rate [KByte/s]: 2.8 3.0 2.4
Loss rate [1/s]: 0 0 0
Frame loss [%]: 0.0 0.0 0.0
Distributed clocks:
Reference clock: Slave 0
DC reference time: 0
Application time: 0
2000-01-01 00:00:00.000000000
pi@linuxcnc:~ $ ethercat slave
0 0:0 PREOP + EK1100 EtherCAT-Koppler (2A E-Bus)
1 0:1 PREOP + EL1008 8K. Dig. Eingang 24V, 3ms
2 0:2 PREOP + EL2008 8K. Dig. Ausgang 24V, 0.5A

linuxcnc-ethercat
# Install the development version of linuxcnc
sudo apt install linuxcnc-uspace-dev

# Download, build and install linuxcnc-ethercat
git clone github.com/sittner/linuxcnc-ethercat
cd linuxcnc-ethercat
make configure
make
sudo make install

Test ethercat with linuxcnc
# Skip the VNC steps if you are in front of the display
sudo raspi-config
3 Interface options → Enable VNC server
Exit raspi-config
# Use VNC Control to connect to the display www.realvnc.com/en/connect/download/viewer/windows/

# Open a terminal window, start linuxcnc
linuxcnc
Select sim→axis→axis, copy the files. Axis should start. Exit axis.
cd linuxcnc/configs/sim.axis

# Choose any of the ini files. In your ini file add in the [HAL] section
HALFILE = ethercat.hal

# Make an ethercat.hal file
loadusr -W lcec_conf ethercat-conf.xml
loadrt lcec
addf lcec.read-all servo-thread
addf lcec.write-all servo-thread


# Add a minimal ethercat-conf.xml
<masters>
<master idx="0" appTimePeriod="1000000" refClockSyncCycles="5">
</master>
</masters>

# Start linuxcnc
linuxcnc inifile.ini

# Check that you have plenty of lcec entries, check with for example (in another terminal window)
halcmd show all | grep lcec

# A small real ethercat-conf.xml is
<masters>
<master idx="0" appTimePeriod="1000000" refClockSyncCycles="5">
<slave idx="0" type="EK1100"/>
<slave idx="1" type="EL1008"/>
<slave idx="2" type="EL2008"/>
</master>
</masters>

# With linuxcnc started, a digital output on the EL2008 can be manipulated using standard
# hal syntax like
halcmd setp lcec.0.2.dout-7 1
# will switch on the output 8. The physical hardware is needed for this, of course.

# Now ethercat works in linuxcnc. Add your own devices...


Edit: This works also for building on Debian on an Intel computer - with a few modifications when building etherlabmaster. There are choices for network interface hardware and the ETHERCAT_MASTER0 needs another name. Best to check etherlabmaster/README.md for details.
Last edit: 06 Apr 2021 06:14 by Hakan. Reason: Built ethercat on intel.
The following user(s) said Thank You: arvidb, tommylight, wazza77, Grotius, thang, 3radfahrer, tiagounderground, Shrek, embedded_guy, Rabin and 1 other people also said thanks.

Please Log in or Create an account to join the conversation.

More
28 Mar 2021 10:59 #203879 by Grotius
Hi Hakan,

Nice tutorial. Thanks !

Please Log in or Create an account to join the conversation.

More
30 Mar 2021 09:22 - 30 Mar 2021 09:22 #204113 by thang
I didnt know you already wrote this :laugh: , so the command make modules_prepare isn't needed, i will link to this tutorial from my post
Last edit: 30 Mar 2021 09:22 by thang.

Please Log in or Create an account to join the conversation.

More
30 Mar 2021 11:46 #204116 by papagno-source
Hi. If want install ethercat on actual master , the prodedure is the same ?

Please Log in or Create an account to join the conversation.

More
31 Mar 2021 19:04 #204265 by Hakan
Yes, except that when installing linuxcnc-uspace-dev you have to download the sources, compile and do all the right things to install linuxcnc. Make sure the ". ../linuxcnc-dev/scripts/rip-environment" is run. I tested this as well and this should work, maybe some adjustment along the way. I abandoned that way when I saw that it wasn't necessary to build linuxcnc from sources.
I guess the answer is "No" then.

Please Log in or Create an account to join the conversation.

More
24 Apr 2021 06:32 #206936 by Hakan
I now have a basic lathe setup with stepper motors using the ECT60 stepper drivers.
I attach the needed config files for running this minimal config. The axis works, that's all it does.

I use the cia402 component from github.com/dbraun1981/hal-cia402.

I don't use pid control on the axis. I tried using pid control and it works but it didn't add anything as far as I saw so I removed it.

File Attachment:

File Name: lathe.ini
File Size:2 KB

File Attachment:

File Name: lathe2-nopid.hal
File Size:3 KB

File Attachment:

File Name: ethercat-conf.xml
File Size:3 KB
Attachments:
The following user(s) said Thank You: andypugh, arvidb, eduard, Rabin

Please Log in or Create an account to join the conversation.

More
14 Jun 2021 19:18 #212048 by Hakan
Here is a video I made using the info in this thread.




I think I have accomplished a circular reference between this thread and the video now
The following user(s) said Thank You: arvidb, Rabin, Wesleyooms

Please Log in or Create an account to join the conversation.

More
10 Oct 2021 16:38 #222770 by tuzki
Hi. I am a novice and I want to ask you a question.
You said that you did not use PID algorithm, why use PID algorithm in the driver? Shouldn't this PID algorithm be implemented in LinuxCNC?

Please Log in or Create an account to join the conversation.

More
21 Jul 2022 13:37 #247939 by wgn21
In the "make build step" I got the following error:

configure: error: Failed to find Linux sources. Use --with-linux-dir!
make[1]: *** [etherlabmaster.Makefile:31: autoconf] Error 1
make[1]: Leaving directory '/home/laserplasma/Desktop/etherlabmaster/etherlabmaster-code'
make: *** [/home/laserplasma/Desktop/etherlabmaster/configure/E3/RULES_ETHERLAB:73: autoconf] Error 2

Can someone please give some insights on how to solve it? I thought it's to do with the header installation but I think I already did that step using sudo apt install linux-headers-4.19.0-19-all

Please help. Thank you

Please Log in or Create an account to join the conversation.

More
21 Jul 2022 19:31 #247982 by andypugh
Is that the right linux-headers? It does not seem to be for an RT kernel.

Is that an exact match for the output of uname -a ?

Please Log in or Create an account to join the conversation.

Time to create page: 0.238 seconds
Powered by Kunena Forum