07.03.2019 This is a driver-package which connects LinuxCNC with a Raspberry oder Arduino client via direct raw-ethernet. So a LinuxCNC-PC without a parport may be used. It's also possible, to connect an IO-Port over a distance of more than 100 meters form the LinuxCNC-PC. The LinuxCNC-component-driver (ethraw.comp) works together with a Raspberry PI oder an Arduino (no driver changes needed). But there are different limitations depending on the hardware used: Arduino No decoding of "quadratur-signals" in this version Secure values latency: 1ms Max. output frequency: 1kHz Peak values latency: 300usec Max. output frequency: ?? Raspberry Secure values latency: 50usec Max. output frequency: 10kHz Peak values latency: 30usec Max. output frequency: 33kHz Files in this package: halcmd.hal Example HAL-file - init and IO-toggle (use "halrun") etheraw.ino Sourcecode for arduino-Uno ethraw.comp LinuxCNC component-driver pcIOethRaw.c Standalone PC-Arduino/Raspberry I/O-test rasPIioEthRaw.c Raspberry-Driver Sourcecode In directory "/WINDER": type0.hal example HAL-file with step_type=0 type15.hal example HAL-file with quadratur-signal (needs WINDER) In this version, step_type 15 is only usable with a Raspberry-PI What you also need: (If you want to use the test-programs "type0.hal" and "type15.hal") http://gnipsel.com/linuxcnc/examples/winder.zip Copy the files into /WINDER ---------------------------- The original version of WINDER is located here: http://gnipsel.com/linuxcnc/examples.html Many thanks to John Thornton for this Example-Files JT’s LinuxCNC Stuff John Thornton version 1.0, (C) 2012 ---------------------------- commandline to use from inside /WINDER-directory: wget http://gnipsel.com/linuxcnc/examples/winder.zip&&unzip winder.zip Compiling of ethraw.comp: halcompile --compile ethraw.comp Then copy the resulting ethraw.so into the /rtlib directory of linuxcnc! Usage with an Arduino-UNO (need ethernet-shield) In this version 10 Output-Pins and 8 Input-Pins are supported. Compile and load "etheraw.ino" to the arduino-Uno. The MAC-address is free configurable on both sides. Regardeless of the real hardware-address of the netword-card. So I use 06:05:04:03:02:01 as MAC-addr. of the LinuxCNC-PC and on the Arduino/Raspberry side 01:02:03:04:05:06. // the MAC-address of myself static byte myadr[6]={0x06,0x05,0x04,0x03,0x02,0x01}; // the MAC-address of my the linuxCNC-Master static byte radr [6]={0x01,0x02,0x03,0x04,0x05,0x06}; TESTING ======= Connect PC and Arduino with a 1:1-cable (no router, no switch between them!) start "tcpdump" on the PC: sudo tcpdump -i eno1 -s 2000 ether host 01:02:03:04:05:06 or ether host 06:05:04:03:02:01 Every change of an arduino-input-pins between "0" und "1" (put "A0" to GND), causes a tcpdump output like this: .. 09:37:40.969104 06:05:04:03:02:01 (oui Unknown) > 01:02:03:04:05:06 [.....] length 50 0x0000: 0000 003f 0000 0000 00b8 ba21 0000 0000 ...?.......!.... 0x0010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0020: 0000 0000 0000 0000 0000 0000 0d00 0000 ................ 0x0030: 0000 This are the packages, which the Arduino send at every rinig or falling edge at an input-pin. compiling of "pcIOethRaw.c" - A test-programm for signal-output (and input): gcc pcIOethRaw.c -lpthread -o pcIOethRaw The following tests do _NOT_ need a realtime-kernel. It works with vanilla out of stock. On the PC-side sudo ./pcIOethRaw -i eno1 -s 06:05:04:03:02:01 -r 01:02:03:04:05:06 (change interface-name -i if necessarry) The output looks like this ------------------------ test-tool - running on pc-linuxcnc-side 06.3.2019 (c) by Ralf Burger compile with gcc pcIOethRaw.c -o pcIOethRaw -pthread Opening interface [eno1]. send to Mac-address [06:05:04:03:02:01]. recieve for Mac-address [01:02:03:04:05:06]. destination MAC: 06:05:04:03:02:01 rec. for MAC: 01:02:03:04:05:06 interface:eno1 init_rec_socket eno1 sending to MAC: 6:5:4:3:2:1 s_sockfd is: 6 (1< 1 PACKET LOST!!!lastEthInNr: 0 pktInNr: bb ------------------------ This test-tool reads an writes IO-ports of the Arduino. The keys 1-8 toggle the bits 0-7 of an IO-port. With "o", the tool switches into output-mode (no echo) With "1", it toggles pin "0" ot the Arduino - Use a LED to test it. The screen-output looks like this: (a single "PACKET LOST!"-message could be ignored) - The counters are in an ansynch-stat at startup. In pcIOethRaw.c is a usleep(1000); inside the thread. (whithout this, a slow system may stall. While using pcIOethRaw the tcpdump will look like this: 09:49:06.556509 01:02:03:04:05:06 (oui Unknown) > 06:05:04:03:02:01 (oui Unknown), ethertype Unknown (0x0808), length 30: 0x0000: 0849 0005 0000 0000 0005 0500 0000 0000 .I.............. 09:49:06.558866 06:05:04:03:02:01 (oui Unknown) > 01:02:03:04:05:06 .... 0x0000: 0000 003f 0000 0000 00ce ce21 0000 0000 ...?.......!.... 0x0010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0020: 0000 0000 0000 0000 0000 0000 1d00 0000 ................ 0x0030: 0000 .. Now to LinuxCNC =============== use "halrun" to run this commands: halrun -I -f halcmd.hal This commands toggles a LED at pin "0" of the Arduino: setp ethraw.0.pin-00-out false setp ethraw.0.pin-00-out true setp ethraw.0.pin-00-out false with halcmd: show pin or with (in a shell-window) watch "halcmd show pin ethraw.0.pin-0" or with "halshow" The level-changes of the output-pins cound be watched. Thats all about "Arduino" for now. Now to Raspberry: You may use also a vanilla-Kernel for testing. compile rasPIioEthRaw.c with gcc rasPIioEthRaw.c -lbcm2835 -lpthread -o rasPIioEthRaw start it with sudo ./rasPIioEthRaw -i eth0 -r 06:05:04:03:02:01 -s 01:02:03:04:05:06 A first test is also halcmd.hal (see above). Switch output-ports with: setp ethraw.0.pin-00-out false setp ethraw.0.pin-00-out true And use a LED for watching or use watch "gpio readall" The pin-definitions are in GPIO.h de. ethraw.0.pin-00-out is pin 11 at the PI3-conenctor Every 2,0s: gpio readall Wed Mar 6 10:15:58 2019 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | | | 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | | | 4 | 7 | GPIO. 7 | OUT | 0 | 7 || 8 | 0 | IN | TxD | 15 | 14 | | | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 | | 17 | 0 | GPIO. 0 | OUT | 1 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 | | 27 | 2 | GPIO. 2 | OUT | 1 | 13 || 14 | | | 0v | | | | 22 | 3 | GPIO. 3 | OUT | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 | | | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 | | 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | | | 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 1 | IN | GPIO. 6 | 6 | 25 | | 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 | | | | 0v | | | 25 || 26 | 1 | OUT | CE1 | 11 | 7 | | 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 | | 5 | 21 | GPIO.21 | OUT | 0 | 29 || 30 | | | 0v | | | | 6 | 22 | GPIO.22 | OUT | 0 | 31 || 32 | 1 | IN | GPIO.26 | 26 | 12 | | 13 | 23 | GPIO.23 | OUT | 1 | 33 || 34 | | | 0v | | | | 19 | 24 | GPIO.24 | OUT | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 | | 26 | 25 | GPIO.25 | OUT | 1 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 | | | | 0v | | | 39 || 40 | 0 | OUT | GPIO.29 | 29 | 21 | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+ Now drive a motor.... ======================= Inside the /WINDER directory of the LinuxCNC-PC start halrun type0.hal Connect a TA66xx module/chip th the Pins 11 und 13 (of the raspberry-connector) (STEP/DIR). kick "Start". With a velocity of 50, the Motor runs at 250Hz. (dependimng on the peroid-time in "loadrt") This is the "usual" step_type=0 usage. With this commandline, the Raspberry switches to "quad-signals": sudo ./rasPIioEthRaw -i eth0 -r 06:05:04:03:02:01 -s 01:02:03:04:05:06 -q [0][0]=[0/1] The LinuxCNC-Pins 0 und 1 will then generate a STEP/DIR (on Pins 11 and 13 of the raspberry-connector) out of the delivered LinuxCNC-output-signals. With the same hal-parameter, the frequency is now 500Hz. This only works with the ""type15.hal"-file !!! Test results with a "type 15"-stepgen on a _NOT_ realtime kernel and a _NOT_ optimized raspberry: 8kHz with a 100usec-thread. With "Max-Vel.=1000" in "Winder" no lost packets: 11:10:51 - 100k packtes received. 11:11: 3 - 100k packtes received. 11:11:16 - 100k packtes received.