Microscope 1

April 18, 2022


Most of the time involved in building the microscope so far was invested in the setup and administration of the Raspberry Pi itself. The configurations used for SSH, VNC, and Samba may need to be adapted for the IT policies of another organization, and obstacles encountered regarding SSH and VLC could be made simpler or obviated entirely with additional hardware that we did not have for the initial setup.

Additionally, our Pi was connected to our network using its wired ethernet port. Some additional steps, not described here, will need to be performed if a Wi-fi connection is desired instead.

First, the Pi needed to be set up to operate in "headless" mode. The first step towards this was making sure that SSH was enabled, by selecting the appropriate option in the Raspberry Pi Imager software and setting an appropriate username and password. Once the OS image was installed on the Micro SD card, the Pi was booted up. We checked our networking hardware to confirm the IP address that the Pi was given, and connected to the Pi using SSH and its IP address.

Once connected to the Pi's shell, the command "sudo raspi-config" was entered to enable VNC so that a graphical terminal could be established. VNC was enabled under the Interfacing Options menu. An additional step is needed to connect to the Pi with VNC software other than RealVNC (such as TigerVNC or TightVNC) although this also reduces the security of the subsequent connection. The lines "Authentication=VncAuth" and "Encryption=AlwaysOff" were added to the file "/root/.vnc/config.d/vncserver-x11" using the nano text editor, and the shell command "vncpasswd -service" was used to set an (insecure) password.

Once the VNC server was configured on the Pi, a graphical terminal connection was made using TigerVNC (on Ubuntu 20.04) or TightVNC (on Windows 10) by connecting to the Pi's IP address determined above, and finally, the Pi could be controlled using its regular graphical user interface over its ethernet connection.

To facilitate transfer of files (particularly images) to and from the Pi, a Samba file share was established that could then be mapped as a network drive on the Windows 10 workstation on the same network. First, the samba packages were installed on the Pi using the shell command "sudo apt-get install samba samba-common-bin". Then, the config file at "/etc/samba/smb.conf" was edited using the nano text editor to contain the following:

[desktop]

path = /home/pi/Desktop
writeable=Yes
create mask=0777
directory mask=0777
public=yes

An unsecured share of the Desktop folder on the Pi was used for our convenience. Once the configuration file was set up, the Samba service was restarted on the Pi with the shell command "sudo systemctl restart smbd", and the network drive was established on the Windows 10 workstation as X: using the Command Prompt command "net use x: \\(Pi IP address)\Desktop".

The Raspberry Pi already has both Python and the libcamera library installed, so the only additional package needed was to control the LED hat. This was accomplished on the Pi by running the shell script "curl https://get.pimoroni.com/unicornhathd | bash" as described on the Pimoroni Github site.

With all of this infrastructure in place, the rest of the day was spent tinkering with the microscope construction, the libcamera libraries, the LED hat APIs, and the Python scripts to make all them work together.

The main script was developed through trial and error and, in short, turns on the LED hat at full brightness and then takes some number of photographs defined in the script, at intervals also defined in the script, and saves them as uncompressed BMP bitmap images in a sub-directory of the location that the script is run from.

Because the optics used must be focused manually, an additional script was written to allow the operator to “dial in” the optics. This script turns on the LED hat at full brightness and creates an image preview window on the Pi’s desktop, and keeps the window open and the LED hat on until the window is closed. When connected to the Pi over VNC, there is a delay between adjusting the focus and the the new image appearing on-screen, but this was only mildly annoying in practice and did not need to be done frequently besides.

A major issue encountered with the microscope’s actual image was that the light diffuser included with the LED hat was insufficient for creating a suitably diffuse bright field; individual LEDs were very visible in the final image. A piece of white packaging foam about ¼ of an inch thick was used instead, which worked relatively well except for the minor issue of the foam cells being faintly visible in the final image. This was further improved by the addition of a thinner plastic light diffuser.

Another issue encountered was the appearance of horizontal bars in the final image, possibly created by some frequency mis-match between the camera and the LEDs on the hat. This was compensated for by increasing the exposure time to 100ms in the current script, but there may be additional configuration options in the libcamera or LED hat settings that will work better.



Back