Thursday 22 October 2015

Accessing Raspberry Pi from your laptop

This is a small how to access the Pi with your laptop, in case you don't have an external monitor and keyboard. One of my friend got this new Raspberry Pi 2 Model B and we tested it.








This model comes with 4 USB ports, 1 ethernet port, 1 HDMI port, audio port, SD card slot, GPIO Header. This models comes with the mini USB wifi adapter, micro SD card with pre-installed OS (NOOBS).


pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux

pi@raspberrypi ~ $ cat /proc/version
Linux version 3.18.11-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015



pi@raspberrypi ~ $ uname -r
3.18.11-v7+



Either you would need an monitor supporting HDMI with a keyboard to see it boot and configure it accordingly. For us we did had any external monitor so we got it working by connecting it to our laptop and configuring dhcp server on my laptop.

We used tftpd32: http://tftpd32.jounin.net , which also can be configured for dhcp and connected our Pi to my laptop.



The Pi got an ip and we were good to go.




Finally you can use putty to ssh to your Pi. 

If you have a wireless network available you can also configure the Pi to connect to the wireless ssid. First of all make sure that the wireless adapter is getting detected.


pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 007: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

Do iwconfig to check if the wireless interface shows here. You can also do, sudo ifdown wlan0/sudo ifup wlan0 to bounce the interface.

Use the command : sudo iwlist wlan0 scan  to scan the wifi network available, to make sure the network you are about to configure is seen in this list.

Now open the wpa-supplicant.conf file using nano or vi and edit it to add you desirable network to the list. Goto the bottom of the file and add:

network={
    ssid="My-SSID"
    psk="My-Password"
}

Save and exit and the Pi should connect to your wifi if configured correctly.

For me the Pi was getting an ip however was not able to go out to the internet for which I had to configure the default gateway as the gateway was not configured for my device:

pi@raspberrypi / $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 wlan0


sudo route add default gw 192.168.1.1 wlan0


pi@raspberrypi / $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 wlan0
192.168.1.0     *               255.255.255.0   U     0      0        0 wlan0



Once the Pi has an ip address you can access the Pi GUI using couple of methods:


1. Using X11 Forwarding /Xming:


You can also use X11 forwarding and Xming to access the Graphic Interface of the Pi. 
Open putty, specify the ip address of the Pi, use ssh/port 22. Goto X11 on putty window and enable X11 Forwarding and connect to your Pi. 




On the Pi terminal type startlxde or lxsession and you should see the Pi desktop on Xming.



2.Using Xrdp :


You can install xrdp on Pi and rdp to it using the windows laptop.

pi@raspberrypi ~ $ sudo apt-get install xrdp
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  xrdp
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 252 kB of archives.
After this operation, 1,499 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main xrdp armhf 0.5.0-2 [252 kB]
Fetched 252 kB in 1s (135 kB/s)
Selecting previously unselected package xrdp.
(Reading database ... 79469 files and directories currently installed.)
Unpacking xrdp (from .../xrdp_0.5.0-2_armhf.deb) ...
Processing triggers for man-db ...
Setting up xrdp (0.5.0-2) ...
[....] Generating xrdp RSA keys......
Generating 512 bit rsa key...

ssl_gen_key_xrdp1 ok

saving to /etc/xrdp/rsakeys.ini

done (done).
[ ok ] Starting Remote Desktop Protocol server : xrdp sesman.



Open remote desktop (mstsc.exe) and connect to you Pi ip. You will be presented with the login screen, feed the Pi credentials and there you go.






Hope this would be helpful.

Labels: , , ,