Friday 21 November 2014

Eyepiece - Part 4 - Building from a clean install.


This is the approach when using a Windows system - users of Linux and Mac will need to look for their own software.



NOTE:

There is an issue with automatic log-in when running XDM on Raspbian. The workaround is not to start the XDM service until after the system has logged on the primary user.





Preparing your Raspberry Pi.

After downloading the latest build of Raspbian (Debian Linux for Raspberry Pi), you will need to unzip the disk image and install it onto a SD card with a capacity of at least 4 GB. The download is about 1000MB (1GB) in size.



http://www.raspberrypi.org/downloads/
Raspberry Pi Downloads (O.S.Images)
http://www.7-zip.org/
For unzipping, I use 7zip, a free utility. 


http://sourceforge.net/projects/win32diskimager/To transfer the operating system image onto the bootable SD card, you will need Win 32 Disk Imager.

Once your image is transferred, insert the SD card into the socket on your Raspberry Pi and boot it up. You will need a monitor and keyboard attached just this once.

A screen will appear asking you to choose a number of setup options. Make sure that you change the Host Name to something distinctive so that you can find it in the next step.

Complete your set up and reboot you Pi.

http://www.advanced-ip-scanner.com/At this point, you will need to know the network address of your Raspberry Pi. I use a product called Advanced IP Scanner, though you may have another program that you prefer.

Run this program  (or something similar) for your local network, and make a note of the IP address of your Raspberry Pi. You will need this IP address for the next part.


Updating your Pi.

At this point, you will need to run PuTTY, a program that operates as a remote terminal to communicate with a Linux computer. You will also need to have an active Internet connection on your network.

http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY is also free software, and has more uses than just this.
http://www.chiark.greenend.org.uk/~sgtatham/putty/

When PuTTY starts, you will be presented with a window that asks for Host Name or IP Address. Enter the address you were supplied with by Advanced IP Scanner (above). Make sure that the option SSH is selected (just below where you entered the IP Address).

Click OPEN at the bottom of the window. Accept any warnings about identity and security, this is perfectly normal the first time you communicate with a new computer.

A new window will open and, after a few moments you will be invited to


Logon as:█

As this is a brand new install, the user name is Pi. Type this in and press enter.

You will be asked for a password. 

pi@192.168.1.39's password:█

Enter the password, the default being raspberry. Again, press enter.

You will be given a block of text disclaiming any liability for anything at all and you will be presented with a prompt:

pi@(none) ~ $

You are now able to do things with your Raspberry Pi ... things like getting the remote graphical interface working.

 Now, enter

sudo apt-get update

This command will take a couple of minutes to complete while it installs all of the updates to your new machine - some of the programs on the Pi are updated almost weekly.

Next, enter

sudo apt-get upgrade

You might as well go and make a coffee since this typically takes 10 to 15 minutes to complete.

Your operating system is now fully up to date.

enter

sudo shutdown -r now
This will restart the Raspberry pi.


Installing a Desktop Manager

Once your Pi is up and running again, log in using PuTTY and your previous credentials. Once you get to the system prompt, enter

sudo passwd root
You will then need to type in a password for the root user (super user, administrator, head honcho etc.) ...

... twice.

This is not normally recommended, but since we will be accessing the computer remotely, then this is necessary (at least for now).

Now, you need to enter
su -
Which command logs you in as the root user, who is allowed to do anything at all - including deleting the whole operating system. You have been warned.

Enter

apt-get install xdm
This installs the X Desktop Manager, which will give us remote access to the system's graphical interface. It will also run dpkg-reconfigure xdm.

When  asked to choose a default desktop manager, select XDM and then OK.

You now need to change the contents of two files. Be very careful. You may need to read the simple editor tutorial page (coming soon).

Enter

cd /etc/X11/xdm 
ed xdm-config
 this opens the file /etc/X11/xdm/xdm-config in the default editor.

You need to change the line that reads

DisplayManager.requestPort: 0
to read as
! DisplayManager.requestPort: 0
so enter
,p
You should see the entire file being listed on your screen.  The last line should be the relevant line. If so, then you may use the following script:

l
s/Display/!Display/
,p
The line should have been correctly edited. if so, then you may enter
w
q
 which saves the file and quits the editor.

Now enter


ed /etc/X11/xdm/Xaccess


 the line that reads

#*                       #any host can get a login window
needs to be changed to read
*                        #any host can get a login window
entering
,p
will list the file. The line you want is a little under half way down.

Enter

46
This should display the correct line. If not, you can advance lines by entering + or go back by entering - (minus).

once the correct line is reached, enter:


s/#//
w
q
This should have configured the machine to allow remote desktop access. Be warned that this is an insecure method and anyone on your network would be able to intercept your data.

Enter the following three commands to start the X Desktop Manager service, and to install some useful applications.
service xdm start
apt-get install x11-apps
apt-get install x11-xserver-utils
apt-get install xscreensaver
apt-get install midori
apt-get install python-picamera
apt-get install python3-picamera
apt-get install python-picamera-docs


x11-apps and midori (a web browser) will take a few minutes to install. python3-picamera and python3-picamera are most likely to be already installed. 

Now is the time to check that that XDM is running correctly:

netstat -ulnp | grep 177
This should return the following information:

udp        0      0 0.0.0.0:177         0.0.0.0:*                  2864/xdm
if  you see udp, :177 and xdm then everything is running properly.

Enter
service xdm stop
shutdown -r now
and wait for the system to reboot

Next: Accessing your Pi with Xming and configuring your system

Wednesday 19 November 2014

Eyepiece - Part 3 - Where , oh where has my remote drive gone?

After two days of struggling to get the Raspberry Pi to log in automagically, to set up user accounts, to set up remote desktop access, disabling the screen saver and to try to get the camera working (even though is seems to be dead), it was time to get the computer to mount some network shared directories into the local file system.

I can do this in Windows in my sleep.

Seemingly, others can do this in Linux, in their sleep.

I ended up cheating.

After a day of fiddling with the settings inside the operating system (which requires hunting for all manner of different text files to edit), I could manually mount those directories wherever I wanted, just not automatically at boot-up.

Now, in Linux, when you attach a network share to your system, it gets linked into an empty directory (folder) that exists in the file system.

The command is:
mount.cifs {where from} {where to} -o {options}
Which worked fine. You can also tell the operating system to attach some remote directory to the file system - but if it can't do it, the entries are deleted, although you can tell it to mount them 'later', when mounting them becomes this command:
mount -a
Much easier, and again it works, but not automatically.


After trying all of the dozen or so methods of getting those remote shares to mount without human intervention, I gave up and cheated.


I wrote a script (a DOS Batch file) that starts a remote console (text only) session, logs in and does the job, it then closes the session and terminates itself. I also did the same thing to restart and shut down the Pi.


Happily, this isn't an issue, since the machine will always be run from another computer, I will set it up so that the main computer performs those tasks routinely itself.


eyepiece.bat
"C:\Program Files (x86)\PuTTY\putty.exe" -load M55 -l root -pw passwd -m mount.sh

"C:\Program Files (x86)\Xming\Xming.exe" :1 -terminate -clipboard  -query 192.168.1.72
 And the mount.sh script
#!/bin/bash
mount -a
exit 0
Now, all I need to do is do the whole thing over again with a clean install of the latest version of Raspbian from the Raspberry Pi site.

For more information on the Raspberry Pi ...
http://www.raspberrypi.org/

Next: Building from a clean install.

Eyepiece - Part 2 - The initial hoops and hurdles.

Before anything else, it was necessary to set up the computer and to find out how the camera worked.

I actually bought the camera module a year ago, but hadn't managed to get around to trying it out.

I intend to do a clean install later, and will go through the full set up again, this time taking notes and screen-shots. The full set up will be published, eventually.

So ...
I set up the SBC (Single Board Computer) and started it up. Now, a long time ago, I got fed up with a monitor, keyboard and mouse attached to every computer I used, and so I discovered the joys of the Remote Desktop.

For Microsoft Windows, there is a program (creatively named Remote Desktop) that will access a Windows computer as though you were sat at the desk it is on. Remote desktop doesn't work for non-Windows computers, so I went to start my copy of Xming, which does the same job but with a Linux computer at the other end of the network. Well, that had disappeared last time I rebuilt my laptop, so I had to re-install. Xming is available for free.

http://www.straightrunning.com/XmingNotes/


Now, getting two computers talking together when they are running very different operating systems is a bit of a chore, and I needed to make some changes using the command line interface (you remember DOS, don't you - this is similar, but very different.) - for that I needed an old friend called PuTTY, another fine piece of free software designed specifically for that purpose.

PuTTY: A Free Telnet/SSH Client

A complicated hour or two later, including an update of the whole operating system via the Internet, and I had remote access to the Raspberry Pi desktop.

Now, I could install the driver software, in the form of Python libraries.

Python is a programming language with which I am only passing familiar, so I followed the instructions in the tutorials. I managed to capture an image or two (dog's nose, the wall, my right foot etc.) without ever seeing the preview.

Down in the notes there were words to the effect that the preview image is only displayed on the primary display hardware. This required a monitor with an HDMI interface, and a suitable cable.

Some plugging and rebooting later, and I had an excellent view of the cables in which the SBC nestled. A good picture that moved in real time (unlike a traditional web-cam or other networked camera). It even captures still images when told!

Then the LED on the camera came on (as normal) during a simple script test, and the program hung.

Reboot, unplug and re-connect. check everything and then check the website. It seems that the magic smoke that the camera runs on had escaped. [Insert appropriate imprecations and incantations here.] So, I need to order a new camera module.

Undeterred, I start work on the other bits of the set up, and notice that the primary display has gone blank. Cue a bit more cussing while I tried to discover how to disable the screen saver. That took a couple more downloads and a strange discovery - it is impossible to disable the screen saver on the log-in screen on Debian. You also have to install the screen saver software in order to disable it on a user profile.

The solution turned out to be a bit of editing in order to log in a dummy user when the computer starts up. It only took me 48 hrs to figure out how to do this reliably.

Thank goodness for Google and people willing to share their expertise!

After that it took a few minutes to share folders from the SBC to the network using SAMBA (which meant another package download and install).

Next: Adventures in accessing files across the network.

Tuesday 18 November 2014

Eyepiece - Part 1 - the start of a new project

Now that winter has arrived, I am able to find time to start work on some of my planned indoor projects.

I have decided that the first project that I am going to work on is a camera eyepiece for my venerable Vickers M55 microscope - partly to save my poor aching eyes, and partly in order to allow me to do some micro photography.


Lacking the resources for purchase of a specialist microscope camera, I am going to put together a camera using an Raspberry Pi with its dedicated camera module (5 Mega pixel live feed, computer initiated capture including video). Later, I intend to add in a home-built spectrometer, but that's for another time.

This project will neatly encapsulate three of my interests - computers, microscopy and electronics.

I have had the computer for a couple of years. For anyone who doesn't know, this is a tiny single-board computer that runs the Linux operating system (amongst others). In this case, it will be running Raspbian the Raspberry Pi's custom distribution of Debian Linux.

It is a bit larger than a credit card and has a custom camera module that can be attached. The model B boasts both USB ports and a network port  as well as a high definition video output. Instead of a disc drive, it accepts a wafer-thin SD memory card.

In order for this minimalist system to be useful for large-scale image capture, it will need to have access to  a computer network which will allow it to use another computer's disc-drive for image storage. It will also allow access to the computer without having to have a keyboard and mouse attached to the Pi. The monitor, however, stays, as it is where the camera will send its preview video stream to.

It will also require quite a bit of programming in order for it to do its job.

While I am a more than competent computer user with some experience of using Linux computers as file servers, I am not that used to delving into the heart of the operating system in order to change the way it works.

Thus comes the first set of hurdles.

Next: Testing and initial setup.