Skip to main content

Controlling LED through Octolapse for 3D print timelapse

Today's post is about one of the 3D Printing adaptation that I learned. This is specifically about how to control an LED light automatically through OctoLapse so that it is switched on only when the timelapse photo is taken.

Just as a background, I have been learning to use 3D printer and its customizations options for a few months now and was a lot of learning since then. The best thing was OctoPi, a platform for controlling the 3D printer and the many plugin options that are developed by the community.  Most of them are like open source. Today we will discuss specifically about an adaptation to one such plugin, OctoLapse.

OctoLapse is the plugin for taking timelapse photos, with many options for further customisations. One of the best timelapse method is taking photo after each layer is complete, by moving the head out of the way. You can use standard Pi Camera or a DSLR, which is great to get good resolution videos.

One small flash back before we dive into the topic.  I keep the printer at the corner of the shelf.  most of the printing happens at the night. If I needed to check on it, it was not easy.  I found the way around by keeping a LED strip at that location and it was connected using a relay controlled through GPIO pin of Pi. There is an ENCLOSURE plug-in that allows the GPIO pin to be controlled through the OctoPrint Web Interface. This allowed me to switch the light on and off through the web.  When I need to check on the print, I can see the status using the webcam by switching the light on. Once I am done, I can turn it off as well.

Coming back to the topic now. I setup the DSLR to take the time lapse. But the next challenge was that I needed light while taking photo. I could keep the LED always-on to do that, but that was not the best way.  I felt there must be a way to switch on and off the LED before and after the photo is taken, through the OctoLapse. But it was not as straight forward as I thought it would be!

Some guidance from FormerLuker confirmed that it has to be through a python script and thanks to him helping be with right leads. More googling and applying some gut instincts (as my python knowledge was close to zero if not zero).  But then how to create the script. Then realised that it is a file to be created inside Pi and did it through SSH through putty, again salvaged codes from web. Created two files, one for switching on and another for switching off.  I will keep the codes at the end of the post. 

I created those and specified that in the additional settings of camera within the OctoLapse. Again few more nights of debugging and tinkering resulted in success. One issue was that if I keep both raw and jpeg on, it resulted in some error and had to configure camera for only jpeg files. Another issue was that the delay had to be large enough to transfer the file. One those were done right. It worked. Pilot run revealed that I had to allow a second or two for the LED to be of correct colour. One that's also set, it was nearly done.

Once you have the python scripts created, below are the snapshot of the settings to be updated.
1. Go to the OctoLapse and edit the Camera Settings
2. Go to the Custom Camera Scripts and add the python scripts along with full location.


The wiring diagram..



But like any DIY, one challenge leads to another. I realised that the camera battery didn't last enough for to usb connection. Had to make a custom power back for camera, but that's for another video.

Contents of led-on.py
#!/usr/bin/env python
#!/bin/sh

import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

GPIO.output(18, True)

time.sleep(2)

Contents of led-pff.py

#!/usr/bin/env python
#!/bin/sh

import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

GPIO.output(18, False)

time.sleep(2)

Hope this helps you further the explorations 😀 

Comments

Popular posts from this blog

TreeView Structure in Excel VBA

TreeView is extreamly useful in specific cases but it can be bit tricky sometimes to implement.  Last Few days I was working on a TreeView Structure and thought I will share the knowledge I gained...  This post takes you through the basic operations to create and operate a TreeView. It will be like the Folder tree window of the windows explorer.  Moreover, you can have it dynamically updated based on the data in excel.... Here we go..

Excel Function :TABLE

Its been a while since I have done some posting. This option in excel is something which I thought would be very useful for many. Its the TABLE Function in MS Excel. This is especially useful in the following scenarios.