kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Machinekit Raspbian Jessie for RPi1 and RPi2

Sat Mar 05, 2016 2:02 pm

Here are the preliminary steps to create an updated Machinekit installation based on Raspbian Jessie for RPi v1 and v2:
  • Download and install MINIBIAN
    The default un/pw is root/raspberry
  • Install raspi-config

    Code: Select all

    apt-get update
    apt-get install -y raspi-config raspberrypi-bootloader
    
  • Configure RPi

    Code: Select all

    raspi-config
    • Expand Filesystem
    • Overclock
    • reboot to apply changes
  • Add Machinekit repo:

    Code: Select all

    apt-key adv --keyserver hkp://keys.gnupg.net --recv-key 43DDF224
    echo "deb http://deb.machinekit.io/debian raspbian main" > /etc/apt/sources.list.d/machinekit.list
    apt-get update
    
  • Install RT-PREEMPT kernel
    • RPi1

      Code: Select all

      apt-get install -y linux-image-rpi-rt
    • RPi2

      Code: Select all

      apt-get install -y linux-image-rpi2-rt
  • Update /boot/config.txt to use the new kernel
    • RPi1

      Code: Select all

      cd /boot
      echo kernel=$(ls kernel_rt*.img) >> config.txt
      echo device_tree=dtbs_rt/bcm2708-rpi-b-plus.dtb >> config.txt
      Use the corect dtb file for your board.
    • RPi2

      Code: Select all

      cd /boot
      echo kernel=$(ls kernel_rt*.img) >> config.txt
      echo device_tree=dtbs_rt/bcm2709-rpi-2-b.dtb >> config.txt
    Sample /boot/config.txt for RPi2

    Code: Select all

    [email protected]:~# cat /boot/config.txt
    gpu_mem=16
    arm_freq=1000
    core_freq=500
    sdram_freq=500
    over_voltage=2
    kernel=kernel-4.4.3-rt9-v7+.img
    device_tree= dtbs_rt/bcm2709-rpi-2-b.dtb
  • Add the following parameters to /boot/cmdline.txt

    Code: Select all

    dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0
    Sample /boot/cmdline.txt

    Code: Select all

    [email protected]:~# cat /boot/cmdline.txt
    dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 elevator=deadline root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes rootwait
  • Install Machinekit

    Code: Select all

    apt-get install -y machinekit-dev machinekit-rt-preempt
  • Install PICnc-v2 driver

    Code: Select all

    cd ~/
    wget https://github.com/kinsamanka/PICnc-V2/raw/master/HAL/picnc.{c,h}
    comp --compile picnc.c
    sudo cp picnc.so /usr/lib/linuxcnc/rt-preempt
    
  • Install your favorite DE

    Code: Select all

    apt-get install lxde
    Replace lxde with whatever suits your fancy ;-)
  • Add Machinekit user

    Code: Select all

    adduser mk
  • Reboot

    Code: Select all

    reboot
Note:
MINIBIAN was chosen to keep the installation size small. Standard raspbian image can also be used, just omit the DE installation step.

The rt-preempt kernels are still considered beta, tests are needed to see if this is suitable for Machinekit.

updates: Added RPi2 kernel
Last edited by kinsa on Fri Mar 18, 2016 12:22 pm, edited 2 times in total.
42

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sat Mar 05, 2016 2:07 pm

VikTan wrote:Hi,

I found an article about experimental hardware accelerated OpenGL driver for Raspberry Pi.
http://hexus.net/tech/news/graphics/904 ... l-support/

I want to ask, now I using image RPi2-machinekit-1.0 and there is low performance of LinuxCNC GUI on RasPi2. It is caused by software accelerated OpenGL or it is completely different problem? Big ngc files also makes GUI performance slower. Trajectory generation works without any problem.

Thanks,
Viktor
The axis UI is a resource hog. This is inherent to the design of the interface. You can try the mini UI and you'll see the difference.

With regards to big ngc files, the preview window actually loads the whole ngc file to generate the previews. Turn off the preview and the performance will improve.
42

mung
Posts: 506
Joined: Fri Nov 18, 2011 10:49 am

Re: LinuxCNC

Sun Mar 06, 2016 1:28 am

Very cool that a new version of linuxcnc/machinekit is available, I think the xenomai kernel maybe more responsive when using axis gui, is there an ETA for when a xenomai version maybe available?

Also will 64bit be available for real time kernels?

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sun Mar 06, 2016 5:15 am

Unless someone ports xenomai to run on the latest kernels, there will be none ;)

64 bit is too new. If someone has an developed an RT kernel for it I'll be glad to host it.

Cheers
42

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Mon Mar 07, 2016 3:05 pm

Updated instructions for RPi2.

Cheers
42

VikTan
Posts: 11
Joined: Wed Nov 11, 2015 2:36 pm
Location: Bratislava

Re: LinuxCNC

Mon Mar 14, 2016 2:26 pm

What about run RPi2-machinekit-1.0.img run on RPi3? I tried it but it didn't boot. It's a problem of 64bit architecture?

dega
Posts: 8
Joined: Wed Mar 07, 2012 4:44 pm

Re: LinuxCNC

Fri Mar 18, 2016 9:08 am

Kinsa,
there is a discrepancy on your steps: the /boot/config.txt should be

Code: Select all

cd /boot
echo kernel=$(ls kernel_rt*.img) >> config.txt
echo device_tree=dtbs_rt/bcm2709-rpi-2-b.dtb >> config.txt
instead of "echo dtoverlay=..."
in fact in the sample just below is correct; I tried the dtoverlay but the RPI would hang at boot

I am planning to use a RpiV2 with 3 x DQ542MA stepper drivers to control a cnc milling machine.
Do you have any suggestion on where to look for instructions on to use the GPIOs to control the motors directly? I just need the pulses there instead of a SPI communication with a Pic.

Thanks

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Fri Mar 18, 2016 10:32 am

Are you using the latest bootloader?

I have not used the gpio directly. Maybe you can ask jam1 for his hal file as he was able to control steppers using gpio only.
42

dega
Posts: 8
Joined: Wed Mar 07, 2012 4:44 pm

Re: LinuxCNC

Fri Mar 18, 2016 12:12 pm

kinsa wrote:Are you using the latest bootloader?

I have not used the gpio directly. Maybe you can ask jam1 for his hal file as he was able to control steppers using gpio only.
I think so,
I downloaded the image 2016-03-12-jessie-minibian and then followed your instructions.

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Fri Mar 18, 2016 12:27 pm

Fixed the instructions, thanks!

Here's the example hal for driving the gpios: https://github.com/machinekit/machineki ... o_demo.hal
42

dega
Posts: 8
Joined: Wed Mar 07, 2012 4:44 pm

Re: LinuxCNC

Fri Mar 18, 2016 12:42 pm

kinsa wrote:Fixed the instructions, thanks!

Here's the example hal for driving the gpios: https://github.com/machinekit/machineki ... o_demo.hal
Thanks, I'll have a go.
If it works I'll post a guide on how to use GPIO as well, my milling machine is a MF70/CNC ready

bfree
Posts: 11
Joined: Fri Feb 06, 2015 9:13 pm

Re: LinuxCNC

Thu Mar 24, 2016 6:13 pm

Hello, All,
Perhaps, I am missing something but, so far, this new machinekit install is not usable fo me on a model B+ pi.
I installed using both cases, standard raspian and the minibian. The latter was more responsive, as expected, but still quite dreadful. Digging around the net I found this discussion that may account for the high CPU load: http://community.emlid.com/t/rt-kernel- ... cpu/1002/8 . Whatever the irq/33-dwc_otg stuff is, it is hungry for cycles (times 3); here is output from top:

Code: Select all

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                
 2563 pi        20   0  127144  72940  46532 R 32.1 14.8   0:46.45 axis                   
 2536 root      20   0   62680  59928  11952 S 22.2 12.1   0:35.76 rtapi:0                
   71 root     -51   0       0      0      0 S 13.2  0.0  12:21.89 irq/33-dwc_otg         
   73 root     -51   0       0      0      0 S 10.4  0.0  10:44.37 irq/33-dwc_otg_        
 2562 pi        20   0   24192  15152  12860 S  7.1  3.1   0:11.67 milltask               
   72 root     -51   0       0      0      0 S  5.5  0.0   5:56.48 irq/33-dwc_otg_        
 2590 root      20   0    5016   2564   2136 R  4.1  0.5   0:03.52 top 
I know axis is a hog but in the interest of comparing with the previous kernel, this is what was used and worked just fine on the same B+ unit.
Maybe, I am just missing something?
Have fun!
Bob

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Thu Mar 24, 2016 11:17 pm

Thanks for the feedback.

Looks like rt-preempt is not useable for older boards unless you slow down the usb speed by setting dwg_otg.speed=1.

I'll try to find an updated xenomai kernel and will post it soon.

Cheers.
42

bfree
Posts: 11
Joined: Fri Feb 06, 2015 9:13 pm

Re: LinuxCNC

Sat Mar 26, 2016 8:16 pm

Thank you for the tip. The dwg_otg.speed=1 setting improves things considerably, though still slower than previous.

Am having trouble getting machinekit operational with the rt-preempt image. The PICnc LED rate increases on loading the CNC program, as usual, but have not observed any motion and am getting following errors.
Does this image assume updated firmware in the PICnc?

Also, looking at machinekit status I see MAX_ACCELERATION numbers that are like 10^100; this, regardless of the values I have in the .ini file. Any thoughts on where these might be getting corrupted?

As always, thanks for the project, the good work and assistance.
Regards,
Bob

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Sun Mar 27, 2016 12:15 am

I think the first gen RPi will only be useful with the xenomai kernel.

Unfortunately machinekit hasn't been ported to the latest xenomai version, 3.0, so we'll be stuck with the old kernel.

I'll try to update the xenomai kernel to include all the drivers but I don't have an old RPi at the moment so it will take a bit of time, maybe early next month.

Cheers
42

bfree
Posts: 11
Joined: Fri Feb 06, 2015 9:13 pm

Re: LinuxCNC

Mon Mar 28, 2016 2:23 pm

kinsa,
Has been a while since I compiled a kernel but I have been giving it a try - just for the re-education. In doing this I found the .config used for my current kernel does, indeed, have USB wireless enabled ad several devices (including one device I have) are compiled as modules. I proceeded to add apt sources for the firmware and driver (rt2800usb); now, the wireless is working!
Bottom line is that my wi-fi driver issue is resolved and there is no need to distract you from your other endeavours to create a new kernel/image on my behalf. But, I sure do appreciate the offer and support, anyway.
Thanks again,
Bob

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Mon Mar 28, 2016 2:54 pm

There's a known working 4.1 xenomai kernel for RPi 1. I just need to test it first before packaging ;-)
42

dega
Posts: 8
Joined: Wed Mar 07, 2012 4:44 pm

Re: LinuxCNC

Mon Mar 28, 2016 3:26 pm

Here is the hal_gpio driver to use directly the IO pins of the Raspberry Pi (V2 or V3 preferably),
to add it just follow the same procedure from Kinsa in viewtopic.php?p=920778#p920778 and instead of the PICnc-v2 driver just complie the 2 files in attach:

Code: Select all

comp --compile hal_gpio.c
cp hal_gpio.so /usr/lib/linuxcnc/rt-preempt
The file hal_gpio,c is based on https://github.com/machinekit/machineki ... hal_gpio.c but then I added the get_rpi_revision procedure and some other stuff from the BCM2835 library to control the pull up/down restistors as well.
For my application I load the module with:

Code: Select all

loadrt hal_gpio dir=15729632 pullUp=33652740
to get the pins in this configuration:
Pin 03, GPIO 02 set as Input, Pull OFF
Pin 05, GPIO 03 set as Input, Pull OFF
Pin 07, GPIO 04 set as Input, Pull Up
Pin 29, GPIO 05 set as Input, Pull OFF
Pin 31, GPIO 06 set as Input, Pull OFF
Pin 26, GPIO 07 set as Output
Pin 24, GPIO 08 set as Output
Pin 21, GPIO 09 set as Output
Pin 19, GPIO 10 set as Output
Pin 23, GPIO 11 set as Output
Pin 32, GPIO 12 set as Input, Pull OFF
Pin 33, GPIO 13 set as Input, Pull OFF
Pin 08, GPIO 14 set as Input, Pull OFF
Pin 10, GPIO 15 set as Input, Pull OFF
Pin 36, GPIO 16 set as Input, Pull OFF
Pin 11, GPIO 17 set as Input, Pull Up
Pin 12, GPIO 18 set as Input, Pull Up
Pin 35, GPIO 19 set as Input, Pull OFF
Pin 38, GPIO 20 set as Input, Pull OFF
Pin 40, GPIO 21 set as Input, Pull OFF
Pin 15, GPIO 22 set as Output
Pin 16, GPIO 23 set as Output
Pin 18, GPIO 24 set as Output
Pin 22, GPIO 25 set as Output
Pin 37, GPIO 26 set as Input, Pull OFF
Pin 13, GPIO 27 set as Input, Pull Up
Attachments
gpio.rar
hal_GPIO driver with pull Up/Down support
(15.12 KiB) Downloaded 506 times

dega
Posts: 8
Joined: Wed Mar 07, 2012 4:44 pm

Re: LinuxCNC

Tue Mar 29, 2016 10:26 pm

Now all the configuration files
MF70.rar
Configuration files
(4.54 KiB) Downloaded 422 times
if someone else is trying to do the same.
The driver board has just a BC 547 and a 5k6 resistor from the GPIO to the tranistor's base.

This is a short video of my setup: https://www.dropbox.com/s/y1u98e5fofup3qj/MF70.avi?dl=0

enesterov
Posts: 4
Joined: Mon Apr 18, 2016 2:50 pm

Re: LinuxCNC

Mon Apr 18, 2016 3:19 pm

Hello Everyone,

There is really great information in this thread! Thanks for all your efforts.

I've followed kinsa's and dega's instructions to get RPI 2 to run machinekit and I am almost there - the only things that is missing is that I would like to run my drivers in the "active low" mode. I've followed the the recommendations of the linuxcnc manual on how to invert sygnal

Code: Select all

setp hal_gpio.pin-22-out-invert 1
but machinekit won't start as it says that hal_gpio.pin-22-out-invert can not be found. I am using dega's driver from and would appreciate someone telling me what am I doing wrong.

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Tue Apr 19, 2016 1:06 am

You can use the not component to invert a hal signal.

See here: http://linuxcnc.org/docs/2.5/html/hal/b ... .html#_not
42

dinkata
Posts: 1
Joined: Mon Apr 18, 2016 4:01 pm

Re: LinuxCNC

Tue Apr 19, 2016 3:46 am

I installed it on Raspberry pi2 minibian and machinekit
viewtopic.php?f=37&t=33809&p=941129&hil ... nc#p941129
after that I installed gmoccapy_lcd7
http://machinekit-gmoccapy-lcd7.blogspo ... to-la.html
I am trying run configs ,gmooccapy opens ,but error mesage :
.......
Found an error!
The following information may be useful in troubleshooting:

Traceback (most recent call last):
File "/usr/bin/gmoccapy", line 4153, in <module>
app = gmoccapy()
File "/usr/bin/gmoccapy", line 241, in __init__
self._init_audio()
File "/usr/bin/gmoccapy", line 1038, in _init_audio
self.audio = player.Player()
File "/usr/lib/python2.7/dist-packages/gmoccapy/player.py", line 36, in __init__
self.player = gst.element_factory_make("playbin", "player")
ElementNotFoundError: playbin

.........
please help !
what it takes to work gmoccapy ?
GUI Axis work !

jagspaul
Posts: 5
Joined: Mon Dec 03, 2012 6:46 am

Re: LinuxCNC

Tue Apr 26, 2016 1:13 pm

I have gone through the code of PICnc-V2 and tried to understand the logic of Step Pulse generator, but for me it is too difficult to understood.

Can anybody explain the logic of Step Pulse generator?
However I have some question as follows.

1) Why value of Step size (STEP_MASK) is too high i.e. (1L<<22) [2^22 = 4194304]
2) If STEP_MASK is set some low value (1L<<8) then what will happened .
3) position=stepgen_input.velocity
velocity value is received from LinuxCNC through SPI. What is the minimum & maximum value of velocity.
4) if velocity value too high then position will overflow within few cycle. How it will effect the Step Pulse generator?
5) How frequent LinuxCNC change velocity value & send through SPI.
6) How frequent LinuxCNC change stepwidth value & send through SPI.
7) How step pulse get stooped?

thanks & regards

/jags

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: LinuxCNC

Wed Apr 27, 2016 1:33 am

PICnc is a hardware implementation of the hal software stepgen component.

You can read the description here: http://linuxcnc.org/docs/html/hal/rtcomps.html#_stepgen

We're using the Step Type 0 mode.

Regards
42

enesterov
Posts: 4
Joined: Mon Apr 18, 2016 2:50 pm

Re: LinuxCNC

Wed Apr 27, 2016 4:42 pm

kinsa wrote:You can use the not component to invert a hal signal.

See here: http://linuxcnc.org/docs/2.5/html/hal/b ... .html#_not
Thanks kinsa, it looks like it worked. Still cranking through configuration but motors started to spin!

Return to “Automation, sensing and robotics”