Difference between revisions of "Raspberry Pi"

From Organic Design wiki
m (Making a wifi signal extender)
m (Making a wifi signal extender)
Line 78: Line 78:
 
</source>
 
</source>
  
In my case I found that the original on-board one showing up as '''wlan1''', and the new one as '''wlan0'''. I figure that it would be best to use the new one as the one that connects wirelessly to the internet router, because it has an external antenna and so probably can reach the router from further away than the on-board one could. The connection details (the router SSID and password) are usually added to the ''/etc/wpa_supplicant/wpa_supplicant.conf'' file to have the wifi adapter automatically connect to the router on boot up. But if we do that then both of the wifi adapters will connect to the router, to have the details in the file only apply to a specific interface, the interface name can be included in the file name - in this case we call the file '''wpa_supplicant{{h|-wlan0}}.conf.
+
In my case I found that the original on-board one showing up as '''wlan1''', and the new one as '''wlan0'''. I figure that it would be best to use the new one as the one that connects to the internet router, because it has an external antenna and so probably can reach the router from further away than the on-board one can. The connection details (the router SSID and password) are usually added to the ''/etc/wpa_supplicant/wpa_supplicant.conf'' file to have the wifi adapter automatically connect to the router on boot up. But if we do that then both of the wifi adapters will connect to the router, to have the details in the file only apply to a specific interface, the interface name can be included in the file name - in this case we call the file '''wpa_supplicant{{h|-wlan0}}.conf.
  
 
Now for the internal ''wlan1'' wifi, we want to configure that one as a hotspot. The easiest way to do this for Raspbian is using the ''create-ap'' utility which is covered in the [[hotspot]] page. Once you've gone through the installation of that, you can then configure it in ''/etc/create_ap.conf'', the minimal settings involve setting the interface names and specifying an SSID and password.
 
Now for the internal ''wlan1'' wifi, we want to configure that one as a hotspot. The easiest way to do this for Raspbian is using the ''create-ap'' utility which is covered in the [[hotspot]] page. Once you've gone through the installation of that, you can then configure it in ''/etc/create_ap.conf'', the minimal settings involve setting the interface names and specifying an SSID and password.

Revision as of 05:59, 11 October 2019

RaspberrypiAnim.png

The Raspberry Pi is a credit-card-sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools. The Raspberry Pi is manufactured through licensed manufacturing deals with Element 14/Farnell and RS. Both of these companies sell the Raspberry Pi online.

The Raspberry Pi has a Broadcom BCM2835 system on a chip (SoC), which includes a 700MHz ARM11 processor (The firmware includes a number of "Turbo" modes so that the user can attempt overclocking, up to 1 GHz, without affecting the warranty), VideoCore IV GPU, and was originally shipped with 256 megabytes of RAM, later upgraded to 512MB. It does not include a built-in hard disk or SSD, but uses an SD card for booting and long-term storage. The Foundation's goal is to offer two versions, priced at US$25 and US$35. The Foundation started accepting orders for the higher priced model B on 29 February 2012, and the lower cost model A on 4 February 2013.

RaspberryPi.jpg

The Foundation provides Debian and Arch Linux ARM distributions for download. Also planned are tools for supporting Python as the main programming language, with support for BBC BASIC, C, and Perl. On 17 December 2012 the Raspberry Pi Foundation, in collaboration with IndieCity and Velocix, opened the "Pi Store", as a "one-stop shop for all your Raspberry Pi (software) needs". Using an application included in Raspbian, users can browse through several categories and download what they want. Software can also be uploaded for moderation and release.

How it came about

The original idea in 2006 was a response to the gradual drop in computing skills seen in students applying for computing degrees at Cambridge. Everyone knew how to use Microsoft Word, PowerPoint, Excel, Access; they didn't know much about coding, though, or what actually happened inside the machine.

Those familiar with schools in the 1980s will know they were full of BBC Micro computers, and everyone learnt how to write programs in BASIC. Computer games back then ran on computers that were practically built for coding, and plenty of amateur enthusiasts now work in the computer science industry. Sadly, as computers have become more complicated, school lessons have changed to train students in simple computer usage, without understanding what goes on underneath. The sheer complexity and expense of computers also means that kids aren't encouraged to fiddle with them, and purpose-built games consoles now dominate where Sinclair ZXs, Amstrads and Commodore Amigas once stood.

Thus, the solution: make a cheap but very capable computer that can be used in classrooms, that can be replaced easily if broken, and that lets you play with computer code whether at school or at home. Make it so it plugs into the TV at home, like computers used to do.

Installation with Raspbian

Raspbian is a Debian variant based on the ARM hard-float (armhf)-Debian architecture port but optimised for the ARM instruction set of the Raspberry Pi hardware. Raspbian provides over 35,000 available deb packages pre-compiled for easy installation on a Raspberry Pi computer, specifically tuned for optimal performance on the Raspberry Pi ARM hardware. The Raspbian distribution basically contains the LXDE desktop environment, the Openbox window manager, the Midori web browser, software development tools and example source code for multimedia functions. Raspbian is a project of a small, dedicated team of developers, and is not affiliated with the Raspberry Pi Foundation.

We use the Raspbian Lite which you can download from here. Lite is stripped down version of Raspbian with other software packages bundled as compared to the usual desktop-oriented Raspbian distribution which is best for headless servers.

Simply write the bootable Raspbian image to your SDcard with your favourite disk utility, and then add an empty file called "ssh" to the root directory of the boot partition which will ensure that youu have ssh access after the system is booted. If you also want to give it some default wifi connection details, add them in a file in the same place called wpa_supplicant.conf with the following format:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
	ssid="WiFi_SSID"
	psk="WiFi_Password"
}
  • Note1: The wpa_supplicant.conf file will be copied into /etc/wpa_supplicant which is where it can be created or modified after the system is up and running.
  • Note2: If you'd like the file to apply only to specific interfaces (in the case that you have more than one wifi adapter) you can name the file e.g. wpa_supplicant-wlan1.conf.


Put the card in the Pi and power it up. It will connect to the networks over LAN and/or wifi using DHCP. You can find it's IP with nmap, e.g

nmap -sP 192.168.0.0/24

Here's some example output showing the Pi's information:

Starting Nmap 7.70 ( https://nmap.org ) at 2019-09-17 13:00 -03
Nmap scan report for 192.168.0.1
Host is up (0.0040s latency).
MAC Address: CD:0E:DC:E9:B3:E3 (Cisco Spvtg)
Nmap scan report for 192.168.0.5
Host is up (-0.087s latency).
MAC Address: B8:31:EB:3C:5C:6F (Raspberry Pi Foundation)
Nmap scan report for 192.168.0.14
Host is up.
Nmap done: 256 IP addresses (3 hosts up) scanned in 3.60 seconds

If you want to give it a fixed IP, you can set this up using in your router's DHCP server using the Pi's MAC address. Once you have discovered the Pi's IP you can ssh into it with the default credentials of user name "pi" and password "raspberry". Then you can begin configuring it starting by removing the default password! One very useful thing you may like to do straight away is make your Pi into a wifi hotspot :-)

External drives

Adding external drives to be mounted on boot in the Pi seems to be a bit dodgy sometimes, I've been having problems with transfers of large data freezing after a few minutes and then the drive finally being remounted in read-only. I didn't get the errors from the log unfortunately, but so far I've found nofail,noatime 0 0 seems to give the best results for an external mechanical 2.5" disk (defaults, 0 2 was not good).

This problem was a power supply issue as syslog is showing a lot of under voltage warnings, when using a 1A cellphone charger, I tried a 3.1A "fast charger" from an African on the street which worked a bit better, but still ran nto the same problem. Eventually I found that you need to use an official Raspberry Pi power supply because they have 5.1v output to account for this voltage drop that happens regardless of the current your power supply produces.

PiBackie.jpg
NeedMorePower.jpg

One way of making the system less reliant on the SD card is to have it used only for initial booting and then use the external drive for root partition. This is set in the /boot/cmdline.txt file, see this for more detail.

Making a wifi signal extender

In a few AirBnB's we've stayed at recently we've found that the wifi signal is very weak in some parts of the house where we like to use the computers a lot. I decided to make a general purpose solution using a Pi with an extra wifi adapter added via USB. This extra wifi adpater could also be further extended using a 5m USB extension cable in the case of very extreme cases involving concrete walls etc.

It's easiest to get an official wifi module so that you know it's supported by the Pi out of the box, but in my case I already had a USB adapter that was based on the RTL8192EU chip which took a few hours to get working. In the end I found these instructions that use this script which worked flawlessly:

sudo wget http://fars-robotics.net/install-wifi -O /usr/bin/install-wifi
sudo chmod +x /usr/bin/install-wifi
sudo install-wifi


After running this, I could then see my two wifi adapters listed in ifconfig. To see which is which, you can check the driver that each one is using:

readlink /sys/class/net/wlan0/device/driver
readlink /sys/class/net/wlan1/device/driver

In my case I found that the original on-board one showing up as wlan1, and the new one as wlan0. I figure that it would be best to use the new one as the one that connects to the internet router, because it has an external antenna and so probably can reach the router from further away than the on-board one can. The connection details (the router SSID and password) are usually added to the /etc/wpa_supplicant/wpa_supplicant.conf file to have the wifi adapter automatically connect to the router on boot up. But if we do that then both of the wifi adapters will connect to the router, to have the details in the file only apply to a specific interface, the interface name can be included in the file name - in this case we call the file wpa_supplicant-wlan0.conf.

Now for the internal wlan1 wifi, we want to configure that one as a hotspot. The easiest way to do this for Raspbian is using the create-ap utility which is covered in the hotspot page. Once you've gone through the installation of that, you can then configure it in /etc/create_ap.conf, the minimal settings involve setting the interface names and specifying an SSID and password.

WIFI_IFACE=wlan1
INTERNET_IFACE=wlan0
SSID=PiFi_Extension
PASSPHRASE=MyPwd

Then I set the hotspot service to start on bootup and rebooted it to test everything was working :-)

systemctl enable create_ap

Pi based projects

Useful links

Other options

See also