Getting started with Machinekit on the CHIP

5 minutes read

This blog post is about getting started with Machinekit on the Nexthing CHIP.

With a price of 9$; the CHIP is the cheapest single board computer with wifi and flash memory on the market. The low price and easy availability make the CHIP an ideal platform for low-budget motion-control applications.

This blog post focuses on the user perspective of using Machinekit on the CHIP. If you are also interested in how the CHIP GPIO driver works please take a look the earlier blog post.

Why using Machinekit?

Machinekit is a machine control software platform. It is available across a wide range of hardware platforms and real-time environments and delivers excellent performance at low cost.

One key feature of Machinekit is the HAL component architecture, an easy to use circuit model that includes over 150 building blocks for digital logic, motion, control loops, signal processing, and hardware drivers.

Machinekit makes it easy to build real-time Linux applications. Choosing real-time Linux as platform for your project you can use the full spectrum of open source software and at the same time build hard real-time motion control applications.

Machinekit supports local and networked UI options, including mobile platforms like phones or tablets.

Machinekit is open source and has an active and inspiring community which is eager to help newcomers.

Summarized, if you want to use your CHIP to interface with the real world, you should consider using Machinekit.

Setup the CHIP for Machinekit

In this tutorial, I assume you are using the CHIP in a headless setup. Headless means the CHIP is connected to your computer via a (USB) serial terminal or SSH. For more details, please take a look at the CHIP documentation.

First of all, you need to flash the 4.4 Debian image on your CHIP using the Online Flasher. I used the Headless 4.4 image.

If your CHIP is already connected to the internet, you can skip ahead to the installation section.

Connect to WiFi

First of all, you need to connect to your CHIP to the web. To achieve this you have to connect the CHIP to a WiFi network.

First, list the available networks.

nmcli device wifi list

You should see a list of available networks.

*  SSID      MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
*  NextThing HQ    Infra  11    54 Mbit/s  100     ????  --
   NextThing Shop  Infra  6     54 Mbit/s  30      ?___  WPA1 WPA2
   2WIRE533        Infra  10    54 Mbit/s  44      ??__  WPA1 WPA2

Next, connect a network. Without password:

sudo nmcli device wifi connect '(your wifi network name/SSID)' ifname wlan0

Or with password:

sudo nmcli device wifi connect '(your wifi network name/SSID)' password '(your wifi password)' ifname wlan0

For more info about the CHIP and WiFi please take a look at the docs.

Once connected you are ready to install Machinekit.

Install Machinekit packages and RT-PREEMPT kernel

Installing Machinekit on the CHIP is as easy as executing the following line:

curl -sSL http://bit.ly/2cyf0At | sudo -E bash -

Behind this link, you can find an install script located on GitHub in this repository.

This script will download and install Machinekit and an RT-PREEMPT kernel for the CHIP 4.4 images. If you run the script on the PocketCHIP it will install the POSIX-thread flavor of Machinekit.

Caution: During the installation, the script will download a few hundred megabytes of data.

Furthermore, the installation will take some time and automatically reboot your CHIP.

Testing Machinekit

Now it is time to download and run the first Machinekit configuration.

First, install git:

sudo apt install git

Then, clone the hal_hello_chip configuration and execute the run.py:

cd
mkdir repos
cd repos
git clone https://github.com/machinekoder/hal_hello_chip
cd hal_hello_chip
./run.py &

Now you should have a running Machinekit instance. To verify your setup is working run:

halcmd show pin

You should see something similar to this:

Component Pins:
  Comp   Inst Type  Dir         Value  Name                                             Epsilon         Flags
    73        bit   OUT         FALSE  chip_gpio.in-04                                                  0
    73        bit   IN          FALSE  chip_gpio.in-04.invert                                           0
    73        bit   OUT         FALSE  chip_gpio.in-05                                                  0
    73        bit   IN          FALSE  chip_gpio.in-05.invert                                           0
    73        bit   OUT         FALSE  chip_gpio.in-06                                                  0
    73        bit   IN          FALSE  chip_gpio.in-06.invert                                           0
    73        bit   OUT         FALSE  chip_gpio.in-07                                                  0
    73        bit   IN          FALSE  chip_gpio.in-07.invert                                           0
    73        bit   IN          FALSE  chip_gpio.out-00                                                 0 <== square
    73        bit   IN          FALSE  chip_gpio.out-00.invert                                          0
    73        bit   IN          FALSE  chip_gpio.out-01                                                 0
    73        bit   IN          FALSE  chip_gpio.out-01.invert                                          0
    73        bit   IN          FALSE  chip_gpio.out-02                                                 0
    73        bit   IN          FALSE  chip_gpio.out-02.invert                                          0
    73        bit   IN          FALSE  chip_gpio.out-03                                                 0
    73        bit   IN          FALSE  chip_gpio.out-03.invert                                          0
    73        s32   OUT          3625  chip_gpio.read.time                                              0
    73        s32   OUT          3875  chip_gpio.write.time                                             0
   102        float IN              1  siggen.0.amplitude                               0.000010        0
   102        bit   OUT         FALSE  siggen.0.clock                                                   0 ==> square
   102        float OUT    -0.9921147  siggen.0.cosine                                  0.000010        0
   102        float IN             10  siggen.0.frequency                               0.000010        0
   102        float IN              0  siggen.0.offset                                  0.000010        0
   102        float OUT         -0.04  siggen.0.sawtooth                                0.000010        0
   102        float OUT     0.1253332  siggen.0.sine                                    0.000010        0
   102        float OUT             1  siggen.0.square                                  0.000010        0
   102        float OUT         -0.88  siggen.0.triangle                                0.000010        0
   102        s32   OUT          7958  siggen.0.update.time                                             0

Congratulations, the installation is complete! Now you are ready to use Machinekit

CHIP GPIO

A core part of Machinekit platform support is a HAL GPIO driver. I have presented a HAL GPIO driver in an earlier blog post.

chip_pinouts

The hal_chip_gpio component controls the CSIDn pins rather than the XIO-Pn pins for performance reasons.

You can use the driver in a HAL configuration using the following command:

rt.loadrt('hal_chip_gpio', output_pins='0,1,2,3', input_pins='4,5,6,7')

The output_pins parameter determines which pins to use as output. The input_pins determines which pins to use as input.

You can connect these pins for example to software PWM or stepper generators. I also tested the software encoder component with the CHIP.

During my first tests with the CHIP, I observed that the performance is good enough to for most basic motion control applications.

Setup USB OTG networking

I found it useful to have a non-wireless connection with the CHIP. If you want to use USB networking on your CHIP, you can use the following commands.

sudo editor /etc/network/interfaces.d/usb0

And insert

auto usb0
iface usb0 inet static
address 192.168.7.1
netmask 255.255.255.0

Start the network by running:

sudo ifup usb0

On your host computer, you have to manually configure the network adapter to use the static IPv4 address 192.168.7.2 and netmask 255.255.255.0.

How to continue

Now it is time for you to explore Machinekit. The best place to start with learning Machinekit is the Machinekit documentation.

Just type the topic you are interested in into the search bar.

Note: a lot of the documentation is still using the old style .hal files and syntax. However, I recommend you using the newer Python API.

I know that the learning curve for Machinekit might seem very steep in the first place. But you will soon see that learning to use Machinekit pays off.

Please stay tuned for more beginner blog posts on this blog. I will dedicate some future blog posts on practical examples using Machinekit and the CHIP.

Summary

In this blog post, you learned how to install Machinekit on the CHIP.

Furthermore, the article explains how to configure different types of networking on the CHIP. Moreover, the post introduces an short example HAL configuration and the CHIP GPIO HAL component.

I hope you found this article useful, and I'm looking forward to your feedback.

Your
Machine Koder

Spread the love

Comments 15

  1. Hi
    This is a very nice article and I can flash the headless debian and install Machinekit on my CHIP.
    I am a beginner and I really did not find any info on how to connect my chip remotely and see the gcode running GUI

    Regards
    Nuri

    1. Post
      Author

      Hi Nuri,

      Thank you. I'm glad to hear that you got Machinekit running on the CHIP.

      I'm currently working on making QtQuickVcp, the remote UI for Machinekit, easier to use. I will write some articles on how to use and create remote UIs for Machinekit.

      Best Regards,
      Alex R

  2. Brilliant! Thanks so much for taking the time to take the machinekit support for CHIP to the next level, I really enjoyed how clear and accurate your instructions are. I saw your original post about compiling MK for CHIP and was hoping you'd follow up on that, and to provide such a simple process for installing/running it is perfect.

    I look forward to your next article!

    1. Post
      Author
    1. Post
      Author

      Hi Marco,

      Yes, you can control a mill machine with LinuxCNC via a parallel port. However, LinuxCNC does only support desktop computers at the moment.

      Machinekit does also support ARM-based platforms, and you can find BeaghleBone Black capes for parallel port support here: Machinekit Blog If you are asking if the CHIP will work for this scenario then I have to say no.

      I would suggest you taking a look at the Xylotex parallel port cape or the TheCoolTool SandyBox if you are looking for a turnkey solution.

      --
      Machine Koder

  3. Thanks, looking forward to firing mine up with a simple project.

    Out of curiosity, why does the PocketCHIP get POSIX flavor instead of PREEMPT-RT?

    1. Post
      Author
      1. After trying this on my CHIP with 4.4.13-ntc, it seems it does not install the RT-PREEMPT kernel due to version mismatch with the expected 4.4.11-ntc.

        Is there an easy fix to roll it back to 4.4.11-ntc from the 4.4.13-ntc it installed from the chip flasher?

        I tried forcing it through but I landed on a kernel panic. Thanks.

        1. Nevermind, I found your other instructions on cross compiling the kernel. I'll run through that and see if I can get it going that way. Thanks!

          1. Post
            Author
  4. Hi Alex!

    PLEASE make a flashable image for chip.
    Is it really neccesarry to compile all these stuff to use my cnc?
    With the x86 linuxcnc you can boot from CD and done, no compiling / terminal crawling needed.

    It's too complicated for an end user. 🙁

    1. Post
      Author

      The CHIP is not suitable for a CNC. This blog post is targeted for developers and Linux power users. If you are interested in Machinekit for CNC either use the ready to use BeagleBone Black images or install via the package manager on a Debian installation.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.