Categories
3D Printing Electric Skateboard Electronics

Custom lighting system for my electric skateboard

Recently I’ve joined a local electric skateboard group that goes on regular group rides. Unfortunately most of these are at night and I don’t have any sort of lights. It’s dangerous to ride at night as I can’t see what’s ahead of me and others can’t see me.

Instead of forking out a large amount of money for some pretty basic (and boring) lights I decided to make my own. I purchased some 300 LED/m WS2812B strip and a 15W LED light bar off eBay. The light bar requires 12v so I built a 3s3p (12.6v, ~6Ah) battery pack out of 18650 Li-ion batteries. This means I needed a 5v power supply to run the LED strips and ESP8266 micro controller. Products on eBay tend to be overrated so I normally aim for something rated much higher than necessary.

The 5v, 5A power supply used.

I designed and 3D printed a case to fit all of the batteries and electronics inside. It’s a bit bigger than necessary but I wasn’t certain on the size of everything when I made it. I designed it so the light bar attaches onto the front so it’s easier to mount on the board. The cables come out via two waterproof glands for the light bar, and charger (red, black) / led strip (yellow, green, white).

The controller box and light bar mount.

The adhesive that comes on the LED strip isn’t very good. I 3D printed some little plastic holders for the strip instead. Using some tiny screws, these screwed into the board for a really solid mount. Near the back wheels it was easier to use zip ties for mounting the strip.

The underside of the board with the light strips held in place by some 3D printed plastic clips.

The final result is great! It makes a huge difference while riding at night. I can clearly see what’s in front of me, and everyone can see me coming from ages away due to the fancy light show going on underneath the board and huge light bar on the front. 😉

Categories
3D Printing Linux Raspberry Pi Software

How to get great webcam quality with Octoprint

I have OctoPrint set up to help me manage my 3D printer, record timelapses and remotely monitor it. OctoPrint is a great tool and something I strongly recommend to everyone. I’ve also setup a webcam so that OctoPrint can stream the footage in real time, and also create awesome timelapses. I have a Logitech C920 – one of the highest regarded webcams available, and yet I was still getting poor results. Read on to find out how I fixed this.

The Logitech C920 is a great webcam and can be had for as little as $100. However, in the case of mounting it up close on a 3D printer with a quickly moving subject, the auto focus and exposure really struggles. I’ve got a fixed mount, and a consistent lighting set up in my printer’s enclosure so there’s no reason for the focus or exposure to be adjusted once it’s correct.

Luckily, it’s easy enough to manually configure these settings. These commands were tested on a Raspberry Pi 3+ Model B with a Logitech C920 webcam. Results may vary on other setups.

First of all, you’ll want to turn off auto exposure by running the following command on your OctoPrint Pi:

v4l2-ctl -c exposure_auto=1

Once you have turned off auto exposure, it’s time to play around with the exposure value. A good starting value is probably around 600, but it varies with your specific set up. You should play around with this number by adding or subtracting 100 at a time until you get a good quality image. You can open up the OctoPrint webcam stream while you’re doing this. Run the command below to set your exposure to a value of 600:

v4l2-ctl -c exposure_absolute=600

Now your exposure is dialed in, it’s time to move onto the focus. This was the biggest problem for me as the webcam was hunting for focus all the time resulting in a near constant blurry image. Turn off auto focus by running the command below:

v4l2-ctl -c focus_auto=0
A picture of my 3D printer (CR-10 v2) webcam setup. The printer control box and OctoPrint Pi are off to the left out of frame.

With auto focus off, we can now play around with the focus settings. My webcam is mounted above my 3D printer towards the front, and is about 50cm away from the build plate (pictured above). Start with a focus value of 1 and then work your way up from there by adding 1 at a time. If you’re not seeing much difference between the values, try jumping up 5 at a time then fine tuning it when it’s almost there. Set the focus value to 1 with this command:

v4l2-ctl -c focus_absolute=1

Putting it all together

Now that we’ve got all the settings dialed in, it’s time to make them stick. By default, these settings won’t persist if you reboot your OctoPrint Pi. First you should combine all the commands together like the code snippet below, be sure to replace with your dialed in values:

v4l2-ctl -c exposure_auto=1 && v4l2-ctl -c exposure_absolute=600 && v4l2-ctl -c focus_auto=0 && v4l2-ctl -c focus_absolute=2

You’ll need to open a config file called /home/pi/mjpg-streamer/start.sh. Note, some users have reported that /etc/rc.local is now the correct place (you’ll need to use sudo when editing this). You may have to try both. Use your favourite text editor. If you’re new to editing files on the command line, you should look up how to use nano and come back here once you’re familiar. Create a new line at the very end of the file and the code snippet from above there. Save and exit. Now whenever OctoPrint starts up the mjpg-streamer service your custom camera settings will take affect.

Following these steps helped me dramatically boost the quality of the live stream, and timelapse footage of my prints. It went from over exposed and fuzzy to nice and clear with a good exposure.

Note: I’ve been using the excellent “octolapse” plugin recently which has similar functionality (and a GUI!) built right in. So I’d recommend to give that a go if you don’t mind the extra plugin and complexity.