RPi MacroScope

22,108

253

23

Posted

Introduction: RPi MacroScope

Raspberry Pi Contest 2017

Runner Up in the
Raspberry Pi Contest 2017

LED Contest 2017

Runner Up in the
LED Contest 2017

The Raspberry Pi, combined with an adjustable focus camera, can be used to help us better observe the world between microscopic and the un-aided eye. I primarily use this for photographing electronic assembly (including all the pictures in this Instructable), but it can also be used to take videos and create timelapses. The addition of a foot pedal allows for hands-free camera work. Images can be stored on a USB thumb drive, or to the expanded Fat32 formatted section of the Pi's SD card so it can be removed and read on a Windows computer.

This project is quite involved, but has three separate aspects that can be utilized independent of the others:

  • PiFet: A circuit board containing circuitry to control the LED light ring and provide user input via push buttons.
  • Case: A 3D printed case and camera mount.
  • Setup: Configure the Raspberry Pi and Python scripts.

I've found this project to be quite useful, and hope you will find something intriguing enough for you to try it. Let's begin ...

Step 1: PiFet: Parts and Supplies

To start with, we are going to use a MOSFET to control a 12 volt LED ring. Since we are going to use 12 volts, we might as well power the Pi with it to eliminate an unneeded USB cable. And, since we are making a PCB, we might as well add buttons and LEDs for user interaction.

You will need the following items for the PiFet:

The following items needed for setting up the Pi can also be purchased from Digikey:

Tools and Supplies:

For my workshops, I use SparkFun's Beginner's ToolKit which has everything you need:

  • Soldering iron.
  • Solder
  • WireFlush-cut plyers (I love the $5 Hakko CHP170!)
  • Desoldering braid

A kit for this project is available on Tindie.com. Purchasing the kit will save you the time and expense of ordering from several different vendors and avoid the minimum PCB order premium. You will also be helping me develop and share other projects in my workshops!

Step 2: PiFet: Resistors

We are going to assume you have some kit-building experience. If you need some help soldering, head over to www.sparkfun.com/tutorials/213 to brush up or watch the Geek Girl explain it at https://youtu.be/P5L4Gl6Q4Xo. I also have a kit appropriate for beginners at https://www.tindie.com/products/3447/.

I like starting with the resistors because a) they are relatively heat resistant while you are getting into your soldering groove and the iron is coming up to temp, b) they have no polarity, so orientation is not critical, and c) they are the lowest component on the board so sit tight when soldering.

  • Bend the leads to the width of the pads
  • Insert the resistor.
  • Flip the board over and solder the leads.
  • Trim the leads with flush cuts.
  • Hit them again with the iron if you want them to impress your geek friends.

Step 3: PiFet: Diode

We have one diode to install, which does have a polarity, so must be installed in the correct orientation. The position on the board is marked "D4" and has a wight stripe on one end which must match the strip on the component.

Note: If you intend to put the project in a case, the diode and 10K resistor must be installed on the opposite side of the board.

  • Bend the leads to the width of the pads
  • Insert the diode.
  • Flip the board over and solder the leads.
  • Trim the leads with flush cuts.

Repeat this steps for the final remaining 10K resistor (or do them at the same time).

Step 4: PiFet: Capacitors

Some capacitors have polarity, but these do not. These are also installed on the bottom side of the board.

  • Insert the capacitors so the leads come up next to the push button silk screen on the top of the board.
  • Solder the leads in place.
  • Cut the leads flush with the board.

Step 5: PiFet: LEDs

LEDs have polarity, and are the most heat-sensitive component on the board. The color order is arbitrary and your choice.

  • Insert the LED with the long lead (positive) in the square pad marked "+".
  • Solder one lead in place.
  • Verify the LED is seated correctly and reheat if necessary.
  • Solder the remaining lead in place.
  • Trim the leads flush with the circuit board.

Step 6: PiFet: Buttons

The buttons can be used for anything and are marked with the GPIO pins they are connected for. I use SW1 to turn the light on and off and shutdown or restart the Pi. I use the other two to zoom in and out.

  • Insert the red button in SW1 position.
  • Insert black buttons in SW2 & 3 positions.
  • Flip the circuit board over and solder the leads.
  • Clip the leads flush.

Step 7: PiFet: MOSFET

  • Place the MOSFET leads in the pads and bend the leads so hole in the heat sink matches up the hole in the PCB.
  • Solder the leads in place.
  • Trim the leads flush with the PCB.

Step 8: PiFet: Power Jack

The 2.1mm Power jack is pretty common, and "center-positive" is the usual arrangement, so hopefully you have one laying around.

  • Insert the jack on the top side of the board.
  • Solder the back led in position.
  • Tilt the jack up several millimeters (you'll see why later).
  • Solder the remaining two leads in position.

Step 9: PiFet: Terminal

  • Insert the terminal on the bottom side of the board with the terminal opening facing outward.
  • Solder the leads in place.
  • Trim the leads flush with the PCB.

Step 10: PiFet: Header

  • Insert the header on the bottom side of the board.
  • Solder two pins in place.
  • Check that the header is flush and straight.
  • Solder the remaining pins.
  • Clip the pins flush.

Step 11: PiFet: Regulator

To convert 12 volts to 5 volts, we will use a 1 amp power switching regulator for efficiency.

  • Install the regulator on the bottom side of the PCB with the text facing outward.
  • Solder the leads in place.
  • Clip the leads flush with the circuit board.

Step 12: Case: Parts & Hardware

Now to case our project. I've tried a couple of cases I found on Thingiverse, but was never completely happy with them, so I designed one from the ground up using FreeCad. That means not only can you build one, you can change it to meet your needs (using free Open Source software)!

I've posted all the files you will need at https://www.thingiverse.com/thing:2720256

Print the body with support. All the other parts do not need support. I would use a fill of 50% or 100%.

You will also need the following hardware and parts:

Step 13: Case: Assembly

  • Slide the light ring over the housing.
  • Press firmly to get the tabs over the edge (this is opposite the way they were designed).

  • Place the Pi into the body with the underside up.
  • Place the bottom on to the case.
  • Insert the four screws and tighten.

Step 14: Case: Camera Cable and LED Leads

  • Install the camera cable (with the pads away from the Ethernet port).
  • Insert the ribbon cable up through the top of the case.
  • Insert the LED leads down through the top of the case.
  • Insert the leads to the terminal observing the polarity.
  • Insert the PiFet on to the Pi header.

Step 15: Case: Top and LED Ring

  • Arrange the wires so they don't pinch and place the top of the case in place.
  • Insert the four screws.
  • Place the camera arm base on the top and insert two screws.
  • Place the LED ring housing on the top of the arm.
  • Insert the bolt with the hex head on the side containing the hex inset.
  • Screw the knurled knob until it is snug.

Step 16: Case: Camera Arm and Camera.

  • Insert the arm on the arm bracket.
  • Insert the hex nut on the side with the hex inset.
  • Screw knurled nut on to bolt snugly.

  • Place camera on LED ring base and install at least two of the screws on opposite sides.
  • Insert the ribbon cable through the slot and into the camera connector.

Step 17: Setup: Downloads

Step 18: Setup: Raspberry Pi

Fire Up the Pi:

  • Insert the SD card into the Raspberry Pi.
  • Connect your Raspberry Pi to the monitor, keyboard, and mouse.
  • Power up the Pi and let it boot into the desktop.

From the desktop, start a command window, and issue the command "sudo raspi-config" and change the following options:

  • Change password
  • Enable SSH, I2C (optional)
  • Enable camera
  • Set time zone
  • US keyboard

Free up some extra space by removing unnecessary software via the command line:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get purge wolfram-engine sonic-pi scratch
  • sudo apt-get clean
  • sudo apt-get autoremove

And lastly, we need some additional software for creating MP4 videos:

  • sudo apt-get install -y gpac

Step 19: Setup: Resize Partition (Optional, and a Bit Difficult)

The Raspberry Pi card has two partitions, a small FAT32 formatted section that is readable in a Windows computer, and the Linux partition containing the Raspberian OS. If we want to save more than just a couple of pictures to the FAT32 section, we need to resize it. Unfortunately, this is not trivial. I use the instructions at: https://learn.adafruit.com/resizing-raspberry-pi-boot-partition/edit-partitions

You can use the program GParted in one of the following methods:

If this all seems a bit overwhelming, skip this part and just use a USB thumb drive to save the pictures to.

The good news is, once you get the partitions the way you want, use Win32DiskImg to save a copy of the image and you can clone it at will.

Step 20: Setup: Final Touches

All that is left is to make a desktop icon and configure the script to run on startup:

Add desktop icon:

  • sudo cp /boot/macroscope/Macroscope.desktop /home/pi/Desktop/Macroscope.desktop
  • sudo chmod +x /home/pi/Desktop/Macroscope.desktop

Execute script on startup:

  • sudo nano ~/.config/lxsession/LXDE-pi/autostart
  • Add: "@sudo python /boot/macroscope/macroscope.py"

Step 21: Setup: Use

For most actions, there are buttons and keyboard commands. I initially pictured this being used without a keyboard or mouse, but they can be useful if you want to use the Pi for other things as well.

Red button:

  • Single quick push takes a photo.
  • One second hold turns LED ring on or off.
  • Five second hold shuts down Pi.
  • If the Pi is off, press to startup.

Black buttons zoom in or out.

Keyboard:

  • Space: take a picture
  • f : flips the screen horizontally
  • - : zoom out
  • = : zoom in
  • q : quit
  • h : help
  • v : start video
  • t : start timelapse

If a USB drive is inserted, the picture/video will be saved in a folder based on the date, otherwise, it will be saved in the boot partition of the SD card.

All this can easily be modified in the "/boot/macroscope/macroscope.py" file if you have other needs or ideas. Please share them if you come up with something you find useful!

Share

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • First Time Author Contest 2018

    First Time Author Contest 2018
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

21 Comments

Awesome Instructable! Very good directionms.

Nice project and good instructable. I think you might need to add another pushbutton to the parts list. Three used on the PiFET but only two listed.

Good catch. Updated. Thanks!

Very nice project. I think the only thing missing now is an IR receiver, so you’ll be able to take pictures without the risk of shaking the camera when you push the button. But I guess since your Pi already has WiFi, this could also be implemented purely as a software based solution by using an app on your phone as remote.

What an excellently written and documented project. Very exemplary.

WHat material is the case made of - I know nothing about 3D printing and must give this away to an EU company that offers such service.

Well done indeed.

Hobby 3D printing is usually PLA or ABS plastic filament. Try https://www.3dhubs.com/ or check with your local maker space.

NICE INSTRUCTABLE....I'M NOT COMFORTABLE WITH WIRES AND CIRCUITS BUT I`LL TRY....WITH YOUR HELP....IF I HAVE ANY QUESTION MAY I ASK YOU?

That is why I publish Instructables. The questions that get asked help me understand how to write better instructions.

Cool project! Are you going to make the Python script available? Also, do you have any photos of it doing the thing?

The python in is the macropy.zip file on Step 17.

The only photos I have right now are in the Introduction Step, but I'm planning on doing a video of it in action soon.