Installing Universal G-Code Sender on the Raspberry Pi

Anyone will tell you that a CNC machine generates dust. Computers and dust don’t mix that well, so that started me on a quest to find a Raspberry Pi solution. For my 3D printer I use Repetier to drive the device. I was looking for another alternative.

I found an open source project Universal G-code Sender. This Java based solution looked like it would be ideal. So, it started me on a 3-4-day quest to get it to work. I think I’ve accomplished my goal, though I still have a few minor bugs to work out. I do want to thank the author of the code for pointing me to more detailed information that helped me overcome some of the issues I encountered.

There were some instructions available on how to install UGS on a Pi. They didn’t quite align to my needs though, so I thought I’d document the steps I took.

One if my requirements is that I wanted to ‘see’ the desktop remotely, rather than have a dedicated screen. This allows me to minimize the footprint in my work area and provide the greatest flexibility. I decided on VNC as the solution of choice, since it runs on just about any platform. The following is an updated version of the process as of Feb-28-2021.

  1. Install the OS
    1. Download latest version of Raspian image and place it on an SD card. I did  use the full image. I used the rpi-imager, since it formatted…
    2. Install into pi and boot follow the prompts (this should define the keyboard and the time  zone…) — this will take a while since there is a software update check at the end.
    3. Once it boots, run the program that checks the quality of the SD card: Accessories > Raspberry Pi Diagnostics
  2. Run sudo raspi-config
    1. Update to latest version by selecting Update
    2. Update the video drivers so it can use OpenGL effectively
      • Advanced Options -> GL Driver -> GL (fake KMS) this allows for OpenGL to work and your screen size to be large on VNC
      • Advanced optons -> Expand the file system using advanced options
    3. Reboot
  3. Install java
    1. Make sure that java is installed with java -version
    2. If it is not there or not the most current jdk (you’ll need to do this if you don’t use the full Raspian image).

sudo apt-get update
sudo apt-get install openjdk-8-jdk

This will take a while

  1. If you are going to run headless, check to ensure that remote desktop (VNC) is working properly (you probably want to have the Raspberry Pi have a fixed IP address)
    1. If it is not installed use the command
      • sudo apt-get install realvnc-vnc-server
    2. On the raspberry pi configuration GUI select Menu > Preferences > Raspberry Pi Configuration > Interfaces.
      • Ensure VNC is Enabled.
      • You may want to enable SSH as well here
    3. Install an entropy generator:
       

sudo apt-get install haveged

  1. Define the connection to VNC from your PC or other devices (use ifconfig on the Pi to validate your IP address)
  1. Set the framesize on the Pi
  2. If you need to check the ports being listened to: netstat -tupln
  3. Check to make sure it works from another PC and reboot.
  4. Then try it again without the monitor connected (to ensure that headless works).
  5. Your resolution will likely be something other than what you want, to change it: sudo raspi-config
  6. Select display options and define the one you want. I went for 1920 x 1080
  1. Install the CAM software
    1. Using your browser on the raspberry pi, click on: https://github.com/winder/Universal-G-Code-Sender#downloads
    2. Select the version of the software you would like to download and download it:
  1. Uncompress the software (note that when you download it, it is a ,tar,gz file). You should be able to open up the file manager and open it.
  1. Move the unzipped folder to where you’d like it, but I am assuming it is at the top level of the pi directory
  1. Make a shell script to run the program and get around a bug that prevents the path simulation display from working (this may not be necessary on the latest Raspberry pi). In my case I created a shell script file called ugsstart.sh on the desktop

#!/bin/sh
sudo mv /opt/vc /opt/vc.old
/home/pi/ugsplatform-pi/bin/ugsplatform &
sleep 75
sudo mv /opt/vc.old /opt/vc
echo “File reset”

Note that if the folder does not get reset, VNC will not work until it is renamed back to the original name. You might need to play with the sleep number, but 75 seconds was long enough for even my oldest raspberry pi. You may want to start with the lowest number that allows the simulator to start up. Before you say anything else — YES, this is a real kludge.
 

  1. Open the properties for your file and set it to execute:
     
  1. Run the UGS software by double clicking on the script file in the file manager. You’ll need to tell it that you want to Execute, rather than execute in a window. 
    1. Set up the serial port to be the JSSC software in the Tools -> Options ->USG -> Sender Options menu so that the serial connection is more reliable. (see the picture below — this now seems to be the default so may not be necessary)
    2. Plug in the CNC
    3. Refresh the ports in the software
    4. Select the port for the CNC
    5. Make sure the CNC jogs properly
Options 
General Editor Fonts & Colors Keymap Appearance Miscellaneous LIGS 
Auto Leveler Macros Visualizer Sender Options Controller Options 
C] Show verbose output 
@ use separate step sizes for Z and XY jog movements. 
D Enable single step mode 
@ Enable status polling 
Status poll rate (ms) 
D Show warning popup for Nightly Builds 
Auto start pendant on startup 
Language 
English 
Connection driver 
ssc 
Workspace directory
  1. If you want to free up some space on a full install
    1. sudo apt-get autoremove
    1. sudo apt-get update
    2. sudo apt-get dist-upgrade

Here is a picture of UGS running on a Pi over VNC (shown on my Windows machine).

39 thoughts on “Installing Universal G-Code Sender on the Raspberry Pi

  1. I had to one other thing to make my installation run consistently. Since I had to move the VC file to get UGS to run effectively, I needed to move it back if something bad happens and my system crashes.

    I added a boot time cron job to check to see if the .old directory exists. If it does, move everything back to where it belongs and reboot. The shell script looks like:
    #!/bin/sh
    # check to see if the machine went down without restoring the VNC file
    if [ -d /opt/vc.old ]
    then
    echo “reset file”
    # looks like we need to replace the file and reboot
    sudo mv /opt/vc.old /opt/vc
    sudo reboot
    exit 0
    else
    echo “file was ok”
    fi

    to add the cron job:
    1) create the file
    2) set it to be an executable
    3) run sudo crontab -e to open the editor for the system cron script
    4) add in the line @reboot TheFullLocationOfYourScript

    that should do it.

    Liked by 1 person

  2. Thx much for figuring all this out. I am planning to use a touch screen case combo and send over my gcode via Mozilla. Using VNC is definitely nice but my shop’s WiFi is sketchy so l would like the option to use either a VNC connected PC or the touch screen. Do you foresee any issues with both?

    Like

    • I don’t see much of an issue. I have been running VNC on my phone, an android tablet and a couple different PCs with the UGS dedicated Pi and have had no issues. I believe there will be even fewer issues with your touch screen setup since there are significantly fewer ‘moving parts’. Good luck

      Liked by 1 person

  3. Thank you for your post. I ran UGS on my laptop and liked it, but hadn’t gotten it to work on the RPI because of the visualizer. I implemented your suggestion to move the /opt/vc directory and it works great. One thing I did, though, was to move vc.old back right after starting UGS.

    I have a file named in the /home/pi/Desktop/ugs.desktop that contains the following code:

    [Desktop Entry]
    Name=Universal Gcode Sender
    Exec=/home/pi/ugsplatform/bin/my_ugsplatform
    Type=Application
    Icon=/home/pi/ugsplatform/bin/ugsplatform.exe
    Terminal=false
    Categories=None;
    StartupNotify=true
    Path=/home/pi

    The /home/pi/ugsplatform/bin/my_ugsplatform file contains the following code:

    #!/bin/sh
    sudo mv /opt/vc /opt/vc.old
    /home/pi/ugsplatform/bin/ugsplatform &
    sleep 45
    sudo mv /opt/vc.old /opt/vc
    echo “Finished”

    The “sleep 45” statement lets UGS start before moving the vc directory back. I have this running on a raspberry pi 4 with 2g ram.

    Like

  4. Can you please make a youtube video? I am a beginner and don’t quite understand it. i have an rp4. and tried a lot already. but so far it has not been successful to get ugs on the pi.

    Like

  5. Hi there. Like most people here, I want a gcode solution without an actual computer gathering dust. It is awesome that you figured out how to use the raspberry. Could you be more specific on the version (rpi4? 2gb ram?) and the performance issue and limitations you encountered? I will buy a rpi for that specific purpose and would like to get good performance without overkilling it. Thanks!

    Like

    • Mine is a Pi 2 (it has an Ethernet USB adapter) and I think it has the default config. for a pi 2.
      There are no real performance issues that I’ve encountered. It was just one I had lying about and thought I’d try it. Buying a new Pi should be more than sufficient.

      My free -m is:
      total used free shared buff/cache available
      Mem: 925 163 524 9 237 697
      Swap: 99 0 99

      My CPU Info is:
      processor : 0
      model name : ARMv7 Processor rev 5 (v7l)
      BogoMIPS : 38.40
      Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
      CPU implementer : 0x41
      CPU architecture: 7
      CPU variant : 0x0
      CPU part : 0xc07
      CPU revision : 5

      Hardware : BCM2835
      Revision : a21041
      Serial : 00000000f7413a5a
      Model : Raspberry Pi 2 Model B Rev 1.1

      That should be more info than you need.

      Like

    • I am using a Raspberry PI 4 with 2 gig ram. I am running the full “Buster” operating system, which you can get from the Raspberry PI web site. I use a 24 inch HDMI TV for a monitor. I like the PI 4 in the shop because it is fast enough for web browsing etc. It also has desktop apps like a calculator, and office, although I only use the spreadsheet. I have Universal Gcode Sender, and bCNC running on it, and can use either one for the CNC router. I like UGS a little better, maybe just because of the visualizer and because I’ve used it longer. However, bCNC has a nice perimeter check.
      I use WinSCP on my windows machine to ftp gcode files to the PI.

      Like

      • Thank you both cebess and David G ! This is great. I have still not decided the setup I’m gonna use : either have a display next to the pi (but the display gather dust too) or just remotely control it through VNC from another place (but then it’s not very convenient to adjust and test since the controlling computer is far from the CNC). I guess the best would be to have a mobile display I only bring for test and launch, maybe a tablet or something like that. Cebess you said you managed to use your phone to remotely connect to with the pi ?

        Like

        • Don’t forget you can control the CNC from android or iphone. I have a small (cheap) android tablet setting by my setup so I can see the screen. I have a mouse connected directly to the Pi. It seems to work. Also with VNC you have file transport and can have both the phone or tablet connected at the same time as your main machine.
          You are right though that dust collected on the hardware is one of the main reasons for the Pi/tablet combo.

          Like

          • I have now my setup up and running. I have a RPI with UGS, and I control it via VNC with an android tablet.
            The tablet serves as display and keyboard. I also connected a small numpad to the pi, to easily adjust the zero on the CNC. This setup is awesome, and I’d like to thank all of you for your ideas and help.

            Like

          • Sounds like you’ve got something working well. I have VNC running to a cheap android tablet I had lying around, but hadn’t thought about a little keypad. I dig out a large keyboard when I need it.

            Like

  6. So happy. I have been struggling for days to set up my Pi to run my new Millright Mega V. This was the next to last step in a process that has taken me a few months.

    Next step is to be able to watch the CNC from the comfort of my house, or anywhere for that matter. I have the Pi Camera v2 and I am going to try to stream it using the instructions found here: https://elinux.org/RPi-Cam-Web-Interface. I had it working earlier, but then started from scratch when trying to figure out how to get both the visualizer and VNC working, so it should work again. The latency is just barely detectable. Fingers crossed.

    Like

  7. First off Thank you for this guide. It is exactly what i needed. I am running into one issue though. I am running on a 3 B+ and installed the full Raspberry Pie OS and updated today (7/1/2020). I reinstalled Java as it looked like it was version 11 so removed and installed latest of version 8. I set up the sh where it renames the VC directory and launches UGS but when it launches UGS, the task bar blinks on and off a few times then just goes away never to return. I set up the cron job to make sure the folder is renamed if there is and issue and i also tried using what @David Grimm use with the wait 45 and rename the vc.old back to vc and still loose the task bar. Do you or anyone else have any ideas how to resolve?

    Like

      • The OS task bar, where the Rasberry button is, Terminal, file explorer and web browser. The whole thing just goes away, comes back a few (5 – 7) times then is gone. The only way i have been able to get it back is to reboot the rpi.

        Like

        • Not sure what i did but the OS task bar is now staying. Now I cannot get the camera to work with the pelrun camera plugin. I have a Logitech c270 and tested with guvcview. It detects the camera and shows video and records the audio but ugs does not.

          Like

          • So i was up for another 2 hrs after the last message. I setup MJPG-streamer on the same rpi and was able to stream just fine, wondering if that streaming plugin just does not support a usb camera. I set up UGS on my windows machine and it is working with the same camera.

            Like

          • I was just hoping it would be embedded like it is on my laptop that is on its way out the door. Streaming will have to work though and save me from being remoted in all the time to watch.

            Like

    • I think you mean the sudo command which provides the capabilities of running commands with Super User privileges. It is a part of standard Linux. If you mean something else, I am not aware of that instruction so then it would be NO.

      Like

      • step 4 of the instructions “Install the CAM software” is broken into 6 steps.
        The 4th step of that is a shell script which moves a file, launches UGS, and then moves the file back when UGS closes.
        The top line of this shell script, as it is written above, is “#!/bin/shsudo” , which I now assume is a typo?
        I assume it should be “#!/bin/sh” and then you would run the script with sudo

        Like

  8. After more than an hour of playing with this I finally gave up and got a pre-made RPI image of bCNC. It worked perfectly with almost no setup on an RPI 3. And after using both Universal G-Code Sender and bCNC I have found that bCNC is easier to use, has better features and fewer bugs.

    Like

  9. Hey theres an issue with the “sudo mv /opt/vc /opt/vc.old” step; Im receiving the message “mv: cannot stat ‘/opt/vc’: No such file or directory”

    -Mitchell S. Reece

    Like

  10. So when you look around your machine, I assume there is a /opt folder – right?
    You have VNC installed and it worked – right?

    The purpose of doing this is to save the old VNC configuration. I am not sure I even do that anymore after some recent upgrades. I’ll have to check.

    Like

  11. HI cebess, I had followed the instructions on a Raspberrry Pi 4 running VNC server, and decided to try it without moving the vc directory and it worked – until today. Today, it did not display the visualizer, so I put back in the mv commands and it worked. I see that you had also added the “& sleep 75”. When I try this, UGS starts up fine, but then after 75 seconds, it shuts down. What am I missing? Thanks.

    Like

    • Never mind – I forgot to change it to executable. After I did that it works fine. You can delete the post if you want.

      Like

  12. Hello, I cannot get the ugsplatform command to run in the Rpi. I get the following error:

    ./ugsplatform
    ./../platform/lib/nbexec: line 434: 16491 Segmentation fault

    Any ideas?

    Thanks!

    David Foust

    Like

      • I am running the latest version of Raspian on an older Raspberry Pi (Model B version 1.2) and I downloaded the latest version of UGS for the Raspberry Pi (v2.0.12). I am remoting into the Pi using Windows Remote Desktop Connection. I’m following the steps above and when I try to run the /home/pi/ugsplatform-pi/bin/ugsplatform executable, I get the following error (sorry, it’s a long error):

        pi@JoeCNC:~/ugs/ugsplatform-pi/bin $ ./ugsplatform
        ./../platform/lib/nbexec: line 434: 16491 Segmentation fault “/home/pi/ugs/ugsplatform-pi/jdk/jdk8u275-b01-jre/bin/java” -Djdk.home=”/home/pi/ugs/ugsplatform-pi/jdk/jdk8u275-b01-jre” -classpath “/home/pi/ugs/ugsplatform-pi/platform/lib/boot.jar:/home/pi/ugs/ugsplatform-pi/platform/lib/org-openide-modules.jar:/home/pi/ugs/ugsplatform-pi/platform/lib/org-openide-util.jar:/home/pi/ugs/ugsplatform-pi/platform/lib/org-openide-util-lookup.jar:/home/pi/ugs/ugsplatform-pi/platform/lib/org-openide-util-ui.jar” -Dnetbeans.dirs=”/home/pi/ugs/ugsplatform-pi/etc:/home/pi/ugs/ugsplatform-pi/extra:/home/pi/ugs/ugsplatform-pi/ugsplatform:/home/pi/ugs/ugsplatform-pi/bin:/home/pi/ugs/ugsplatform-pi/ide:/home/pi/ugs/ugsplatform-pi/java:/home/pi/ugs/ugsplatform-pi/platform:” -Dnetbeans.home=”/home/pi/ugs/ugsplatform-pi/platform” ‘-Xms64m’ ‘-Xverify:none’ ‘-Dsun.java2d.noddraw=true’ ‘-Dsun.awt.noerasebackground=true’ ‘-Dnetbeans.indexing.noFileRefresh=true’ ‘-Dorg.openide.text.big.file.size=20’ -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=”/home/pi/.ugsplatform/2.0.12/dev/var/log/heapdump.hprof” org.netbeans.Main –cachedir “” –userdir “/home/pi/.ugsplatform/2.0.12/dev” “–branding” “ugsplatform” 0<&0

        I have installed Java 8 on the Rpi as well. I rebooted the Rpi and still get the same error.

        Thanks for the help!

        David Foust

        Like

  13. Line 434 in the nbexec file is:

    wait $PID

    I’m guessing the variable $PID isn’t defined in the script. Continuing to research that.

    Like

  14. I controlled my laser for years with UGS on Raspi 3b and Raspbian.
    For another reason I install new Rapberry Pi OS. And yet the installation of UGS seems to be impossible. Have anyone ever installed UGS on latest Raspberry Pi OS (only java11-, no java8-Support)

    Like

Leave a comment