Showing posts with label raspbian. Show all posts
Showing posts with label raspbian. Show all posts

Remote desktop for Raspberry Pi

Avid readers of this blog will know that I am a big fan of the RISCOS pi operating system for Raspberry Pi. I mainly use it for the nostalgia factor, however I also keep a set of note on it in addition to some programming.

I also have a need for the Linux distribution as well.  I currently regularly use Raspbian flavour of Linux for the following tasks:

These are all jobs that I want to have running permanently, however it started to annoy me that I had to quit Raspbian in order for the device to boot into RISCOS.  The solution was to get a second Raspberry Pi 2 to use as a dedicated RISCOS Pi and leave the first device for uninterrupted Linux stuff! This caused it's own problems, of course, as I only have room for one monitor, one keyboard and one mouse. Swapping the devices over when I wanted to quickly check on something on the server was becoming irritating and so the obvious solution is to install a remote desktop.

If you were not aware, a remote desktop allows you to run one computer from another computer. You literally see the desktop of one computer in a window on a second machine. This is incredibly useful for doing things with Raspberry Pi wherever the use of keyboards, mice and monitors are a problem. For example, you might want to put the Raspberry Pi in a remote location in your house or garden to monitor temperature, or take photos as aliens pass over your roof. Maybe you want to set the machine up as a burglar detection and capture system. Maybe your Raspberry Pi is the central brain of your doomsday machine or robot butler and having a monitor and keyboard attached is just soooo nineteen nineties. Either way, controlling your Pi from another computer or tablet is really cool.

Your choice of software for performing a remote desktop depends on your current distribution of Raspbian: you could try xrdp, or VNC.

XRDP

I have used xrdp on a number of Pi devices at both work and at home. These instructions should work if your device was installed before 2017.


1. First install the xrdp software onto your Pi. Navigate to the terminal and type: sudo apt-get install xrdp
2. Follow any on-screen instructions.
3. Once completed restart your device with sudo restart
4. You will need the IP address of your device on your home network. If you don't know it you should be able to find it from either your home router's admin page, or type the command: ifconfig You are looking for a line that reads something like: inet addr:192.168.1.162

5. Once you are happy that xrdp is ready for your Raspberry Pi you should be able to connect from your second computer.  In Windows 10 select Cortana and type "Remote Desktop". This should launch a program called "Remote Desktop Connection".

Finding the Remote Desktop in Windows 10. For earlier versions of Windows, it will be found in your Start > All programs > Accessories folder.

6. Type in the IP address of your Raspberry Pi from part 4 (for example, mine is 192.168.1.162).
7. Enter your username and password. You should now find that you can now see your Raspberry Pi desktop.

Enter your username and password at the prompt. If you haven't changed them already, then your username should be 'pi' and the password is 'raspberry'

If you get connection problems, then you probably need to follow the steps for VNC below.

VNC

1. Navigate to your Terminal in Raspbian and type: sudo raspi-config
2. A menu should appear. Find “Interfacing Options” and make sure that VNC is enabled.
3. Reboot the Raspberry Pi.
4. Whilst your Pi is rebooting you can install the VNC Viewer client software on your second computer. I downloaded the portable version from the RealVNC website for Windows, however other versions are available for other machines.
5. Once you have this client running you should be able to enter your IP address and connect.

If everything has gone to plan then you should be seeing your Raspberry Pi desktop on your other computer. Very handy for controlling your computer from another room.

Another really good feature is that VNC will allow you to transfer files from your computer onto the Raspberry Pi. To do this, first click on the icon in the top left corner. Then select "File Transfer" from the menu. I use this to maintain various files on my home server. For example I have a set of notes written using Zim. These notes are written on my PC and keep track of various things that are useful for both RISCOS and Raspbian (such as all the instructions on this blog article). As soon as I learn something new about the Raspberry Pi, I make a note of how I did it and then upload it to the server. As they are kept on my server I can access them from any of the machines on my home network, including the RISCOS device. Very handy indeed!




Getting my pi on the network

I have recently been setting up a Raspberry Pi and documenting the process here.

In previous posts I have been dealing with the RISC OS setup. Today I moved over to Raspbian. This post will deal with:

  • Getting the Pi to see my home network hard drive.
  • Setting up the Pi as a home server.
  • Changing the system password.

Getting the Pi to see the network hard drive
I have a 2TB USB hard drive on my home network. I use this to share music, movies and other media between computers in my home. You can read my full article about getting a USB hard drive to work on your network, however I have summarised the steps for Raspbian below.


  • You need to mount the network drive into the Raspbian file system.  To do this you need to have cifs-utils installed.  My Raspberry Pi 2 came with this pre-installed.  You can check whether it exists or not by running the following command: dpkg -s cifs-util


  • Should you need it, you can install cifs using the command sudo apt-get install cifs-utils


  • Next create a directory on your pi for where you want to mount the network drive: sudo mkdir -p /media/network/public


  • You need to edit the etc/fstab file in order to mount the network drive. You may need to give yourself permission to do this, so navigate to your /etc folder and type chown pi: fstab (where pi is your username).


  • Now open the etc/fstab file in your text editor and add the following single line:

   //192.168.1.254/usb1 /media/network/public cifs defaults,rw,username=pi,password=yourpassword,domain=domain 0 0

Note that the first part is //IP ADDRESS OF ROUTER/directory name of network folder. If your network folder has any spaces in the name, eg "My Documents", then replace the spaces with \040, eg My\040Documents.

The second part is the path to the folder you created in part 3. You will need to put in your own username and password .


  • Now mount the drive using sudo mount -a


Once complete, you will see your network drive appear as a folder in your file manager.

Raspberry Pi file manager showing network drive

Setting up the Pi as a home server
The following steps will allow your Raspberry Pi to serve dynamic web pages to other devices on your network.

  • First install the full LAMP stack with sudo apt-get update and then sudo apt-get install apache2 php5 php5-mysql mysql-server
  • This will install all the software that you will need to run a home server. You may be prompted to enter a password so do add a suitably secure password at this stage. Once you are happy with your password (at it is one that you will remember) the rest of the process may take a few minutes.
  • When the install finished you should navigate to the /var/www/html folder. This folder will contain all of the files that your server will use.
  • To check that your server is working, Apache should provide a test page. Using another computer or phone type the IP address of your web server on your home network. Mine is http://192.168.1.162 and you may be able to get this information from your home router page or using the command ifconfig. If all is well, you should get a confirmation page.
Apache confirmation page as viewed in Chrome browser under Windows 10

  • You can now replace this file with your own home page. Should you find that you do not have permission to access files in your webserver, you can use the Linux chown command to change ownership permissions. The syntax is: sudo chown pi: item where pi is your username and item is the name of the file or folder you wish to access, for example: sudo chown pi: index.html will give you ownership access to the file. It may still mean that you can't edit the file, so navigate to the file in your file manager, right click and bring up the 'properties'. Then change the 'permissions' to 'change content: anyone'.
Changing the system password
Now that your Raspberry Pi system is running a web server and has access to the network drive, you will probably want to set the password for access to the Raspberry Pi system. Your Pi may boot directly into a password entry when it boots, however many new installations of Raspbian skip this step so as to make using the machine as painless as possible for new users.

  • Find the main menu, and navigate to 'Preferences' and then 'Raspberry Pi Configuration'.

Finding the password preferences in Raspbian
  • You will be prompted to enter your old password before you can change it. If you are using the default user 'pi', then the default password is 'raspberry'.
  • Make sure that you un-check the box that says Login as user 'pi'.
Hit the 'change Password...' button to change your password. Then make sure you un-tick the box shown. This is what has been letting you log in automatically to the Raspberry Pi, but it also lets your little brother get in and see all your stuff too!


Well, that's all I have for today.  If you are still awake, then you might be interested in some more Raspberry Pi related posts.

Playing audio through Raspberry Pi

My Raspberry Pi and my BBC Master both share a 32 inch TV screen.  The problem is that I wish to continue using my Pi as a media player whilst simultaneously working with the BBC microcomputer (which doesn't play media).  In its default setting the Raspberry Pi sends audio through the HDMI to the TV and so all is very quiet when I switch to the BBC computer on SCART.

The Pi has an audio output however nothing happens when you plug an audio jack in.

A little Linux is required:


    lsmod | grep snd_bcm2835


Followed by:

    amixer cset numid=3 1


(To return to the default settings change the final '1' to '2'.)


I can now use the Pi as a media player, whilst simultaneously using my BBC computer as a productivity machine.  My music media files are stored on an external hard drive on my home network.  Altogether I am a happy nerd.

I cannot, however, force the audio through the headphones audio jack when using RISCOS on the Raspberry Pi.  I have tried changing the config.txt file by following online instructions but so far have had no luck.  If anyone knows how to do this then please get in touch.


Sharing a usb drive to chromebook, raspberry pi, Android and Windows 10

I noticed that my new home router comes with a USB port. I figured that it was possible to connect an external hard-drive and use my router as a home file server. This means that I will be able to share files between my Chromebook, Raspberry Pi, Android tablet and Windows machines.


Here are the steps I used by device.

First steps
Plug in your usb drive and check the admin settings on your home hub.  I get there through the default address of my router which is 192.168.1.254 and yours is likely to be similar.  It is a good opportunity to change the admin password at this stage.

In Windows 10
Access to the shared network drive is as easy as opening the file explorer and typing the address into the address bar eg //192.168.1.254

Your files are now ready to be accessed on all your devices.


On a Chromebook.
It would be useful to access my PC files on my Chromebook as well.  I used File System for Windows.


Your shared files are now available in the ChromeOS File app.

On Raspberry Pi under Raspbian

1. You need to mount the network drive into the Raspbian file system.  To do this you need to have cifs-utils installed.  My Raspberry Pi 2 came with this pre-installed.  You can check whether it exists or not by running the following command: dpkg -s cifs-utils

2. Should you need it, you can install cifs using the command sudo apt-get install cifs-utils 

3. Next create a directory on your pi for where you want to mount the network drive: sudo mkdir -p /media/network/public

4. You need to edit the etc/fstab file in order to mount the network drive. You may need to give yourself permission to do this, so navigate to your /etc folder and type chown pi: fstab (where pi is your username).

5. Now open the etc/fstab file in your text editor and add the following single line:
   //192.168.1.254/usb1 /media/network/public cifs defaults,rw,username=pi,password=yourpassword,domain=domain 0 0

  Note that the first part is //IP ADDRESS OF ROUTER/directory name of network folder
 If your network folder has any spaces in the name, eg "My Documents", then replace the spaces with \040, eg My\040Documents.
 The second part is the path to the folder you created in part 3.
 You will need to put in your own username and password .

6. Now mount the drive using sudo mount -a


Android

There is no single file explorer app for Android, but many of them allow you to access network drives. I use ES file explorer which has a nice 'search' feature which will find your network drive in a few seconds. You can also pin your network drive to your desktop for easy access.

Accessing your network drive in Android

Windows Phone

I have downloaded Metro File Explorer to access my home network files on my Lumia 950.


That's all for now (I've run out of devices to try). It's time to backup to my file server and tidy up a bit.

Raspberry Pi Sense HAT data logger

I have been working on a command line temperature/humidity/pressure data logger for my Raspberry Pi Sense HAT.

You can get the Python code from this folder.

The data logger command line running on the Raspberry Pi 2 showing all available commands.

The script provides the following commands for accessing the Sense HAT sensors:


  • temp (gets the current temperature)
  • pressure (gets the current air pressure)
  • humid (gets the current relative humidity)
  • time (gets the current time/date)


You can also set up a 'log' which will automatically log data from the sensors to a csv file. The duration of the log run and the time interval between measurements can be set through commands.

This log shows the change in temperature and humidity over a few hours.
Running a log.

Hello Sense HAT

Yesterday I bought one of the wonderful Sense HAT boards from element14.com. The Sense HAT provides an 8x8 LED maxtrix display, accelerometer, gyroscope, magnetometer, air pressure sensor, temperature sensor and air pressure sensor, as well as a small joystick.  Basically a bundle of sensors that plug in directly to the GPIO pins on your Raspberry Pi. They are well worth purchasing should you wish to upgrade your Pi.  I would like to set up a data- logging weather station, however I have only had time for a brief experiment with the features so far.

Follow link for buying options.


Setting up is very easy: the board just plugs straight in and the online instructions are very easy to follow. I suggest you download the Sense HAT Python API or you wont get very far with Sense HAT.

Listed in this post are two of my 'hello world' programs.

Space Invader


I am your father...
This program creates a space invader tile on the LED matrix display and flashes the colours.

# Displays a space invader on the LED panel
# and flashes the colours a bit
import time
from sense_hat import SenseHat

def getInvader():
    return [
            O, O, X, X, X, X, O, O,
            O, X, X, X, X, X, X, O,
            X, X, O, X, X, O, X, X,
            X, X, X, X, X, X, X, X,
            X, X, X, X, X, X, X, X,
            O, X, X, O, O, X, X, O,
            O, X, X, O, O, X, X, O,
            O, X, O, O, O, O, X, O
            ]

sense = SenseHat()

while True:
    for r in range(255, 0,-5):
        for b in range(0, 255,5):
            X = [r, 0, 0]
            O = [0, 0, b]
         
            sense.set_pixels( getInvader() )
            time.sleep(0.1)




Thermometer


Displaying a scrolling display of the sensor outputs.
This program simply displays a continuous scrolling readout of the temperature and air pressure. The colour of the display depends on the current air temperature.

# Displays the temperature and pressure
# on the LED panel
import time
from sense_hat import SenseHat

sense = SenseHat()

while True:
    # find temp in celsius
    t = sense.get_temperature_from_humidity()
    # find temp in fahrenheit
    f = ((t/5)*9)+32
    # find pressure in mb
    p = int(sense.get_pressure())
    # find display colour
    # this depends on the current tremperature
    if t<12:
        myCol = [ 0, 200, 230 ] # a cold colour
    elif t<22:
        myCol = [ 0, 220, 0 ] # a neutral colour
    elif t<29:
        myCol = [ 200, 100, 0 ] # a warm colour
    else:
        myCol = [250, 0, 0 ] # very hot colour
    #display message
    sense.show_message( str((int(t*10))/10)+"C   "+str((int(f*10))/10)+"F    "+str(p)+"mb", text_colour=myCol)
    time.sleep(0.5)


Sense HAT reading the wrong temperature

One problem: the temperature sensor is positioned on the board so that it is directly above your Raspberry Pi processor. This means that it picks up the ambient air temperature as well as some of the heat from the processor. Positioning the Pi vertically along its widest edge alleviates some of this problem due to better convection however not altogether.

I do not have a decent thermometer to test the callibration, however I suspect that the Pi can become inaccurate by 12 degrees Celsius or greater.

The manufacturers make no apologies for this.

One solution is to make a heuristic algorithm (a fudge-y guess) at the temperature, however this is not very satisfactory.

Another solution will be to position the Sense HAT further away from the motherboard using a 40 pin ribbon cable and GPIO cobbler. I have a 20cm cable currently with the Royal Mail (along with some blu-tak). I'll let you know how I get on with this.

Still awake? That's all for now, but try these...
More Raspberry Pi adventures.
More programming things.
Something completely different.

#raspberrypi #senseHAT

Music on Console for Raspberry Pi

Following on from last week's post on setting up my RISC OS Pi machine as a media center, I started to play around with the Raspbian distribution. I needed a lightweight media app to play music as i work, and a little research led me to MOC, or Music On Console.

The MOC console running on Raspbian.
Installation
This is very straight-forward.  If you are interested, type:

sudo apt-get install moc

Launch the application with:

mocp

MOC will run even if you don't have a GUI installed.  You can even close the terminal window or tab and your music will continue to play.


General Instructions

MOC is very simple to use. Navigation through your folder structure uses the cursor keys. Press 'Enter' to play.  Press 'n' to skip to the next track.

Press 'h' for help. This will bring up the list of keyboard short-cuts for controlling the system.  I have only just scratched the surface here.

It is also possible to control MOC from the command line through flags, ie characters following a dash.  For example, to stop the current playback, use:

mocp -s

Or, to display information about the current song file:

mocp -i


Th..th..that's all folks!
MOC looks good and I look forward to experimenting with all that it can do over the next few weeks. It really is a very lightweight app - it is currently using less than 1% of my system resources.



Day two: I broke my Pi


It is day two of my Raspberry Pi adventures and I have run into trouble. I wanted to listen to BBC Radio 4 this morning to catch up on some vital shipping forecasts.  Problems: Firefox for RISC OS didn't seem to run at all, so I fell back on the bundled browser NetSurf. Choice of browser was academic, of course, as the BBC use Flash in their internet radio (come on Beeb, sort this out!).

Undeterred I followed some forum advice (I wont link it here) to install Gnash on the Raspbian side of the Pi.

This install seems to have corrupted my computer as I am now unable to login to the Raspberry Pi under Raspbian.  The login dialogue appears, but upon entering my correct credentials the screen goes blank, the machine appears to do something and then the login dialogue appears again. This cycle continues regardless of what I type into the dialogue box.

I tried switching to Linux command line using CTRL+ALT+F1. Although this allowed me to enter my credentials, the screen goes blank and I can make no further progress.

I've posted here in case this is of use to someone, or indeed, if anyone can help.

The adventure will continue when I have rebuilt... stay tuned.

Still reading? Have a look at my first Raspberry Pi post, or look at something else.

#Raspbian
#Gnash
#Pi
#Raspberry Pi
#RISC OS

Label