www.NewsDownload.co.uk Page 17

Raspberry Pi Headless

2013-02-13 11:47 By Jason Birch

For running systems with a Raspberry Pi computer which do not require any auxiliary devices to be connected. For example web, FTP, file, media, database servers. Yet the Raspberry Pi device is still accessible enough in isolation, to be able to administer the system independently.

VIDEO
The video here demonstrates the project which this article describes how to build.

The article breaks the project down into several stages:

  • Hardware
  • System application software
  • Configuring the OS
  • Project costing

Reference:

Hardware
The hardware has several elements, all of which are simple to understand. There is a pair of transistors so that the LCD can be powered off using software to improve battery performance. There are a pair of transistors to change the voltage levels on the RS232 Tx and Rx lines. There is a switched mode 5V regulator to provide power for the Raspberry Pi from the battery pack. There is an 20 x 4 character LCD display and four LEDs to display information to the user and four switches to receive information from the user.

GPIO Pin Allocation
First Blue LED GPIO 2
Second Blue LED GPIO 25
Red LED GPIO 3
Yellow LED GPIO 27
Green LED GPIO 23
Switch 1 GPIO 4
Switch 2 GPIO 17
Switch 3 GPIO 22
Switch 4 GPIO 24
LCD 0V Power Off GPIO 30
LCD 5V Power Off GPIO 31
LCD Enable Control Line GPIO 7
LCD Register Select Control Line GPIO 8
LCD Data bit 4 Line GPIO 11
LCD Data bit 5 Line GPIO 9
LCD Data bit 6 Line GPIO 10
LCD Data bit 7 Line GPIO 18
RS232 Tx GPIO 14
RS232 Rx GPIO 15

20 x 4 Character LCD Module
The module fits really neatly into the playing card case I use for my projects. The module comes with out a header installed, so a 16 pin right angle header was used in order to keep the profile of the device as low as possible. A right angle header was also added to the stripboard which mounts directly on the Raspberry Pi header pins. To connect the two headers together a couple of 16 pin header connectors where wired together with short wires. The header connectors needed to be trimmed a bit as space was tight.

The LCD module has a 5V power supply which goes to the logic, back light and LCD. The LCD supply is generated using a 10K variable potential divider between 5V and 0V, this effectively creates an adjustable contrast control. The power is switched on and off using two GPIO pins which switch a couple of transistors. A PNP transistor is required to switch the positive side and an NPN transistor is required to switch the negative side. To power the LCD module, the PNP needs to be held low and the NPN needs to be held high. To switch off the LCD module I make the GPIO pins high impedance as inputs. Each time the module is powered up in software, it is important to remember to run the re-initialize routine again and display the last displayed text again.

The LCD module has control lines which need to be driven from GPIO pins. It has a read and write mode.

IMPORTANT: The LCD module must never be in read mode because it will output 5V signals to the GPIO pins, which will damage the GPIO circuity in the Raspberry Pi. To prevent this the R/!W pin is connected directly to 0V so the device is permanently in write mode.

There are eight data pins, luckily the module can be used in 4 bit mode, which means only the upper four data lines (D4 - D7) need to be connected to GPIO pins. This is done via 1K resistors as a precaution. A data line called Register Select is connected via a 1K resistor to a GPIO line, this selects if the data being sent is a command or character data. Finally there is a data line called Enable which is also connected to a GPIO pin via a 1K resistor, this tells the module when there is some data to be read.

NOTE: Resistors Are Cheap
When ever I have logic data which I want to drive from a GPIO pin on the Raspberry Pi, I place a 1K resistor in line. I do this in case I make a wiring error and accidentally try and sink or source too much current from the GPIO pin. This wont protect the GPIO pin in all circumstances, but will in some and potentially give you enough time to spot the error and correct it in others. In the observation above, as the display runs off of 5V, I do not know what the effect of experimenting with switching the modules power on and off if I did not have a 1K resistor in the GPIO lines. It may have been OK, but I feel better for them being present and it's not a big expense.

LED and Switches
The LEDs and Switches are implemented in the most basic form. For LEDs there is a 470R resistor in line with a GPIO pin and the anode of the LED up to 3V3. The switches have a 1K resistor in series to a GPIO pin and the other side of the switch is taken to 0V. The GPIO is programmed to have an internal pull up resistor, reducing the amount of external hardware required.

LED and Switch Circuit

Power supply
The 5V power for the Raspberry Pi is supplied from a switch mode regulator, though more expensive than a 7805, it provides much longer battery life. It is pin compatible with a 7805 regulator, so a 7805 can be substituted if required.

Circuit for Regulated 5V Supply



System Application Software

Download
V1.00 2013-02-13 - Headless Pi application.

Download the application package here.

The application for the project consists of the following files:

README.txt            - Information about the package.
License.txt           - User license agreement.
License.dat           - License file.
HeadlessPi            - Linux application.
HeadlessPi.ini        - Application configuration file.
ArchInstall.sh        - Install script.
uninstall.sh          - Uninstall script.
HeadlessPi.service    - Install script.
RestartNetwork.sh     - Script to start network.

Place the application package into the /root/ directory. Then run the following commands at the terminal as root:
cd /root/
gunzip HeadlessPiDriver.tar.gz
tar -xf HeadlessPiDriver.tar
cd /root/HeadlessPiDriver/
chmod +x ArchInstall.sh
./ArchInstall.sh

The application has a configuration file HeadlessPi.ini. In this file the GPIO pins can be allocated to each function manually. This article describes the default settings for GPIO allocation.

Two network devices can be defined for displaying the IP address of. Also two partitions can be defined for displaying the free space of:

IP_1_NAME=eth0
IP_2_NAME=wlan0
DISK_PATH_1=/boot
DISK_PATH_2=/

Finally the levels for each of the status values can be defined for temperature, load average, free memory and swap space. DEFCON_1_* is the yellow LED, DEFCON_2_ is the red LED, DEFCON_3_ is strobe the red and blue LEDs and DEFCON_4_TEMP is to shut the system down at this level:

DEFCON_1_SYS_TEMP=50
DEFCON_2_SYS_TEMP=60
DEFCON_3_SYS_TEMP=70
DEFCON_4_SYS_TEMP=80

DEFCON_1_LOAD_AVG=100
DEFCON_2_LOAD_AVG=200
DEFCON_3_LOAD_AVG=400

DEFCON_1_FREE_MEM=100000
DEFCON_2_FREE_MEM=50000
DEFCON_3_FREE_MEM=1000

DEFCON_1_SWAP_USED=0
DEFCON_2_SWAP_USED=100000
DEFCON_3_SWAP_USED=200000


Pin Symbol Level Function
1 VSS - GND (0V)
2 VDD - Logic Power +5V
3 V0 - LCD Power
4 RS H/L H: Data - L: Command
5 R/W H/L H: Read - L: Write
6 E H/L Clock In Data
7 D0 H/L Data Lines
8 D1 H/L
9 D2 H/L
10 D3 H/L
11 D4 H/L
12 D5 H/L
13 D6 H/L
14 D7 H/L
15 A - Back Light Power +5V
16 K - Back Light Power 0V
PINOUT for Display Module RT204-1

Circuit for LCD Display

OBSERVATION: LCD Power Supply
Originally I planned to power down the LCD display with a single transistor by placing it on the 0V supply and switching it on and off. It appeared to work, but the display was still on just much dimmer. At first I thought the transistor was not fully switched off, however with some experimenting I discovered that somehow the circuits in the LCD module will use the data I/O lines as a power source when either 0V or 5V is switched off independently. So the only solution I found was to use two transistors and switch off both power supply lines at the same time.



OBSERVATION

GPIO 2 and GPIO 3 as INPUT/OUTPUT
While developing the project initially GPIO 2 was used for a switch and GPIO 3 was used for an LED. During an initial test it was found that the switch would only register when the LED was lit, the input value of the switch was correct during the period of the LED being lit, but always 0 when the LED was not lit. The GPIO lead where switched around so 2 was the LED and 3 was the switch, exactly the same effect occurred. So the GPIO of another LED was swapped with the GPIO for the switch, with both GPIO 2 and 3 being used as outputs they worked fine.

I have now found that because of the design of the processor, in order for the GPIO to have multiple functions on a pin, in the case of GPIO 2 and 3 using a 470R current limiting resistor instead of 1K should solve this issue.

RS232
When the Raspberry Pi boots up, the Linux Kernel uses the UART pins 14 and 15 on the GPIO as a serial terminal. The technical specification for an RS232 signal is between -15V to -5V for logic 1 and +5V to +15V for logic 0. Using a transistor it is possible to convert the UART levels to 0V and 5V, this is outside the specification of the RS232 standard, but I managed to receive the boot up messages on my desktop computer running MiniCom on Linux. Because this is outside the specification it should be considered unreliable, but I have included it in my project for experimental use.

Circuit for Experimental RS232



Configuring The OS
The operating system used for this project is Arch Linux, this was chosen as it boots very quickly and comes as a very light weight OS, with the option to install any software package required. The Arch Linux image is downloaded directly from the www.raspberrypi.org web site.

It is always a good idea to update the Linux OS as a first task when it is running on the Raspberry Pi. At a root command prompt run the following command:
pacman -Syu

This is all that is required to prepare the operation system for the application to be installed.

TIPS: Controlling The LCD
When updating a all lines of the LCD use the LCD command to switch off the display while updating the lines and then switch the display back on. This make the update look faster than it is. The switch off command does not turn off the back light.

When updating a few characters on the display, use a double buffering method and only update the characters which have changed. This will also make the display updates look faster.

Description Uptime
Device without Wifi adapter 6.25 Hours
Device with Wifi adapter 6 Hours
Battery life test for 6 x NiMH 2400mAh
Tested with Model B, for longer battery
life use Raspberry Pi Model A

Project Cost
Item Reference Qty Each Cost
Tactile switch 6x6mm - Square Button (Vertical) BitsBox 4 £0.20 £0.80
Caps for 6x6mm square button (Round) BitsBox 4 £0.09 £0.36
470R Resistor Carbon film 1/4W 5% BitsBox 4 £0.04 £0.16
1K Resistor Carbon film 1/4W 5% BitsBox 16 £0.03 £0.48
10K skeleton trimmer pot BitsBox 1 £0.12 £0.12
Kynar Wire - 5m length BitsBox 1 £1.55 £1.55
BC337 NPN Transistor BitsBox 3 £0.09 £0.27
BC327 PNP Transistor BitsBox 1 £0.09 £0.09
3mm Blue LED BitsBox 2 £0.30 £0.60
3mm Red LED BitsBox 1 £0.09 £0.09
3mm Yellow LED BitsBox 1 £0.10 £0.10
3mm Green LED BitsBox 1 £0.10 £0.10
Header Strip Right Angle 0.1" Pitch (36-way) BitsBox 1 £0.40 £0.40
Header Strip Straight 0.1" pitch (4-way) BitsBox 3 £0.08 £0.24
Single Row Sockets 0.1" pitch (14-way) BitsBox 2 £0.40 £0.80
Crimp Housing 0.1" Pitch (10-way) BitsBox 2 £0.39 £0.78
Crimp Housing 0.1" Pitch (6-way) BitsBox 2 £0.36 £0.72
Crimp Housing 0.1" Pitch (4-way) BitsBox 2 £0.30 £0.60
Crimp Housing 0.1" Pitch (2-way) BitsBox 1 £0.29 £0.29
Crimp sockets BitsBox 42 £0.06 £2.52
Stripboard 127 x 95mm 50 holes x 36 holes BitsBox 1 £1.59 £1.59
Pozi Pan Head Machine Screws M2.5 10mm BitsBox 2 £0.03 £0.06
Nuts M2.5 BitsBox 2 £0.02 £0.04
Washers M3 BitsBox 2 £0.025 £0.05
9-way chassis/shell mount D Connector plug BitsBox 1 £0.40 £0.40
BitsBox Shipping BitsBox 1 £1.75 £1.75
TSR 1-2450 RS 1 £5.95 £5.95
6AA Battery Case eBay 1 £6.70 £6.70
RT204-1 LCD Display eBay 1 £6.59 £6.59
Playing Card Case eBay 1 £0.99 £0.99
Plastic Snap Rivets 10 Pack Maplin 1 £1.49 £1.49
SUB TOTAL £36.68
Raspberry Pi Farnell (element 14) 1 £32.73 £32.73
4GB SD Card eBay 1 £3.19 £3.19
TOTAL £72.60

Loading...