Introduction: Raspberry Pi Zero HDMI / WiFi Soldering Microscope

Soldering SMD components can sometimes be a bit of a challenge, especially when it comes to things like 0.4mm pin pitch TQFP chips with 100 or more pins. In such cases, having access to some kind of magnification could be really helpful.

In an attempt to address this issue, I decided to build my own soldering microscope based on a Raspberry Pi Zero W and a camera module. The microscope is capable of streaming Full HD video directly to an HDMI monitor with practically no latency, which is perfect for soldering. But also over WiFi with a latency of less than half a second, which is pretty good for board inspection.

Optionally, with a bit of an extra cost the microscope can also be made portable, which combined with its WiFi video streaming capabilities opens up an extra dimension of potential use cases.

If you happen to have a 3D printer, make sure to also check out RichW36’s amazing project on Thingiverse for a version of the microscope using 3D printed parts!

Step 1: Tools and Parts

To build the microscope you are going to need the following parts:

1 x Raspberry Pi Zero W[10€]

1 x Raspberry Pi Camera Module[8€] - You will need to hack it in order to change its focal length and make it possible to focus on objects very close to it. I don’t know if the same procedure is also possible with the new 8MP camera module, so I’d recommend getting the original 5MP one instead.

1 x Raspberry Pi Zero Camera Cable[2€] - As you may already know, the Raspberry Pi Zero has a smaller camera connector than the other Raspberry Pi boards, so you will also need a special adapter cable to connect the camera module to it.

1 x Plastic Caliper Micrometer - The cheaper you can find the better, I just used an old plastic analog one that I had lying around.

1 x Piece of Ruler - The ruler width has to be smaller than the length of the moving jaw of the caliper. As for the length, around 10cm to 15cm should be fine.

1x Aluminum Project Box[4€] - This is going to be used as the base of the assembly and it needs to be made out of metal, so it will also be heat resistant. The reason a box is needed is so you can put a weight inside it, in order to be more stable during soldering.

1 x HDMI Cable and a Female HDMI to Male Mini HDMI Adapter - You can also purchase HDMI to Mini HDMI cables if you want, but I already had a regular HDMI cable lying around.

1 x Micro USB Power Supply - According to my measurements, the current drawn by the Pi never exceeds 400mA even while streaming 1080p video over WiFi and HDMI the same time. So, even a 500mA power supply should be sufficient. Just to be safe though I recommend though getting an 1A one, especially if you plan to build the portable version which is also going to have losses on the boost converter.

1 x MicroSD Card[5€] - Even a 4GB one is going to be enough, just make sure that it is a high quality Class 10.

4 x M2 Screws and Nuts[less than 1€] - Screws of larger diameter could also be used. Though, the bigger the screw the wider needs to be the hole, and the grater the risk of the plastic breaking.

1 x Hot Glue Stick[1€]

Cable Zip Ties[less than 1€] - Those are going to be used to attach the Pi on the moving part of the caliper.

And the following tools:

A Hot Glue Gun

A Dremel - With a disk that can cut through plastic, plus drill bits for plastic and aluminum at the size of the screws.

A Long Flat Nose Pliers

A Bolt Cutting Pliers - You will need a way of cutting the screws on the appropriate length. A pair of bolt cutting pliers is what I used, though I’m sure there are other tools that can do the job as well.

Philips Screwdriver

Optionally, if you want to make it portable, you will need the following additional parts:

1 x LiPo Battery[8€] - The capacity of which is going to depend on the battery life you want, the efficiency of the boost converter and the average power consumption.

1 x LiPo Battery Charger / 5V Boost Converter[20€] - For this project I choose the PowerBoost 1000C from Adafruit. Much cheaper alternatives are also available on eBay, though I decided to go with that particular one because of a nice feature it had, which I’m going to talk more about later on.

1 x 40-Pin Dual Row Male Pin Header[less than 1€]

1 x 40-Pin Dual Row Female Pin Header[less than 1€]

1 x 8-Pin Male Pin Header[less than 1€]

1 x 8-Pin Female Pin Header[less than 1€]

1 x Piece of Prototyping Board[1€] - Because you'll have to solder pin headers on both sides of the board, I recommend getting a double sided one. Alternatively, you can get a prototyping board specifically designed for the Pi Zero, such as this from MakerSpot.

1 x 1K Resistors[less than 1€]

1 x 10K Resistor[less than 1€]

1 x BC547[less than 1€] - Any general purpose NPN transistor will do, this is just what I used.

1 x DPST Momentary Switch[1€] - Ideally, you want a DPST switch, so you can turn on and off the Pi using the same push button. Unfortunately, I didn’t have one around, so I had to use two separate SPST momentary switches instead.

Cable Zip Ties[less than 1€] - One more is needed for the portable version, for attaching the battery on the back side of the prototyping board.

Solder Wire

And the following additional tools:

A Soldering Iron

A Pair of Wire Cutters

The total cost for the non-portable version, excluding the power supply, the HDMI cable and the adapter to mini HDMI, was around 30€. And the additional cost for making it portable was also around 30€. The majority of the parts were purchased on eBay.

Step 2: Preparing the MicroSD

Burning the image to the microSD card

As a base for the system I decided go with the official Raspbian Lite image and install then only exactly what I needed. To get started, first download the latest Raspbian Lite image from the raspberrypi.org website, and burn it to your microSD card.

If you are running Linux, after unzipping it you can burn it by running the following command as root,

dd if=/path/to/<yyyy-mm-dd>-raspbian-jessie-lite.img of=/dev/sdX bs=4M

Where X is the letter of the device that corresponds to your microSD e.g. c. Before running the command make sure that there are no mounted partitions that belong to the microSD card. In case there are use the following command to unmount each one of them,

umount /dev/sdXY

But be extremely carefully here, using the wrong letter in place of X may do irreversible damage to your system and ruin your day. Before running the dd command double check that the letter you typed in place of X is really the one that corresponds to the microSD device.

If you are using Windows, after downloading the Raspbian Lite image and unzipping it, you can use the Win32DiskImager to burn it on the microSD card. More information can be found on the official Raspberry Pi documentation.

On MacOS there is a graphical application called Etcher available, which can be used to burn the image on the microSD card. Alternatively, you can also use dd similarly to Linux, but the process is a bit different. Again, you can check the official documentation for more information.

Configuring the WiFi

After burning the image to the microSD card you will need to configure the WiFi before the first boot and also enable SSH.

First thing you need to do, is to create an empty file named SSH inside the boot partition of the microSD card. If you are on Windows, the boot partition will most likely be the only partition you would be able to see, as Windows can’t natively read or write ext4 partitions. If the microSD card partitions are not currently mounted, just unplug and replug the card to your computer.

Then, again inside the boot partition, create a file named wpa_supplicant.conf with your wireless settings. The contents of the file should look similar to this,

country=<COUNTRY_CODE>
network={
ssid=<SSID>
psk=<PASSWORD>
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}

proto can either be RSN for WPA2, or WPA for WPA1.
key_mgmt
can either be WPA-PSK, or WPA-EAP for enterprise networks.
pairwise
can either be CCMP for WPA2, or TKIP for WPA1.
auth_alg
will likely be OPEN, while LEAP and SHARED are the other options.
As for country, ssid and psk, those should be pretty much self explanatory.

That’s it, now just unmount the microSD card from your computer and put it to your Pi. Next, plug your Pi to an HDMI monitor, plug the camera module using the special ribbon cable and finally put the power. After a few seconds your Pi should have booted up and automatically connected to your WiFi network. On the screen, you should be also able to see the IP address that it got from the DHCP server of your router.

Step 3: Establishing an SSH Connection

In case you haven’t connected a monitor to your Pi yet and you can't see what IP address it got, there are several ways to discover it. One way is by checking the logs of the DHCP server of your router. Every router is different, so I'm not going to describe that process.

On Linux another easy way is by running the following nmap command as root,

nmap -sn x.x.x.x/y

Where x.x.x.x is the IP address of your private network e.g. 192.168.1.0 and the y is the number of ones (in binary) of the network mask e.g. for the network mask 255.255.255.0 the number of ones is 24. So, for that particular network you would run,

nmap -sn 192.168.1.0/24

An example output for this command is the following,

Starting Nmap 6.47 ( http://nmap.org ) at 2017-04-16 12:34 EEST
Nmap scan report for 192.168.1.1
Host is up (0.00044s latency).
MAC Address: 12:95:B9:47:25:4B (Intracom S.A.)
Nmap scan report for 192.168.1.2
Host is up (0.0076s latency).
MAC Address: 1D:B8:77:A2:58:1F (HTC)
Nmap scan report for 192.168.1.4
Host is up (0.00067s latency).
MAC Address: 88:27:F9:43:11:EF (Raspberry Pi Foundation)
Nmap scan report for 192.168.1.180
Host is up.
Nmap done: 256 IP addresses (4 hosts up) scanned in 2.13 seconds

As you can see in my case the Pi has the IP address 192.168.1.4.

If you are on Windows, there is also a version of nmap available that you can try, for which you can find more information here. After obtaining the IP address of the Pi you can SSH to it using the following command on Linux as well as MacOS,

ssh pi@<IP-OF-YOUR-PI>

Or on Windows by using PuTTY.

The default password for the pi user is raspberry.

Step 4: Configuring the System

General configuration

On the first boot the system is almost completely unconfigured so there are some tasks you will need to do first.

The very first thing you need to do, is to change the default password for the pi user,

passwd

Then, you will have to configure the locales. You can do this by running the following command,

sudo dpkg-reconfigure locales

Go ahead and select all the en_US locales by using the space bar plus any other locales you want. When you are done hit Enter. Lastly, select the en_US.UTF-8 as the default locale and hit Enter.

Next you will need to configure the timezone,

sudo dpkg-reconfigure tzdata

At this point it's probably a good idea to update the system,

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

Next, you need to enable the camera module by using the raspi-config command,

sudo raspi-config

Select the Interfacing Options from the menu and then select the Camera option. Answer yes to the question asking you to enable the camera and then select OK. Finally, select finish and answer yes to the question about if you want to restart the Raspberry Pi now. After the reboot, reconnect to your Pi through SSH the same way as before.

To test that the camera is working properly you can run the following command,

raspivid -t 0

You should be able to see the video feed on your HDMI monitor, you can stop it any time you want by pressing Ctrl-C. You can also use the -vf and -hf flags to flip the image vertically and/or horizontally if you need.

Setting a static IP address

Next thing you need to do, is to set a static IP address for your Pi. To do so using nano edit your /etc/dhcpcd.conf,

sudo nano /etc/dhcpcd.conf

and add the following lines at the end,

interface wlan0
static ip_address=<IP-OF-THE-PI>
static routers=<IP-OF-YOUR-ROUTER>
static domain_name_servers=<IP-OF-YOUR-ROUTER>

On the domain_name_servers setting you can add multiple nameservers divided by spaces if you want, e.g. you could also add the IP of the Google DNS which is 8.8.8.8 to be used as a backup server. Hit Ctrl-X to exit, type y and finally hit Enter to save the changes.

Then restart the dhcpcd and networking services by running the following two commands,

sudo systemctl restart dhcpcd.service
sudo systemctl restart networking.service

At this point the SSH session should hang. Don’t worry though that’s to be expected since you just changed the IP of the Pi, just reconnect to it via SSH but this time using the IP you assigned.

Step 5: Installing GStreamer

There are several ways to stream video from a Raspberry Pi over the network, but the one that provides the least amount of latency is by using GStreamer. To install GStreamer you can simply run the following commands,

sudo apt-get update
sudo apt-get install gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-bad

GStreamer has quite a few dependencies so this is going to take a while. After the installation is done, you can stream the video feed of the camera over the network and HDMI the same time, using the following command,

raspivid -t 0 -w 1920 -h 1080 -fps 30 -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=<IP-OF-YOUR-PI> port=5000

This is going to create an RTP stream on port 5000 which can be received by any machine on your local network by using GStreamer,

gst-launch-1.0 -v tcpclientsrc host=<IP-OF-YOUR-PI> port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false

Installing GStreamer on any machine running a Debian based Linux distro is done exactly the same way as on the Pi. Most major non-Debian based distros should also have GStreamer in their repositories.

GStreamer is also available on Windows and MacOS, detailed information on how to install it can be found here and here.

Step 6: Configure Streaming to Automatically Start on Boot

Of course using the previous command you can start the streaming any time you want, though that requires connecting first to the Pi via SSH which isn’t very convenient. What you want to do instead is to create a script which will run automatically on boot as a service and start the streaming.

So, to do this first create a file using nano,

sudo nano /usr/local/bin/network-streaming.sh

and inside paste the following two lines,

#!/bin/bash
raspivid -t 0 -w 1920 -h 1080 -fps 30 -vf -hf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=<IP-OF-YOUR-PI> port=5000

The -vf and -hf flags are being used to flip the image vertically and horizontally. Depending the orientation of the camera after you install it, you may or may not need them.

Hit Ctrl-X to exit, type y and finally hit Enter to save the changes. Then make the script executable by running,

sudo chmod +x /usr/local/bin/network-streaming.sh

Next you need to create a systemd service file,

sudo nano /etc/systemd/system/network-streaming.service

And paste inside the following lines,

[Unit]
Description=Network Video Streaming
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/network-streaming.sh
StandardOutput=journal+console
User=pi
Restart=on-failure

[Install]
WantedBy=multi-user.target

Save the file and exit nano, and run the following command to test your service,

sudo systemctl start network-streaming.service

If everything works as expected, you can then run the following command to make the service automatically start on boot,

sudo systemctl enable network-streaming.service

Step 7: Making the File System Read-Only

One of the big problems of SD cards and flash storage in general is that they are very prone to corruption.

The best way to combat this, is by mounting all the partitions of the microSD card as read-only. This will also allow you to unplug the power from the Pi any time you want without having to initiate a proper shutdown, which is very useful especially for such an application.

First thing you need to do, is remove some packages by running the following command,

sudo apt-get purge triggerhappy logrotate dphys-swapfile

Next, you need to replace rsyslog with the syslogd daemon of busybox which will allow as to keep the system logs on memory,

sudo apt-get install busybox-syslogd
sudo apt-get purge rsyslog

and run,

sudo apt-get autoremove

to remove any packages that are no longer needed.

After that, you will be able to view the system logs at any time using the logread command.

Next, you need to move /etc/resolv.conf to /tmp, which is going to be mounted on memory, because it needs to remain writable.

sudo rm /etc/resolv.conf
sudo touch /tmp/resolv.conf
sudo ln -s /tmp/resolv.conf /etc/resolv.conf

Another file that needs to be writable is /var/lib/systemd/random-seed, so similarly,

sudo rm /var/lib/systemd/random-seed
sudo touch /tmp/random-seed
sudo chmod 600 /tmp/random-seed
sudo ln -s /tmp/random-seed /var/lib/systemd/random-seed

Because the random-seed file is not normally created on boot and the contents of /tmp are volatile, you will need to change that by modifying the service file of the systemd-random-seed service file. So, by using nano,

sudo nano /lib/systemd/system/systemd-random-seed.service

and just add the line at the end of the service section,

ExecStartPre=/bin/echo "" > /tmp/random-seed

so it will look like this,

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/lib/systemd/systemd-random-seed load
ExecStop=/lib/systemd/systemd-random-seed save
ExecStartPre=/bin/echo "" > /tmp/random-seed

and run,

sudo systemctl daemon-reload

to reload your systemd service files.

Next you’ll need to edit the /etc/fstab file,

sudo nano /etc/fstab

And add the ro option on /dev/mmcblk0p1 and /dev/mmcblk0p2 partitions in order for them to be mounted as read-only on boot. And, add a few more lines so /tmp, /var/log and /var/tmp will be mounted on memory. After making those changes your /etc/fstab file should look similar to this,

proc            /proc   proc    defaults                0       0
/dev/mmcblk0p1  /boot   vfat    defaults,ro             0       2
/dev/mmcblk0p2  /       ext4    defaults,noatime,ro     0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

tmpfs   /tmp            tmpfs   nosuid,nodev    0       0
tmpfs   /var/log        tmpfs   nosuid,nodev    0       0
tmpfs   /var/tmp        tmpfs   nosuid,nodev    0       0

Finally, edit your cmdline.txt,

sudo nano /boot/cmdline.txt

and at the end of the line add the options fastboot noswap ro in order to disable the filesystem check, disable the swap and force the filesystem to be mounted as read-only. After that your /boot/cmdline.txt should look similar to this,

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait fastboot noswap ro

Finally, reboot the system for the changes to take effect. After the reboot if everything went as expected running,

sudo touch /boot/test
sudo touch /test

should give you in both cases a "Read-only file system" error. Now you can unplug the power from your Pi any time you want without risking the filesystem on the microSD card to become corrupted.

If you need for some reason to make the root filesystem temporally read-write, e.g. for installing some packages, you can do so by using the following command,

sudo mount -o remount,rw /

And after you are done, run the following command to make it read-only again,

sudo mount -o remount,ro /

In case you want to do updates, make sure to mount both /boot and / as read-write, because updates for the kernel and the firmware also write the /boot partition.

At this point we are done with the software part, so I highly recommend shutting down your Pi, remove the microSD and take an image backup of the microSD card.

Step 8: Hacking the Camera Module

For the camera module to be able to focus on objects at very close proximity and provide you with magnification, you’ll need hack it in order to modify its focal length.

The lens that is attached on top of the sensor is actually screwed in place, and secured with a very small amount of glue. Using a pair of long flat nose pliers gently turn the lens back and forth in order to crack the glue bond, and then very carefully completely unscrew the lens.

After that, put the lens back on the module and screw it just a little bit so it won’t fall off when you turn the board upside down. Next, attach your Pi to your monitor if you haven’t already, plug the power and look at the video stream.

What you'll need to do is to adjust how much the lens is screwed on the base, in order to make the camera being able to focus on objects around 10cm from the lens. Try not to go much lower than that, because you need to have a relatively good working distance to be able to solder under it. Don’t worry too much about making it perfect, you can always do fine adjustments after you are done with the microscope assembly.

Step 9: Assembling the Microscope

Now it’s time for the fun part, which is not other than assembling the microscope.

First, you will need to make two holes the diameter of the screws on the upper jaw of the caliper and two on one side of the aluminum case in order to mount it.

Next, you will need to open a slot of the appropriate size to fit the ruler piece. Take your time with this one, because if you go too fast you might break the plastic or make the hole too big. After you are done, insert the ruler to make sure that it fits inside nicely.

Now you need to make a couple of holes on the edge for the ruler in order to mount the camera module. When you are done, screw the camera module in place and cut the remaining part of the screws.

After that, mount the caliper to the side of the aluminum case with screws, pass the ruler with the camera module attached to it through the hole, and fix it in place with hot glue. Make sure to add hot glue on both sides and from both the top and the bottom.

Finally, attach the Raspberry Pi board on the moving part of the caliper using zip ties like you can see on the picture and connect the camera cable.

And that was it, you can now easily adjust the focus of the camera by moving the caliper up and down and if you want to also fine tune the focal length of the lens, in order to achieve the optimal working distance for you.

If you also want to learn how you can make it portable, you can proceed on the next step.

Step 10: Making It Portable: Software

The PowerBoost 1000C has a very handy little feature. It has an enable pin which when pulled high activates the boost converter and starts providing power on its output, and while is being pulled low the power is being cut off.

The Raspberry Pi also has a nice feature, which allow us to configure a GPIO pin as an output that will be at a high state while the Pi is on and at a low state after a successful shutdown. By combining those two features, it’s possible to create a software on/off switch for the microscope.

Let’s start from the software part, the first thing you need to do is to enable this feature of the Pi and make it output a logic high on one GPIO pin from the moment it starts booting, and a logic low after a successful shutdown.

Doing that is really simple, all you need to do is edit your /etc/config.txt file,

sudo mount -o remount,rw /boot
sudo nano /boot/config.txt

and add the following line at its end,

dtoverlay=gpio-poweroff,gpiopin=26,active_low

Now, if you reboot your Raspberry and measure the voltage at the GPIO26 pin (pin 37 on the GPIO header) with respect to ground, you should see 3.3V from the moment the Pi starts to boot. And after doing a complete shutdown that should become 0V.

Now that this is done, you need to write a simple script that will monitor the status a second GPIO pin and when it becomes low trigger a shutdown. For this purpose you are going to need to install the wiringpi package, which comes together with the gpio command.

sudo mount -o remount,rw /
sudo apt-get update
sudo apt-get install wiringpi

Now using nano create the script,

sudo nano /usr/local/sbin/power-button.sh

and paste inside the following lines,

#!/bin/bash
while true
do
    if (( $(gpio read 24) == 0 ))
    then
        systemctl poweroff
    fi
    sleep 1
done

and after saving and exit also make it executable,

sudo chmod +x /usr/local/sbin/power-button.sh

It's important to mention that the pin 24 of the wiringpi corresponds to the GPIO19 pin, which is the pin 35 on the GPIO header. If that sounds confusing, you can take a look at the Raspberry Pi pinout on the pinout.xyz website and the web page about pins on wiringpi.com. Running the command gpio readall, can also be helpful for determining which pin is which.

Next, you need to create a systemd service file,

sudo nano /etc/systemd/system/power-button.service

with the following contents,

[Unit]
Description=Power Button Monitoring
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/sbin/power-button.sh
StandardOutput=journal+console
Restart=on-failure

[Install]
WantedBy=multi-user.target

Finally, to start the service and make it run on boot run,

sudo systemctl start power-button.service
sudo systemctl enable power-button.service

and mount again the filesystem as read-only with,

sudo mount -o remount,ro /

Step 11: Making It Portable: Hardware

Now it’s time for the hardware part. First, you need to build a very simple circuit that consists of an NPN transistor, two resistors and a DPST momentary switch. You can look at the picture of the circuit diagram for more details.

You will also need to solder a male pin header on the GPIO of the Raspberry Pi and also a female one on the PowerBoost, so you can easily attach that and the Pi on the board that you are going to build. Your board essentially, is going to be attached on top of the Pi Zero like a HAT, and the PowerBoost on top of the board. The Pi is also going to be powered directly from the GPIO header using the +5V pin of the PowerBoost.

After you are done with soldering, it’s time to put everything together. First, mount the Pi on the moving part of the caliper using zip ties. Then mount the battery on the back of the board you’ve built again with a zip tie and attach it on the Pi, be careful not to make it too tight or you might damage the battery. Attach the PowerBoost board on top of it and plug the battery to the connector. Last but not least, plug the camera cable and connect the Pi to the camera module, and of course don’t forget to plug the microSD.

And we are finally done! If you now press the power button and keep pressing it for about 8 seconds, the boot process of the Pi should start and after releasing it, it should continue going. Unfortunately, the Pi doesn't immediately start to output the logic high on GPIO26, so if you stop pressing the button too soon the power will be cut off.

After the boot process is complete, pressing the power button once again for about a second, should cause the Pi to shut down and the power to be cut off.

Step 12: Ideas for Improvement

Getting rid of unwanted light sources

This shouldn’t matter much if you plan to use the microscope just for soldering and board inspection, but if you also wanted to take some pictures with it, you might find an annoying red spot appearing in your photos. That is caused by the LED of the camera module which is always on while the camera is working.

If you want to turn it off fortunately it’s quite simple to do. After making the /boot partition writable,

sudo mount -o remount,rw /boot

edit your /boot/config.txt using nano,

sudo nano /boot/config.txt

and add the following line at the end,

disable_camera_led=1

Doing this should cause the camera LED to remain off, after rebooting the system.

Now if you made the portable version, the PowerBoost 1000C unfortunately has a ridiculously bright blue LED to indicate that the power is turned on. That apart from ruining the exposure of your images, you might also find it to be extremely annoying to your eyes while soldering, just because of how bright it is.

For that reason, you may want to consider removing the power LED or the resistor that is in series with it completely from the board. Alternatively, you may want to replace instead the 1K resistor that is in series with it with a larger one, so the LED will become dimmer.

Adjustable Magnification

Instead of getting a regular Raspberry Pi camera module and hacking it to change its focal length, if you don’t mind sparing a few extra money you could also get a camera module with an adjustable focal length, for a bit over than 20€ from eBay.

Such a camera module will allow you to easily adjust the level of magnification, because as you move the camera lower all you have to do is unscrew the lens a bit in order to focus. This will also allow you to easily achieve quite big levels of magnification. Keep in mind though that after a point, the depth of field is going to become so swallow that will make the microscope almost unusable as you can also see in the attach image.

So to summarize, if you can afford it I highly recommend getting one of these camera modules instead, as it is going to give you an incredible amount of flexibility.

Comments

author
RichW36 made it! (author)2017-06-17

I made it unadjustable for height due to my large hands. But I did add the 8mp camera with the adjustable focus. I didn't add all the code to make it boot right to the camera . I just takes a minute to log in a tell it what to do. I did 3d print all the pieces to construct it. I will be uploading all of it to thingiverse for all to enjoy. Thanks for the great idea and taking the time to show me how!

20170618_005622.jpg20170618_005616.jpg
author
magkopian (author)RichW362017-06-18

That looks amazing! Please let me know when you upload the files, I'd really like to give a mention to your project on my intructable.

author
RichW36 (author)magkopian2017-06-19

He is the link. https://www.thingiverse.com/thing:2391660

author
magkopian (author)RichW362017-06-21

Thanks for the link, I added a mention to your project after the project overview.

author
RichW36 (author)magkopian2017-06-22

Thanks!

author
andrei101 made it! (author)2017-05-22

My hot glue monster. Sick!. For anyone wondering, it also works well with a pi zero and a cheapo wifi dongle

2017-05-22 23.50.20.jpg
author
magkopian (author)andrei1012017-05-22

Are you using hot glue as a light diffuser for the LEDs? Never thought of that actually, keeping it in the back of my head for future projects. Thanks for sharing!

author
andrei101 (author)magkopian2017-06-06

Yeah, and it works very well but you need a lot of it to avoid big white spots. Oh and its holds everything together...

But thanks for the design, I use it almost daily! so much so that I'm gonna invest in some better optics.

author
bill2009 (author)2017-04-26

This is great. I'm actually working on attaching a Pi to my telescope but this covers all the ground I need. Thanks very much.

author
rossak (author)2017-04-26

Hey, it's an awesome tutorial, thanks for a great job. I wanted to make it but the cheapest Raspberry Pi Zero W I've found, even in China costs about 25€. Could you please provide a link to the one that costs 10€? Thanks.

author
magkopian (author)rossak2017-04-26

I got mine from The Pi Hut, they sell it for £9.60 which is about 11.30€ so a bit over than 10€ but still pretty close. They also offer pretty low cost shipping for destinations within the EU. As for the camera module and the camera cable, those can be found on eBay for as low as 6€ and 2€ respectively.

author
rossak (author)magkopian2017-04-26

Thanks a lot. I don't know how it is possible that they sell more than twice cheaper than China. And BTW I use GBP as well.

Last question as I'm not familiar with Pi at all, how do you capture video or stills, does Pi handle that or through an external capture device?

Honestly I've never seen such a good quality images even from a lot more expensive chinese microscopes or webcams. This is why you got my attention here. Only thing I would improve is lightning.

author
magkopian (author)rossak2017-04-26

For capturing images you can use the following command,

raspistill -o /path/to/image.jpg

and this for video,

raspivid -o /path/to/image.jpg

With both commands, you can use the -vf and -hf flags to flip the picture horizontally or vertically if needed.

If you have a fully working microscope by following all the instructions I wrote about the software, you will need to stop the network-streaming service before using those commands, as you can't have two different processes accessing the camera the same time.

Also, since the filesystem will be read-only, you will have to connect an external USB storage media to store the footage. Alternatively, if you just want to take a few pictures you can save them on /tmp until you download them to your computer, which will be mounted on RAM.

While capturing video using the raspivid command the HDMI streaming will also remain active, so you can still use it as a microscope while recording.

author
rossak (author)magkopian2017-04-26

Thanks again, that's clear now. I won't be using network streaming anyway, just a HDMI. I will also try to modify it to send the 5V over HDMI cable.

author
jrlandau (author)2017-04-25

What magnification does this setup get, approximately?

author
rossak (author)jrlandau2017-04-26

Just use a ruler and measure it if that number is important to you.

author
magkopian (author)jrlandau2017-04-25

There is no way to answer such a question, because there is no reference to measure the amount of magnification against. How much bigger everything will look to you, will depend on the physical size and the resolution of the monitor you're using, as well as your adjustment of the focal length of the lens.

I personally used a 22'' monitor with a 1920x1080 resolution, so if you watch the video I've taken in such a monitor, you can see exactly how everything looked to me.