Skip to content

DNAPhone/WeLAB-4-makers

Repository files navigation

WeLAB-4-makers

The software that lets you use your We-LAB 4 makers kit is made of a Kivy GUI, a video streaming library (RPi-Cam_web-Interface - available at https://github.com/silvanmelchior/RPi_Cam_Web_Interface) and a Python server that lets the GUI manage the intensity of the microscope led. In addition, there is a PHP script that enables the GUI to save pictures of the microscope view.

Please note that the code is only working for Raspbian Jessie (you can download it here http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-09-28/). Also, the Kivy interface is written for Python 2.7, and is not optimized for version 3, e.g., the print function calls miss the round brackets. So if you want to use it using v. 3, you have to tweak a little the code.

To set your We-LAB 4 makers kit up, connect your Raspberry Pi to the internet, open the terminal and follow the next steps.

1 . If you have not done it before, expand the file system by running raspi-config command, and reboot.

pi@raspberrypi ~ $ sudo raspi-config
pi@raspberrypi ~ $ sudo reboot

2 . Update the firmware, reboot and enable the camera by running raspi-config command and choosing the Enable Camera option. Also, choose Advanced Options then Memory Split and insert 256 to increase the amount of memory available to the GPU.

pi@raspberrypi ~ $ sudo rpi-update
pi@raspberrypi ~ $ sudo reboot
pi@raspberrypi ~ $ sudo raspi-config

3 . To avoid the camera led interfere with the microscope led, disable the former by editing /boot/config.txt file

pi@raspberrypi ~ $ sudo nano /boot/config.txt

to add the following line at the end

disable_camera_led=1

4 . Clone the project folder from GitHub to the home directory (to go to the home, use command cd /home/pi):

pi@raspberrypi:~ $ git clone https://github.com/DNAPhone/WeLAB-4-makers.git

5 . Go to the downloaded folder

pi@raspberrypi:~ $ cd WeLAB-4-makers

Now, you can use our setup script as described in step 6a, or follow the instructions at step 6b. However, if you already have RPi_Cam_Web_Interface installed, follow the steps at point 6b, but skip the library installation. Please note that while the RPi-Cam-Web-Interface library gets installed, it will ask you to confirm a couple of times. Just hit ENTER (the first time it will start the installation process, the second will set the path to where images are saved). At the end, reboot the Raspberry Pi.

6a . (Alternative to step 6b) Change the setup script execution permission and run it. Please note that if you have already installed RPi_Cam_Web_Interface, you have to remove from the setup script the lines that install it: git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git, chmod u+x RPi_Cam_Web_Interface/RPi_Cam_Web_Interface_Installer.sh, RPi_Cam_Web_Interface/RPi_Cam_Web_Interface_Installer.sh install. Also, you have to write the correct RPi_Cam_Web_Interface install dir at line sudo mv php/getMediaSaved.php RPi_Cam_Web_Interface. During the installation process you will be asked to install RPi Cam Web Interface; just press ENTER. After a few instants, you will be asked to provide the default www-root location; just press ENTER again. Finally, you will be prompted to reboot, so do it.

pi@raspberrypi:WeLAB-4-makers $ chmod u+x setup.sh
pi@raspberrypi:WeLAB-4-makers $ sudo ./setup.sh

6b . Steps alternative to step 6a

6b.1 . Update everything

pi@raspberrypi ~ $ sudo apt-get update && sudo apt-get upgrade -y

6b.2 . Install required packages

pi@raspberrypi ~ $ sudo apt-get -y install python-dev python-pip

6b.3 . Install wiringpi to manage the microscope led

pi@raspberrypi ~ $ sudo pip install wiringpi

6b.4 . If you do not have RPi_Cam_Web_Interface, download it

pi@raspberrypi ~ $ git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git

6b.5 . Copy our php file that allows image management to RPi_Cam_Web_Interface folder

pi@raspberrypi ~ $ sudo mv php/getMediaSaved.php /var/www/html

6b.6 . Set the server that receives led management commands

pi@raspberrypi ~ $ sudo mv microscope_led_server/ /opt
pi@raspberrypi ~ $ sudo mv welab_4_makers /etc/init.d
pi@raspberrypi ~ $ sudo mv uconfig /var/www/html
pi@raspberrypi ~ $ chmod +x /etc/init.d/welab_4_makers
pi@raspberrypi ~ $ sudo systemctl enable welab_4_makers

6b.7 . Finally, install RPi_Cam_Web_Interface

pi@raspberrypi:RPi_Cam_Web_Interface ~ $ cd RPi_Cam_Web_Interface
pi@raspberrypi:RPi_Cam_Web_Interface ~ $ chmod u+x RPi_Cam_Web_Interface/RPi_Cam_Web_Interface_Installer.sh
pi@raspberrypi:RPi_Cam_Web_Interface ~ $ RPi_Cam_Web_Interface/RPi_Cam_Web_Interface_Installer.sh install

6b.8. Reboot

pi@raspberrypi:RPi_Cam_Web_Interface ~ $ sudo reboot

7 . Retrieve the ip address of your Raspberry Pi using ifconfig command. Search the output for the wlan interface and write somewhere the inet addr value (in the following ecample it is 192.168.1.2).

pi@raspberrypi:kivy_interface ~ $ ifconfig
...
wlan0 ...
      inet addr:192.168.1.2
...

8 . Now install Kivy on another computer in the network (instructions for your platform available at https://kivy.org/docs/installation/installation.html), copy kivy_interface folder on such a computer and run the GUI.

Mac users can run the following command:

pi@raspberrypi:kivy_interface ~ $ sudo kivy WeLAb.py

Also, we provide an executable archive in folder executable_Mac_OSX. Just double-click it to start the GUI.

Windows users instead have to run the following command:

> python WeLAb.py

If you have added Python to the PATH system variable you can just double-click WeLab.py file and the GUI should open automatically.

Retrieve the ip address of your Raspberry Pi and write it to the GUI's settings (3rd tab).

When you take pictures of the microscope view, the Raspberry stores the original ones in /var/www/html/media. You may want to periodically check for the space they are taking and remove the ones you do not need to backup. On your computer, such images are stored in the folder specified by the GUI's settings.

Kivy

Why Kivy? Because it is a powerful, open-source and cross-platform framework for the development of applications.

You can adapt and run the same code on all supported platforms.

You can use our GUI both remotely (via ethernet or wi-fi connection) or locally on a the same Raspberry Pi that operate the microscope camera.

Please refer to https://kivy.org/docs/installation/installation.html for detailed Kivy instruction for Linux, OSX and Windows operating systems.

Please refefer to https://kivy.org/docs/installation/installation-rpi.html for detailed Kivy instruction for Raspberry Pi.

In case of troubles running our interface directly on the Raspberry Pi, please follow the next tips (tested on a Raspberry Pi 3 running a fresh installation of Raspian Jessie with Pixel, Sept. 2016 version):

  • Recent Kivy versions require Cython version 0.23 or newer. Jessie is currently provided with version 0.21, so be aware that you may need to update the package.

Please check the current Cython version:

dpkg -s cython

If the version is older than 0.23, replace it:

sudo pip uninstall cython
sudo pip install -I Cython==0.23

We installed all required dependencies as suggested on the Kivy website:

sudo apt-get update 
sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev \
pkg-config libgl1-mesa-dev libgles2-mesa-dev python-setuptools libgstreamer1.0-dev \
git-core gstreamer1.0-plugins-{bad,base,good,ugly} gstreamer1.0-{omx,alsa} python-dev

Then we built Kivy:

git clone https://github.com/kivy/kivy 
cd kivy  
make 

echo "export PYTHONPATH=$(pwd):\$PYTHONPATH" >> ~/.profile 
source ~/.profile

As post-install settings, add some more external components:

sudo pip install pyglet docutils  
sudo pip install pygments 

Finally, in order to make the mouse visible you have to edit the Kivy configuration file. Such a file only appears after you have run Kivy at least once. So first run the GUI:

cd /home/pi/WeLAB-4-makers/kivy_interface
python WeLAb.py

Then press the ESC key and edit the configuration file

sudo nano ~/.kivy/config.ini

by adding the following line at the bottom, in the [modules] section:

touchring = show_cursor=true

To run the GUI, go to kivy_interface folder and run it as follows:

cd /home/pi/WeLAB-4-makers/kivy_interface
python WeLAb.py

Alternatively, you can try kivy pie, a compact and lightweight Raspbian-based distribution that comes with Kivy installed and ready to run (http://kivypie.mitako.eu).

Please be aware that Kivy under Raspbian should present some problems or limitations. Some interesting discussions are reported here:

Relevant issues we have experienced :

  • the GUI only works in fullscreen mode. This is not a real problem, but it should be annoying because we have not (YET!!!) added a gallery section to the GUI...

  • there’s the bubbling of mouse events. In order to overcome possible troubles we suggest to tip the option hide the taskbar when not used in taskbar raspbian settings.