Category Archives: Uncategorized

VNC Experiences on Raspberry Pi

I wanted to share some experiences of getting VNC setup on my Raspberry Pi.

How hard could the experience be? A basic search on google and there are a ton of tutorials and examples to follow getting everything setup. Being a fan of adafruit I followed a detailed tutorial they had for setting up VNC which can be found here.

Initially it was working great till I noticed that I wasn’t accessing the current session. For most configurations I suspect this works fine but for my current project I want my VNC session to use the active session that I would see if I had a KVM (keyboard, video, mouse) plugged into my Pi.

Certainly I am not the first to notice or expect this. After trying different configurations and researching things further I discovered that the VNC tool used in all of the tutorials (tightvnc) doesn’t support access to the current session. Apparently in order to achieve this I would have to install and run X11VNC.

The following is the steps that I took to get everything setup:

Install X11VNC

Open a terminal session on your Raspberry Pi and run the following:

sudo apt-get update
sudo apt-get install X11VNC

When installing X11VNC it will want you to confirm the install so make sure to answer Yes to these questions. After it’s done installing you could run x11vnc but you’ll probably want it to work automatically after restarting your Pi.

Setting up X11VNC

In your terminal session you will want to setup a password that can be used when connecting. To set this up you will want to do the following:

x11vnc --storepasswd

When you are done x11vnc should report back that the password was written at /home/pi/.vnc/passwd. For some assurances I checked the file because I didn’t like the idea of password being stored in plain text.

Next you’ll want to set everything up so that x11vnc is running whenever your pi is started. In your terminal session change to the config directory.

cd /home/pi/.config

There should already be an autostart directory but go ahead and run a list to see everything that exists in the directory.


If you do not have an autostart directory then you will need to create one by using mkdir.

Go ahead and change to the autostart directory.

cd autostart

Next you’ll want to create an entry for x11vnc.

nano X11VNC.desktop

Add the following changes to the file:

[Desktop Entry]
Exec=x11vnc -forever -usepw -httpport 5900

To close hit Ctrl-X to keep the changes and exit. Next you will want to restart your Pi.

Testing X11VNC

Your configuration might be different than mine however I am running OS X and I can use the built in VNC viewer from Finder. By clicking on the desktop or if you already have a Finder window open you can do a Cmd-K to connect to a VNC Server.

You will want to enter the address of your Pi using the following format:

vnc://<IP Address>:<Port Number>

If you need to get the IP address of your Pi you can run ifconfig from a terminal session on it. Once you have entered the Server Address Click on Connect and you should be prompted to enter the password that you supplied.

You should now be connected.

Enjoy and as always Happy Coding!!!

Catching the Bug… Server Side Swift

In my opinion Swift is an extremely exciting and powerful language so like many others I was excited when I heard Apple’s decision to Open Source Swift and even more when a Linux compatible version of Swift was released. Writing apps for different platforms with Swift sounded exciting but what immediately started running through my mind was the ability to do server side development with Swift much like I have done with Javascript, Java and C#.

I started to review the different options available and I finally decided to take the next step of going from reading/dreaming about the possibilities to actually doing something. It turns out that I have the perfect opportunity as my website for DooScrib was taken offline and I would like to bring it back online (future updates to the plugin planned).

The following is the environment that I have chosen:

Server Side Frameworks

There are actually several choices out there and as time progressed I narrowed down the options that I was most interested in to the following:

Kitura is great and has a lot of information as well as the security of have a big name like IBM behind it. However as a personal preference I automatically gravitated towards Perfect and Vapor and have been watching both as they have progressed over the last few months.

To be honest I think both Perfect and Vapor are great choices. At a later time I might actually even pursue a separate review of Perfect.

Getting Started

So for those interested in following I plan to write several different posts over the next few weeks as I setup a Virtual Machine running Ubuntu, install and get Swift running and finally begin working with Vapor.

Keep following and as always Happy Coding.

Tracking User Touches with UIImageView

Whether you are having a user draw pictures or allowing the drag elements on the screen there are multiple purposes behind being able to track the location of a users touch in your app. I am going to document a quick example that I recently developed for an app that I have developed.

In this example I am documenting how to track a users touch location. Hopefully this example will give you something to build on for whatever you have in mind.

Create Project

Layout Screen Design

Start off with create a Single View Application:

Screen Shot 2015-05-04 at 10.45.09 PM

Screen Shot 2015-05-04 at 10.46.12 PM

Layout Screen

With the project setup complete click on the projects storyboard (Main.storyboard) and add a Image View to the view. You will want to stretch it out so that it uses the entire display is used as well as add Constraints so that control will be sized for whatever device used.

Screen Shot 2015-05-04 at 11.02.49 PM

With the view setup complete the next step is wiring the UIImageView control into a property for the ViewController.

With the storyboard editor still open click on the Assistant Editor so that both the storyboard and ViewController.h are displayed.

Screen Shot 2015-01-25 at 3.30.55 PM

Then control drag and create a property for the UIImageView:

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

After that is done you can close the Assistant Editor and you will now begin to work on the code that will track the user touches.

Tracking Touches

The rest of the work will be handled in the implementation of the ViewController so click on ViewController.m.

First change the interface to include some properties so that you can track the difference between a user moving their finger or just tapping the screen.

@interface ViewController () {
    bool isMoving;
    CGPoint lastTouchLocation;

Then in the viewDidLoad method make sure to initialize the isMoving property.

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
    isMoving = NO;

Touch Events

Now it’s time to add the methods that will called when the user has touched the screen, is moving their finger and when they have stopped touching the screen. For right now just add the following code and then later we’ll come back and fill them each with more code.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

For each of the methods we’re going to use the following common set of code that will get adjusted to better match each method:

// get one touch event from the NSSet that was passed.
UITouch *touch = [touches anyObject];
// from the touch event get the x,y coordinates via a CGPoint
CGPoint currentLocation = [touch locationInView:[self imageView]];

For both the touchesBegan and touchesMoved method we are going to want to record the location in the lastTouchLocation property. This will allow us to track not only where the users finger is on the screen but more importantly where it was previously. Also need to set the boolean variable isMoving so that in the touchesEnded method we can determine whether the user tapped the screen or dragged their finger.

Change both the methods to match the following:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint currentLocation = [touch locationInView:[self imageView]];

    isMoving = NO;
    lastTouchLocation = currentLocation;

    NSLog(@"user has started to touch screen %@.", NSStringFromCGPoint(lastTouchLocation));

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    isMoving = YES;
    UITouch *touch = [touches anyObject];
    CGPoint currentLocation = [touch locationInView:[self imageView]];

    NSLog(@"user is moving from %@ to %@", NSStringFromCGPoint(lastTouchLocation), NSStringFromCGPoint(currentLocation));
    lastTouchLocation = currentLocation;

Finally you will want to handle the touchesEnded method with the following code that will be able to determine whether the user just tapped the screen or actually dragged their finger across it.

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint currentLocation = [touch locationInView:[self imageView]];

    if (YES == isMoving) {
        NSLog(@"user finished moving from  %@ to %@.", NSStringFromCGPoint(lastTouchLocation), NSStringFromCGPoint(currentLocation));
    } else {
        NSLog(@"user just tapped the screen without moving at %@.", NSStringFromCGPoint(lastTouchLocation));

Go ahead and run the code in your debugger and as you tap or drag your finger across the screen you should see messages being logged in the debugger.

Screen Shot 2015-05-05 at 9.38.06 PM

As I mentioned earlier whether you are having a user draw pictures or allowing them to drag elements on the screen there are multiple uses to tracking the location of a users touch in your app.

For now you can find the source here and as always Happy Coding!!!