Skip to content

Setting up a Raspberry Pi as RepRap host controller

wmar edited this page Nov 17, 2014 · 8 revisions

I've finally succeeded in getting my second RepRap running with full RepRap host control software running on a Raspberry Pi (RPi) - with the RPi mounted on the RepRap itself, this means I have a self-contained print station that doesn't need to tie up an expensive computer while it's printing stuff.

This page is a dump of the various notes I made getting to this stage. There's a more crafted tutorial by @ameralytical at http://entropyprojects.blogspot.co.uk/2012/07/reprap-printing-from-raspberry-pi.html?m=1.

The RepRap is based on an original Mendel design, with a few minor design alternatives that I found scattered around the web - mainly on Thingiverse. The microcontroller that interprets GCodes drives the stepper motors, heaters is a Sanguinololu running Sprinter firmware. (These details may be relevant, as I've found in the past that not all host software is compatible with all firmwares, and not all firmwares with all controller electronics.)

The job of the RPi in all this is to feed GCode commands to the controller, and provide a manual interface for controlling the RepRap, to be used when setting up a print job. (I originally had ideas to use it for 3D design and "slicing" the 3D object into layers and GCode command generation, but those are compute-intensive tasks and just performing the host controller functions seems to use much of its capability.)

Initial system load

The RPi won't boot or do anything - not even flash a blinking cursor - until it has an SD card with a bootable image.

  • Grabbed a copy of the Raspbian software distribution (http://www.raspbian.org/)

  • On a Linux system, copy this onto an 8Gb SD card, thus:

      dd if=<image-file> of=<sd-card-device>
    
  • To find the name of the SD card device, try one of these commands:

      fdisk -l
      cat /proc/partitions
    
  • Insert the SD card with the Raspbian software into the RPi, connect a keyboard, monitor, and network cable, then power up.

Setting up default Debian-based system

  • The initial boot provides configuration options: select the option to expand root partition to entire SD card

  • Reboot - this takes a while (20 mins or so) to resize the root partition

    • with a network cable connected, the system pretty much sorts itself out using DHCP, including setting the system time via NTP.
    • (May need to reboot again.)
  • Login (pi/raspberry), and run these commands:

      apt-get update
      dpkg-reconfigure openssh-server # (to generate host keys)
    

From this point onwards, it is possible to use an SSH connection from another machine to continue the setup process.

Install Printrun host software

  • Install some development-related tools

      sudo apt-get install git
      sudo apt-get install mercurial
      sudo apt-get install python-distribute
      sudo easy_install pip
    
  • Install serial interface drivers for Python

      sudo pip install pyserial
      sudo apt-get install wx-common
      sudo apt-get install python-wx2.8
    
  • Install TK libraries for Python (cf. http://tkinter.unpythonic.net/wiki/How_to_install_Tkinter)

      sudo apt-get install python-pmw python-imaging
    
  • Get copy of printrun (cf. http://reprap.org/wiki/Printrun):

      git clone https://github.com/kliment/Printrun.git
    
  • Download the latest Skeinforge from http://fabmetheus.crsndoo.com/, and unpack. (I don't use Skeinforge on the RPi, but I think there's a dependency on it in PrintRun.)

Check out serial ports

The serial interface to the RepRap controller board is provided via the RPi USB port. To list USB devices visible to the RPi:

    lsusb

With the RepRap Sanguinololu board connected and powered, the interface port should show up as something like /dev/ttyUSB0.

Run the RepRap host software

On the RPi console, logged in as the user used to install the software (default "pi"):

startx

The X-window environment will start. Locate and start LXTerminal (under "Accessories", but I create a desktop shortcut). In the terminal session window that appears, enter:

cd Printrun (or wherever the RepRap software was installed)
python pronterface.py

The host control software should now start.

About this point, I ran into problems. Although the host software would start OK, it would not connect to the RepRap. In hindsight, I think the problem may have been because I was using a high resolution HDMI monitor at 1920x1200 display resolution, which would put quite a high memory demand on the X-window system. Later, I found that using a small composite video monitor, the "pronterface" software would connect OK. But, initially, this problem caused me to follow a different path...

Run the RepRap print console software

In the same directory as the Reprap "pronterface" software is a simple command-line utility that can drive the RepRap using simple commands. Although this is less pretty to work with, it has the advantage that it can be used to drive the RepRap over an SSH network connection from a "headless" RPi (i.e. with no monitor or keyboard attached). Once I got used to it, I actually find this easier than using the graphical interface (provided I know the network address to use for the initial SSh connection).

This utility can be run without starting the X-window system. In a terminal session (on the RPi console of an SSH connection), just enter:

cd Printrun (or wherever the RepRap software was installed)
python pronsole.py

The connect command establishes communication with the RepRap - I find it takes 3-5 seconds to establish a connection, so be patient and wait until a summary of the connection is displayed before proceeding. From there, use the help command to find more.

I prefer to use the RepRap print console via an SSH connection. When using the load command to load a GCode file, no filename completion is provided, so you have to remember and type out the entire path to the GCode file. I use a second SSH session to locate the file using shell commands, then copy and paste to the print console session.

Configuring a non-HDMI monitor

Further to my problems using pronterface with a high resolution HDMI monitor, I have ended up using a small 10" monitor connected via the RPi composite video connector. The pronterface program requires a screen size a little over 800x600 in order to display all of the GUI controls: the default display resolution when using a non-HDMI display is somewhat smaller than this, so I tweaked the video parameters in /boot/config.txt to set the display size to be large enough for pronterface, but leave characters still (just about) legible on a low resolution display. My /boot/config.txt file now contains the following options:

hdmi_group=1
hdmi_mode=41 # 720p, 100Hz

framebuffer_width=880
framebuffer_height=660

overscan_left=16
overscan_right=0
overscan_top=-16
overscan_bottom=-16

Get the mode and framebuffer settings right first, then tweak the overscan to suit your display (if needed). Note that the Ri must be rebooted for changes to take effect, and that editing the /boot/config.txt file needs root privileges.

For more information:

Other random notes and links

  • The tutorial by @ameralytical is well wortn reviewing. There are many useful details there.
  • Following @ameralytical, I overclocked my RPi to 800 before starting.
  • @ameralytical suggests setting the serial rate to 115200. As I was originally experiencing problems connecting to the RPi, I reduced it further to 57600 (this needs change to RepRap firmware), and haven't changed it back. Once connected, the connection seems to be rock solid.