Connecting a camera to the Pi

Testing the camera on the Raspberry Pi

Ok, so today I got my new nifty gadget.  A camera for the Pi!  So here’s the unboxing.

I got it in a neat paper bag like this one :

16832778_2225601784330794_64021547_o.jpg

This is what it looks like.

16880823_2225601770997462_1406325668_o.jpg

I opened the casing and connected it. It’s fairly easy.  Just pull up the handles, put it in, and push the handles back down.

16879954_2225601744330798_1761360833_o.jpg

Now to configure this.  In order to do this, just log on to the pi and start raspi config :

sudo raspi-config

locate the Interfacing options

Schermafbeelding 2017-02-20 om 19.30.54.png

Locate the camera option

Schermafbeelding 2017-02-20 om 19.31.12.png

Enable it

Schermafbeelding 2017-02-20 om 19.31.22.png

and reboot.

Schermafbeelding 2017-02-20 om 19.31.39.png

After the reboot sequence has finished, it’s time to test this.  There are actually 2 command line tools you can use to capture a still image and a video image.  The first one is called raspistill.  It’s got tons of options really.  You should really take a look at them.  But the easiest way to do a test is using this command :

raspistill -o me.jpg

Where the -o parameter sets the output filename.

Schermafbeelding 2017-02-20 om 19.37.04.png

So here it is :

Schermafbeelding 2017-02-20 om 19.38.53.png

The second one is raspivid

Here’s the syntax :

raspivid -o test.h264 -t 3000

in this command the .h264 file is the output. the -t parameter sets the number of seconds to record. It’s expressed in milliseconds, so 3000 means 3 seconds.

Schermafbeelding 2017-02-20 om 19.43.19.png

Good luck testing this!

Raspberry Pi sound output

How a Raspberry Pi is configured to switch between a 3.5mm Jack sound output to HDMI sound output.

So, up until now, I was using a headphone to listen to Alexa’s responses to my questions.  It was time to experiment with sound output. Check out my Amazon Voice Services setup procedure here.

I figured, the easiest way to get sound is through the HDMI interface to the screen.  The screen I’m using contains speakers, so no extra external speakers would be necessary.

There are 2 things you need to do to force the Raspberry Pi to relay the sound output to the HDMI interface.

Log on to the Pi using ssh and type

sudo raspi-config.

Navigate to the advanced options, and choose “Audio”.

Schermafbeelding 2017-01-12 om 18.38.35.png

Select the third option : “Force HDMI”.

Schermafbeelding 2017-01-12 om 18.39.01.png

Confirm, and get out of the interface.

Next, go to the root of the device by typing

cd /

navigate to the boot directory

cd boot

Edit the “config.txt” file.

sudo nano config.txt

Search for the “hdmi_drive=2” setting.  It will probably be commented out using a hash tag in front of it.  Just remove the hash tag.

Schermafbeelding 2017-01-12 om 18.51.49.png

Ctrl-x y enter to get out of the interface.

Reboot the Pi

sudo reboot

Time to do some testing.  If you also have a monitor, go ahead and test Alexa. In my case there was a problem.  The sound worked all right, but there was a lot of latency.  So much latency, the beeping sound Alexa makes when it indicates it has started listening couldn’t be heard.  The first two words (on average) of Alexa’s response were missing as well.

I decided to reverse the settings above (insert the hash tag, force the 3.5mm Jack) and I bought a 14 euro speaker set in the local grocery store.  It’s powered using USB and connects to the 3.5 mm Jack.  It appears to work perfectly.  The problem will probably be integrating them in the mirror.  They are the smalles speakers I sound find, but still wide enough to have a hard time integrating them.  But that’s a bridge I’ll be crossing later.

Enjoy!

Changing the physical screen resolution

How to change the physical screen resolution on the Raspberry Pi.

Next, I want the same effect on the physical screen.  First changing the resolution.  That’s easy.

Log on to the Pi using ssh.

type the following command :

sudo raspi-config

Locate number 7, “Advanced Options”

Schermafbeelding 2017-01-07 om 19.53.57.png

Choose “Memory Split”

Schermafbeelding 2017-01-07 om 19.54.18.png

Enter 128 as the new memory capacity of the GPU.  This way, a larger portion of the on-board memory of the Pi is reserved from showing things on the screen.  It’s important for larger resolutions.

Schermafbeelding 2017-01-07 om 19.54.31.png

Next, to change the resolution, choose “Resolution” and choose your preferred resolution.

Close the raspi-config utility and reboot by typing

sudo reboot

After the Pi reboots, it’s time to change the resolution.

Connect to the Pi using ssh.

Go to the root of the drive by typing

cd /

change to the boot directory by typing

cd boot

edit the “config.txt” file by typing

sudo nano config.txt

go to the bottom of the screen and type

display_rotate=1

to rotate the screen by 90°.

Ctrl-x and Y to save the file.

Reboot by typing

sudo reboot

Connect a physical screen and see the result.

Changing the VNC resolution

How to change the resolution of VNC when connecting to a Raspberry Pi

What I want to do next is the resolution with which the VNC connection is obtained.  Right now it’s a rather small resolution causing the mirror to be quite small, and some modules overlap.

What i’ll do is change the configuration file where the VNC server is started.

navigate to the hidden folder .config

cd .config

navigate to the autostart directory

cd autostart

open the file tightvnc.desktop

nano tightvnc.desktop

Go the line with the “Exec=” prefix and append the following to the command:

-geometry 800x1000 -depth 24

The final result looks like this :

Exec=vncserver :1 -geometry 800x1000 -depth 24

Ctrl-x and Y to save.

Notice how I set the width smaller than the height.  That’s because I want to rotate the mirror.  The final mirror will also be in portrait mode.

reboot using

sudo reboot.

That’s it.  Try connecting using VNC and enjoy the larger, rotated resolution.

Connecting to the Pi using the OSX Finder

Connecting to the Raspberry Pi using OSX integration functionality.

After some browsing around I found out there are 2 great ways to connect to the Pi just using the finder in OSX.

The first one is by connecting to the Pi via the network.  This is how you do it.

First connect to the Pi via ssh.

All you have to do is install this package :

sudo apt-get install netatalk

Once it’s finished, just go to the finder in OSX.

Under the network you should be seeing the raspberry Pi (excuse the dutch screenshot). There will be a button below the computer icon saying “connect as”.  Just click it and provide the default credentials of the Pi : pi / raspberry.

You can see your home directory and are able to drag files in and out.

Schermafbeelding 2017-01-06 om 23.12.19.png

The second is using the screen sharing functionality in OSX to connect to the Pi instead of VNC.

Just go to the finder and go to the “Go” menu, and “Connect to server”, or press command-k on the keyboard.  A screenshot like the one below appears (excuse the dutch).

Schermafbeelding 2017-01-06 om 23.15.46.png

Just type

vnc://<the ip address of your pi>:5901

and press connect.

And there you have it :

Schermafbeelding 2017-01-06 om 23.18.08.png

 

 

Getting wifi to work

Connecting to a wifi network on your Raspberry Pi.

One more thing before I disconnect the screen, network cable and mouse.  Getting the wifi to work.  That’s very important in order to get a good working mirror. We don’t want to have more cables hanging around than necessary.

It’s really easy.  In the graphical interface go to the top right corner, and click the wifi symbol.

Schermafbeelding 2017-01-06 om 21.21.42.png

Choose the network you like and authenticate.  Rasbian should remember the password by default.

I will now go ahead and disconnect the cable.  The result might be that your Pi gets a different IP address.  That’s normal.  Just look it up by typing

ping raspberrypi.local

Try and connect by using ssh and vnc.  That should work.  Shutdown the Pi by typing

sudo shutdown

It will take a while to shutdown safely.  After doing so, just take out all of the cables, and pull out the power cable, and put it back in.

 

Connecting to your Pi through VNC

Make a VNC connection to the Raspberry Pi.

The next thing I want to do is connect to the Raspberry Pi using VNC.  VNC is a remote desktop tool that lets you see the screen of a remote computer on your own screen.

Since the latest version of Raspbian it is included.  All you have to do is go the the Raspberry Pi Configuration under the Menu > Preferences option.  In the tab “Interfaces”, there should be a “VNC” option.  Make sure it is enabled.

If you’re unlucky, like me in this case, this option will be disable for some reason.  I’ve been googling this issue, but can’t seem to find a reasonable solution.

So instead, I will do it the hard way, and show you how.

The first thing to do is install a package called “tightvncserver”.  You can do that by connecting to the Pi via ssh and typing the command

sudo apt-get install tightvncserver

After installation, start the VNC server using the following command :

vncserver :1

Mind the “space” between the r and the 1.  It’s important.

You’ll be prompted to give a password.  The catch is: it’s only 8 characters.  So I chose “raspberr”.

Schermafbeelding 2017-01-06 om 20.58.37.png

You’ll have to reboot the Pi afterwards.

On my mac I downloaded VNC viewer for Raspberry Pi.  You can find it here.

Configure your connection like this :

The connection is made through the IP address followed by the :1 suffix.  Just like the suffix you started your vnc server with.

Schermafbeelding 2017-01-06 om 21.05.32.png

That should work like a charm!

Now to make sure that the VNC server is started every time the Pi boots.

That’s somewhat more difficult.

Connect to the Pi using ssh.  Change directory to the “.config” folder.

cd .config

Note that the name of the folder starts with a dot (.).  That means that it’s a hidden folder.  By default you won’t be able to see it using the “ls” command.  If it doesn’t already exist, create a directory called “autostart”, and go to it

mkdir autostart
cd autostart

Next we have to create a new file called “tightvnc.desktop”.  Do that by typing

nano tightvnc.desktop

Nano is a text editor.  By starting it this way, it will automatically create the file “tightvnc.desktop”.

Type in the following exactly :

[Desktop Entry]
Type=Application
Name=TightVNC
Exec=vncserver :1
StartupNotify=false

Get out of nano by typing ctrl-x and typing “y” and press enter to save.

That’s it. Reboot the py:

sudo reboot

After rebooting, try and connect again using VNC viewer.  That should work perfectly.