Time lapsing in OctoPrint (Properly!)

Updated 28 August 2018

Now that we have decked out our Lulzbot Taz 6 3D Printer with a really nice looking acrylic enclosure, I'm just about ready to turn on some serious 3D printing work. But before I dive into that endless pool of fun, it's a good time to take 5 minutes and set up our Taz 6 and it's OctoPrint Server with a bed-mounted camera and light system. That way I can monitor my prints from the other side of the warehouse using OctoPrint, and more importantly, I can record some primo looking time-lapses of my 3D prints.

The Goal: Fit the Taz 6 with a camera and decent lighting for recording sweet timelapse videos.

labelled-taz-6-chassis-leds-camera-mounts

Now we could just mount the Pi Camera Board and be done with it, however there would be a severe lack/change in lighting over the course of the day/night that would throw the quality of the time lapse out pretty bad, not to mention that the existing lighting is less than ideal for capturing prints over a long period of time (due to printer location and general lighting problems). If you wanted to do something similar, you might want to check out the Remote 3D Printing with OctoPi & Installing your Taz 6 Enclosure tutorials before you start. 

We've got all the parts for timelapsing (without the LEDs etc) available here.

Finally, I'd love to be able to control my LED strip using the OctoPrint server and the GPIO pins on my Host RPi. It seems like a waste to not be utilising the power of the GPIO at all. 

To get our camera and LEDs working, we needed to do the following main steps:


Finding, Printing and fitting A Taz 6 Camera Bed Mount

In the past, we have connected Pi Camera Boards to OctoPrint for streaming our prints, however, they were never attached to the print bed or at the right angle to get truly spectacular timelapses. The effect we are going for is to have our camera mounted on the front of the print bed, looking toward the print bed on a bit of an angle. By doing it this way, not only do we get to see both the front and side faces of our model but we also have the model staying stationary in the frame, and making it look like the environment around the printer is moving. It makes a time-lapse work really well, especially for 3D prints.

So I needed to either design or find a camera mount that attaches to the Taz 6 Bed. Now I'm all for designing custom options, but first, I took a look at the usual suspects to see what was available.

I googled "Taz 6 Bed Camera Mount" and literally found this awesome model collection by Thingiverse user Tomleech come up as the first result, and I can see why. This model was designed by another Taz 6 user, running OctoPrint software that wanted to do exactly what I want to do. So I did a quick check of the print settings, comments and any other information before downloading the files and taking a look at print time/cost/size etc.

camera-mount-models-in-cura

Models in order left to right - Original Bed Mount, Revision 1 of Bed Mount (Taller Camera positioning and ribbon cable holder), Front of Raspberry Pi Camera Board mount, Rear of Raspberry Pi Camera Board mount.

Before I went on, I had noticed that in the comments on Thingiverse, another maker running the PrintedSolid Acrylic enclosure on their Taz 6 noted that the bed mount came out a little too far to have the front of the case on the printer with the camera mount. The creator had commented back that the mount could not have gone any closer to the print bed as the tool head would collide during the bed levelling sequence. But I didn't believe him, so I took a closer look at just how close we were talking.

To figure that out, I went ahead and printed the creator's updated version of the model along with the camera board mounting box. The tall mount did require support structures to be enabled in Cura but they were pretty minimal. I used a Standard PolyLite PLA Profile in Cura and printed these parts on the Taz 6. The print ended up being a 26-gram print and taking around 3 hours to complete. Then I took this picture to see how much space I had to work with. 

camera-mount-printer-bed-level-proximity

The good thing about the bed levelling sequence/proximity problem was that the level sequence is 100% repeatable, so I could have my camera almost touching the tool head during the levelling sequence and it wouldn't ever collide and damage my mount. Essentially, I decided to dive in and alter the model file so that it hugs the print bed and tool head as much as possible to see if I could squeeze it into the box. All I needed to do was use Experimental Mesh Environment in Fusion360, and use some rough calculations to remove parts from the bottom of the elbow joint just before the bed mount. Take a look below if that was confusing to you, it's hard to describe 3 dimensions with only words.

labelled-removable-material-cura

labelled-removable-material-fusion-360

Once that was all taken care of I went ahead and reprinted the newly modified mounting arm. It came up pretty good and gave me a little extra room to work with.

Now for assembling the mount. I needed to get my Raspberry Pi Camera Board to fit into the camera housing, which required some trimming down of the posts from the rear side of the panel. I just used the Xacto Knife from my printer tool kit to take a few shavings off these without breaking them. Once I attached the 610mm Flex Cable to the Pi Camera Board it all snapped together very nicely. Now all I needed to do was run the flex cable down the mounting arm and to my Pi 3's CSI connector. Luckily the case I used for my Pi 3 has a slot in it for the flex cable. It all connected really easily actually, now to get the camera properly running in OctoPrint.

What the camera mount ended up looking like.

printed-camera-mount-tabletop

bed-mounting-assembly-camera-mount

pi-camera-mounted-rear-view


Setting up a Raspberry Pi Camera v2 with OctoPrint

In previous versions of OctoPrint, you needed to run a Raspi-Config command at the terminal to enable all camera's for use with OctoPrint. However, nowadays that has been changed so that if a USB Webcam or Raspberry Pi Camera is detected at startup, the MJPG-Streamer program (the one that handles the video streaming from your Camera) will begin running on your Raspberry Pi. That's about as close to Plug n' Play as it gets, which is good to see with OctoPrint as it seems pretty inevitable that people end up adding the camera to their setups.

So all I needed to do here was boot up my Raspberry Pi after everything was connected and I could see my camera feed in the Octo-print control panel.

control-tab-webstream-octoprint


Configuring the camera

The first thing I noticed when I looked at the camera feed was that it appeared zoomed it, a little blurry and quite dark. So after some quick googling, I found some pretty handy resources on changing the camera settings. Firstly, you can change the aspect ratio of the camera and a few other things by simply logging into OctoPrint (if you have access control enabled) and be navigating to the Settings Menu (The little spanner icon in the tool bar), then "Webcam and Timelapse" under the "Features" submenu to the left.

You'll see the following options:

  1. Stream URL: This is the URL that you can add to your OctoPrint's hostname.local address to view the webcam directly. It's a relative URL, so you just need to add it to the URL you are accessing your Pi on and it will take you to a Stream only page.
  2. Aspect Ratio: This is the ratio used for image dimensions that are captured through the webcam. The Pi Camera Board can be set up to 3280x2464 (see the image below for the different Fields of View you get with different resolutions)
  3. Flip Horizontal/Vertical: These two options mirror what you see in your stream in the direction indicated, I needed to flip my Pi Camera Board V2 stream vertically here to get the image I was expecting.
  4. Rotate webcam 90 degrees counter clockwise: Another rotation option that depends on how your camera is mounted.
  5. Snapshot URL: This is where each snapshot that will eventually render into a timelapse video is saved to, retrieved from here when you decide to download a timelapse from your Pi. I wouldn't mess with this one, however, you can click on the Test button to take a snapshot and open a link to it.
  6. Path to FFmpeg: This is where the software package that handles handling multimedia on your Pi lives. Don't change this one.

raspberry-pi-camera-resolutions-aspect-ratios

By default, the Pi Camera board captures at a 640x480 resolution at 10 Frames Per Second. Which is pretty horrible if you actually want to see what is going on with your print in decent quality. 

So let's tune that camera up a little bit, then try another time-lapse. After a bit of scratching around online, I found that you can get some pretty optimal results from your camera by changing the above settings to 3280x2464 at 15 frames per second. How do you do that? Well, I'm about to show you.

Essentially, you'll need to edit some of the text-based config files on your OctoPi setup to change the default quality of your camera's image captures. To do that we are going to be using a program called PuTTY to SSH to our Raspberry Pi. If you want a slower, more in-depth guide to SSH take a look at Michael's guide to Setting up a Headless Pi Zero W, as he goes into detail about the how and why there. We are just going to connect, change our required files and reboot.

Download PuTTY if you don't have it from here. You will also need the hostname of your Raspberry Pi, which will be octopi.local/ by default.

Go ahead and login to your Pi via SSH, using your username/password. Once there enter the command

cd /root/bin sudo nano /boot/octopi.txt

Then navigate inside of this text file to the line camera_raspi_options="-fps 10"

Now we can enter any string of settings for our Pi Camera, I am really happy with these settings (although your environment might be set up for different settings). If you want any additional settings, you can find them here.

Anyway, change the line to look like

camera_raspi_options="-fps 15 -x 3280 -y 2464 -ex auto"

Then save the text file and exit.

Once you are back in the terminal you can reboot your Raspberry Pi using the command

sudo reboot

That's all you need to do to get your Pi Camera capturing at 3280x2464 Resolution! Bear in mind you will have to change the Aspect Ratio in your OctoPrint Camera Settings to be 4:3, not 16:9 or you will have black borders down each side of the stream.

Now the focus point of the Pi camera is around 62cm, which is great for most applications, however, we want our models to be in focus on the bed which will usually be around 30cm from the camera location. You can manually change the focus point of the camera by turning the lens, however, it doesn't focus quite how you would expect.  We decided to pick up some cheap 2x reading glasses online and retrofit one of the lenses to the pi camera mount. If you want more information on this, check out this awesome post about it. 

Now that we have a good capture resolution & focus point, we can tune our everything for a beautiful time-lapse capture.

[Lit, configured Timelapse - Video to be added shortly]


Time-lapse Configuration

To tune settings for the time-lapse, just go back into the "Webcam and Timelapse" settings within OctoPrint and expand the Advanced Options out. There are a few thing that will determine the quality of your time-lapse video that goes beyond the quality of the camera options, these settings will affect how you view your timelapse as a video file.

Let's quickly go over what a time-lapse is, so we can see how the listed settings will change the quality of ours. A timelapse is a series of still images, stitched together at a certain frame rate (in Frames Per Second) to speed up/slow down how fast time appears to be passing. An easy way to think of this is viewing a sunset in a few seconds, rather than watching the entire thing. 3D Printing can take long periods of time too, so we can set up OctoPrint to take images using the attached camera, then at the end of the print, render those images into a video file, pretty cool if you ask me.

We can set it up to do a timed timelapse video (take an image every X seconds and use it for the timelapse) or we can set it to trigger on a Z-height change (take 1 image at the start of each layer). I realised that the Z-heigh setting also triggered on Z-hops from my slicer settings, and luckily there is a way to exclude all Z height changes that aren't actual layer changes, so you don't fill your storage up with pointless images. Just set the Z-hop option on the timelapse tab to be 0.1mm and you should be fine.

We can dedicate an amount of data per second of our time-lapse video by editing the bit rate setting in OctoPrint. The bit rate of the video is the amount of data we are willing to dedicate to each second of video, the higher the value the better the time lapse will look. However, you can overdo it and the Pi mightn't be able to keep up with rendering things at too high a bitrate, so you might need to experiment with what works for you here.

While you are at it, go ahead and change the bit rate to 10000k from 5000k and Cores from 1 to 4 to help render larger videos (Go Pi 3!). Now let's take a quick look at how we setup our Timelapse videos to be recorded.

Head to the time-lapse menu in the OctoPrint server home screen and take a look at the available options. I played around a bit to get my settings and I am quite happy with how my time lapses are turning out now. I'll show you a screen shot of them below if you want to copy them, but it's probably better to just get in there and play with them yourself.

timelapse-settings-octoprint

That's pretty much it for our webcam/time-lapse setup! Hit save and reboot your OctoPi setup to apply all the changes. When your Pi reboots, you will notice the video feed quality will have improved! Cool. Now all that's left to do is organise the LED lighting & control for our Taz 6!


Adding Lights to the Taz 6

When it comes to adding lighting to your 3D Printer setup, you can go in a few different ways. You could add some lamps to get light in and around your prints, you can mount some LED strips to get your printer well lit, and you could even get some addressable RGB LEDs and go full maker with your Raspberry Pi GPIO for control. We're going a mix of option two & 3 and adding some White LED strips to the frame of our Taz 6, controlling them via the RPi GPIO to make our time-lapse videos well lit.

I found some 5M Rolls of 60 LED/Meter White LEDs laying around the warehouse, alongside a 12V 6A power supply that seemed like a perfect fit for it.

All I had to do was measure up the three sides of my printer and trim down my 5-meter reel to size.

trimmed-led-strip

It seemed like a little bit overkill, but I then stripped the protective rubber coating off the end of the strip and made some small jumps by soldering some Hook-up wire directly to the strip, these were made to bend around the corners in the printer so I didn't have any issues in sticking the LEDs to the printer frame. I also used some heat shrink to cover those connections up.

soldered-led-strips

Then to be sure everything was working, I connected each of my strips up to the Rigol DP832 Power Supply. One of them actually had a dry solder joint (from the manufacturer!) about 3/4 through the strip! To fix this I cut down the protective rubber and re-soldered the joint. Now everything was up to scratch and looking great!

Once I had 2 strips connected together, I made a really simple connection to the power supply by soldering each strip's power connectors together, then crimping them with a spade connector so they were relatively accessible.

lit-led-strip-testing

Now to mount the strips on the 3D printer, I had initially wanted to mount the strips INSIDE of the aluminium extrusions (facing inward toward the print bed), just for a clean and polished look, but the rubber protection that was covering my LEDs wouldn't allow this to fit. So I opted to mount them in the same orientation (facing inward) but by using the 3M adhesive on the back side of the strips (as well as some double sided tape to help adhesion). I found that the LEDs on the right-hand side of the case were too bright for the camera causing all sorts of glare so I ended up ditching them by cutting them off at the marked join, leaving me with 2 strips of lights on the left frame and horizontal top frame. 

led-strip-left-hand-frame

The timelapses still seemed a little dark and not having the additional light from the right-hand side was causing a pretty big shadow to appear on the print bed from the tool head carriage. We decided on mounting a single segment of LED strip to the Camera mount upright. As light would be good for the front left and the front right of the print bed I decided to print ANOTHER camera mount, with the actual U-shaped camera mount cut-off. That way we could have an upright for an LED on the front right of the printer too. To get my mount to fit on the other side of the bed, I used the Mirror function in Cura to flip the model so that it would still attach to the bed on the same angle as my original, but from the right-hand side of the bed rather than the left. It worked spectacularly.

Now all that was left to do was to test my time-lapse settings/camera setup in a dark room with only my LED light strip on for camera light.

Beautiful!

Now I have the ability to generate some pretty awesome Timelapse videos of my 3D prints on every print! The only thing to move past now is controlling the LEDs. At the moment, the power source for the LEDs goes straight to the wall socket and you have to manually plug it in when you want them on.


Raspberry Pi GPIO and LED Strip Control with OctoPrint

This is where this project became a lot more fun. There's something really exciting and enjoyable about making a computer control a physical circuit (even if it takes a couple of tries to get it right). The goal was to utilise the GPIO pins of the Raspberry Pi alongside a Plug-in for OctoPrint so that I could control the status of my newly installed lights from the comfort of the OctoPrint HUD.

First I needed to find a plugin that would do what I needed it to. Then, I needed to find out how that plugin controlled the GPIO. Then I needed a circuit that could switch the 12V ~3A LED Strips on and off safely.

I found the Enclosure Plugin, that not only is made to control LED Lights on a OctoPi setup but also has capabilities to add temperature sensors and enclosure fans to regulate temperatures! Perfect. Below is a screengrab of the basic way you configure an output pin using this plugin.

enclosure-plugin-io-settings

As you can see there are all the options you need for a simple switch (really you just need to be able to switch a pin on and off). All I needed to do was pick a GPIO Pin to use for my switching circuit and configure it to behave like I needed it to. You can find a decent Pinout of the GPIO pins below (note that the GPIO is the same for the Pi 3 and Pi 2).

pi-3-gpio-pinout

I used GPIO Pin 4, had the Lights AutoStart and AutoShutdown using a regular output type (on/off). I also deselected Active Low logic, meaning when the Pi turns on it will switch to a high signal (for the GPIO that's a 3.3V signal). I quickly tested my GPIO Pin with a Multimeter to make sure it was switching like I expected, and it did. Great! Now to find a circuit that can switch my strips safely.

After toiling with a few MOSFETs for a few hours I skipped right ahead to a Relay control circuit. I went with the Beefcake Relay Control Kit from SparkFun as it seemed to, be able to handle everything I needed it to.  After some quick soldering to get the kit together, we tested the how the relay would switch using a 3.3V signal and it didn't seem to switch as convincingly as we would have liked. The circuit was designed for a 5V Control Signal, so we did some quick calculations as swapped the Bias Resistor connected to the Collector of the transistor on the circuit to a 680ohm down from a 1k ohm. This enabled the 3.3V signal to switch the relay reliably.

You can see how we connected the Relay control circuit to our Raspberry Pi 3 below:

beefcake-pi-3-enclosure-plugin-fritzing-diagram

And, just as we expected, we now had full control of the LED strip via the Enclosure Plugin Tab on OctoPrint!

enclosure-plugin-tab-octoprint

And this is how the Enclosure ended up looking with the lights on.

final-enclosure-lights-on

And here is a tasty timelapse print from our new setup. [Video to be added shortly!]

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.