Posts Tagged ‘ vnc

Refresh your Pi

It seems like I use my Raspberry Pi just often enough to forget everything about how I set it up the previous time.  Unlike an Arduino, it’s possible all sorts of new configuration \ updating will need to take place if it’s sat for a few months.  This post will serve mainly a notepad to myself on what I need to do to get it up and running again, and info on how to do fresh installs.

I’m sure this all can vary widely from user to user and Pi to Pi.

Great Linux/Unix command-line cheat-sheet: Web Site, PDF.

First Time Setup Guides

Just in case you do need to do everything from scratch:

The overall gist is:

  • Format SD
  • Download Linux distro and install on card
    • Most recently, I used Pi Filler (looks like Mac only)  : It does both the format and install.
    • Look here for other solutions.
  • Once the pi is up and running, via the settings menu:  (run > raspi-config to get there from the commandline)
    • Expand the root partition:  This is only needed for older distro installs.  If you’re using NOOBS, it should be auto-expanded.
    • Set screen overscan (if wanted)
    • Configure keyboard
    • Change password (if wanted)
    • Set locale, timezone
    • Enable ssh & boot behavior
  • Optionally you can then try to make a new user, but I’ve not found a need yet.  And when I do it, I tend to screw it all up permission-wise.
  • Install VNC (so you access the Pi’s gui remotely)

Linux Distros

I’m the last person you want to ask about which distro to use, but the two main one’s I have used are Raseberian, and Occidentalis.  Rasberian is now installed as part of NOOBS, and it’s a much easier install than in the past.

  • NOOBS : From the page:  “We recommend that first-time Pi users start by downloading and installing our New Out of Box Software (NOOBS) onto a 4GB (or larger) SD card. On first boot, this presents you with a choice of operating systems to install, including Raspbian, Pidora and two flavours of XBMC. Once you have installed an operating system, you can return to the NOOBS interface by holding down shift during boot; this allows you to switch to a different operating system, or overwrite a corrupted card with a fresh install of the current one.”
  • Occidentalis : From the page : “Our distro is based on “Wheezy” but comes with hardware SPI, I2C, one wire, and WiFi support for our wifi adapters. It also has some things to make overall hacking easier such sshd on startup (with key generation on first boot) and  Bonjour (so you can simply ssh raspberrypi.local from any computer on the local network)”

Get into the Pi

It’s been a while, how do I do that?  I forgot where my  surplus usb keyboard is & the wifey is using the spare hdmi cable…

(To do a first-time setup of SSH & VNC, see the post, “Connecting the Mac to the Pi“)

First, SSH:

This will let external machines talk to the Pi.  The primary way I interact with the Pi.
Connect the pi to the network (I use cat5).
There’s a good chance the dynamic ip has changed.  From another computer, access the router and click on the ‘DHCP Client List’ to find the new ip of the Pi.
Or, if you have the Pi plugged into a monitor \ keyboard, you can enter the below command, and look for the “inet addr”

$ sudo ifconfig

Open a shell.  ssh into the Pi:

$ ssh <pi ip address> -l <userName>

Enter password.  Hopefully it lets you in…

This can fail though on a new install.  I get this on my mac:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
etc...

If this happens, lower down in the error it will have this line:

The fingerprint for the RSA key sent by the remote host is

And right below that, is an address.  Copy that address, browse (on the mac) here:

/Users/<userName>/.ssh/known_hosts

Edit that file (known_hosts), and find the section starting with the local ip of your pi.  At the end of that section, add a ‘+’, then paste in the address copied above.

When you try to re-ssh back in, it will ask you if you want to add this new host, and say “yes”.  Enter the password, and you should be good!

Copying files over SSH:

Once you have a ssh connection, you can copy data from one machine to another.

From a terminal on your PC (in my case, a Mac):

Copy data from the Pi to the PC:

$ scp pi@you_pis_ip:/path/to/source/file/on/pi /path/to/destination/file/on/pc

For example:

$ scp pi@192.168.2.27:~/piVid.mp4 ~/macVid.mp4

Copy data from your PC to the Pi:

$ scp /path/to/source/file/on/pc pi@you_pis_ip:/path/to/destination/file/on/pi

For example:

$ scp ~/macVid.mp4 pi@192.168.2.27:~/piVid.mp4

I should note that I’ve not got this to work over SSH from a terminal on the Pi.  But once a ssh connection is open, I can execute these from a terminal on my Mac just fine.

Copying files via SFTP

If you want a more robust solution to copying files to\from the Pi, SSH File Transfer Protocol (SFTP) is a good solution. The post HERE by Trevor Appleton covers how to set it up using FileZilla.  Provides a super easy way via the FileZilla gui to drag & drop files.

Second, VNC:

Once you’ve ssh’d in to the Pi, optionally you can access the desktop via VNC.

If not yet installed, install it:

$ sudo apt-get install tightvncserver

Then start the server:

$ vncserver :1

To start the server.
On your other PC, access the VNC Viewer app.
Set the VNC server address to <pi ip address>:1
Connect:  You should see your Pi’s desktop on your PC.

Update Pi Configuration

Not always needed, but if you need to access the global configuration on the pi, from the shell enter:

$ raspi-config

When done, if a reboot is needed:

$ sudo reboot

Optionally, to safely shutdown the Pi (rather than just unplugging it, which I’m told can be hard on the sd card) :

$ sudo shutdown -h now

Auto Login

Check out the post here:  Raspberry Salad Part 3: Auto-run program on startup

General linux commands

  • ifconfig : network info
  • pgrep <process name> : Return the process id
  • kill <process id> : delete the process
  • lsusb : Get attached usb device info

Setup WiFi

Adafruit has a good overview here.  Note that their section on “Setting up WiFi with the graphic interface” works, but the Pi will only start using WiFi when the gui is up.  If you want wifi to be there at the commandline as soon as the Pi boots, you need to follow their  “Setting up WiFi with the Command Line” tutorial.

Note, I’ve needed to have the pi connected to a monitor\keyboard\mouse to get this setup properly.   Having the Pi hooked up over lan and ssh’d in seems to override the WiFi with the lan, and I can’t get the IP.  Maybe I’m not smart enough.

Check to see if it’s working:

$ ping google.com

BUUUUT, I’d had problems with loosing connection over wifi.  After getting a tip from this thread, I added this line:

wireless-power off

to

/etc/network/interfaces

But that didn’t help anything.  So then I tried the recommendations from this thread (since it’s based on the chipset of the wifi dongle I got from Adafruit) to:

$ sudo nano /etc/modprobe.d/8192cu.conf

and add this code to it:

# Disable power management
options 8192cu rtw_power_mgnt=0

But after a reboot, it still didn’t work well.  In fact it got even harder to ssh in, it would constantly “Operation timed out”.  So I decided to connect the wifi dongle to my powered usb hub.  When I removed it from the Pi, it was really hot:  Power issues?

After plugging the wifi dongle into the  powered hub, and the hub into the Pi, nothing seemed to be working.  I had to power it on\off twice (over lan).  Bu by the 3rd time the wifi dongle started blinking, apparently recognized.  From there I set the Pi to pinging google. com, and my mac to ping the Pi.  So far, so good, internet radio is streaming.

So it looks like the Pi can’t provide enough, or stable enough power to the wifi dongle over it’s own usb port?   That seems… really annoying.

FINALLY, I bought a new wifi dongle:  It worked immediately.  So lesson to you all.  If you have these problems, spend $10 and get a new dongle…

Setup Camera

This post from raspberrypi.org covers it all.

A really good tutorial covering how you can capture raw  h264 videos, convert them to mp4, the play them on the Pi can be found here: Capturing HD Video With The Pi Camera Module.

And, my own setup guide here: “Playing with the Raspberry Pi’s Camera

Software Update

I use the apt-get package manager.

Update your cache:

$ sudo apt-get update

Search the cache for software:

$ sudo apt-cache search <someString>

Upgrade all the software on the Pi (can take a while… hours…)

$ sudo apt-get upgrade

Install new software:

sudo apt-get install <package>

Remove old software.  remove can leave some dependencies behind, purge deletes it all.

$ sudo apt-get remove <package>
$ sudo apt-get purge <package>

Adafruit WebIDE

The Adafruit WebIDE is a great way to program on the Pi from some other computer over ssh.  All the code is managed in the cloud via Bitbucket.   Setup guide HERE.

The general process is:

Note if you’re ‘refreshing’ an old Pi, the WebIDE may no longer recognize it.  In that case, log into your Bitbucket account, and in the “Manage Account -> Integrated Applications” menu, remove any “Consumers” and “OAut Consumers”, and then follow the setup guide to create a new one.

Packages

Scratch-pad area of different packages used based on projects I’ve done, or learned about, and probably forgotten about.

To get a list of all the packages installed:

$ dpkg -l

This post has a great overview of many packages to install: Linux & Python Packages for my Raspberry Pi

Presuming you have pip installed, you can use this to get a list of all Python packages installed:

$ pip freeze --local

Audio

Thanks to this post, I learned about these first three apps:

Alsamixer

$ alsamixer

Alsamixer is part of the distro, and has a simple command-line interface & gui.  Gives you a simple way to adjust volume, etc.

MPD & MPC

MPD is the “Music Player Daemon”.  From the page it is “an audio player that has a server-client architecture. It plays audio files, organizes playlists and maintains a music database all while using very few resources. In order to interface with it, a separate client is needed.”

One of those clients is MPC.  It is “a minimalist command line interface to MPD, not to be confused with musepack.”

To install the two at once:

$ sudo apt-get install mpc mpd

To add internet stream(s) to play (Let’s play some Groove Salad):

$ mpc add http://ice.somafm.com/groovesalad

To play a specific stream:

$ mpc play 1

MPlayer

I used MPlayer as part of my Raspberry FM internet music streamer.

Install:

$ sudo apt-get install mplayer

Play a stream:

$ mplayer http://streamer-dtc-aa01.somafm.com:80/stream/1018

Lot more MPlayer configuration from this post : “Raspberry Salad Part 2: Raspberry FM

Games

Minecraft Pi

Why wouldn’t you want to play Minecraft on you Pi?

Note, Minecraft Pi doesn’t work for me over VNC:  The application launches, but all I see is a black window.  You need to have the Pi directly connected to a monitor/keyboard/mouse.

FYI, it needs to be ran via the XWindows gui mode, so be sure to launch it first via

$ startx

Open a LXTerminal window:  Download (to your home dir), install (then remove the tar), & run:

$ cd ~
$ wget https://s3.amazonaws.com/assets.minecraft.net/pi/minecraft-pi-0.1.1.tar.gz
$ tar -zxvf minecraft-pi-0.1.1.tar.gz
$ rm minecraft-pi-0.1.1.tar.gz
$ cd mcpi
$ ./minecraft-pi

Python

First off, be sure to get pip installed:

$ sudo apt-get install python-pip

Once that’s installed, you can use pip to pull down all other Python packages needed.  This is preferred to using apt-get, this  post does a pretty good job of explaining why.  That being said, I’ve been unable to use pip to install certain packages (like matplotlib), and apt-get works fine.  However, once installed by apt-get, pip recognizes them.

See what Python packages you have installed:

$ pip freeze

RPi.GPIO

You’ll need this to access the Pi’s GPIO pins in Python:

$ sudo pip install RPi.GPIO

pyserial

$ sudo pip install pySerial

PIL

I’ve been unable to get PIL installed via pip.  But apt-get seems to work:

$ sudo apt-get install python-imaging

scipy

Again, pip fails for some reason.

$ sudo apt-get install python-scipy

OpenCV

This wil install OpenCV, and the Python bindings:

$ sudo apt-get install libopencv-dev python-opencv

Some links:

Other Hardware

Arduino

This Instructable has a really good overview of how to instal all the necessary packages to get your Pi to talk to an Arduino: “Arduino / Raspberry Pi Internet Radio“.

$ apt-get install arduino

And other Python dependencies:

$ sudo pip install nanpy
$ sudo pip install pyserial

Connecting the Mac to the Pi

The main hurdle I’ve had with the Raspberry Pi is simply seeing the screen:  Since I don’t have  a spare monitor laying around, it’s plugged in over HDMI to my livingroom TV.  Sitting on my couch,… the text is really small.

Thanks to the awesome people at Adafruit Learning Systems, they’ve provided two tutorials specifically for logging into your Pi remotely over SSH (Secure SHell), and remote-controlling the desktop via VNC (Virtual Network Computing).  This gives you the advantage of not needing a spare monitor, keyboard & mouse to control the Pi:  You can use your current PC’s setup.

I don’t know anything about Linux or sysadmin work, but their tutorials worked exactly as shown and I was connected in no time.  I’m posting this mainly as a reminder to myself how I got all this stuff hooked up…

  • First, you need to get a SSH connection from your computer (in my case, Macbook Air) to the Pi:  Adafruit’s Raspberry Pi Lesson 6: Using SSH shows you how.  Once this is setup, you can easily remotely login from a Terminal on your PC, and take control of the Pi.  But you don’t have access to it’s gui system, only the command-line.
  • Second, to control the Pi’s gui, you need to install a VNC server on the Pi, and a client on your PC (Adafruit recomends RealVNC’s ‘VNC Viewer’).  Their tutorial covers all of this: Adafruit’s Raspberry Pi Lesson 7: Remote Control with VNC.

Once all that software is installed\setup\configured, how do you make the connection?

  • Boot the Pi, wait for it to ‘be ready’.
  • Open a terminal on your PC:  SSH into the pi (put in appropriate ifnet address of the Pi and login name):
    • ssh 192.168.2.97 -l myPiLogin
  • The terminal is now controlling the Pi.
  • Next, start the VNC server on the Pi:
    • vncserver :1
  • Now that you have a SSH connection to the Pi, and the VNC server running on the Pi, you can connect via VNC Viewer on your PC:
  • Open the VNC Viewer app, and connect to the pre-configured server you made earlier:   For example, 192.168.2.97:1
  • After entering in the password, the Pi’s desktop should spring to existence on your PC.
If you forget the address of your Pi, you can run ifconfig from the pi itself (which of couse means hooking it back up to a monitor\keyboard) to get it.
Programming Python on the Pi will be so much easier now…

Pi's desktop on my Mac's desktop: Success!