+ All Categories
Home > Documents > FINAL INDIVIDUAL

FINAL INDIVIDUAL

Date post: 14-Feb-2017
Category:
Upload: william-duncan
View: 21 times
Download: 1 times
Share this document with a friend
111
The Design of a Raspberry Pi Based Temperature Sensor By William Duncan This project is submitted as partial fulfilment for the Honours degree of Bachelor of Engineering in Product Design and Development At the University of the West of Scotland School of Engineering, University of the West of Scotland, ___________________ High Street, William Duncan Paisley, B00207244 PA1 2BE 27 th April 2015
Transcript
  • The Design of a Raspberry Pi

    Based Temperature Sensor

    By

    William Duncan

    This project is submitted as partial fulfilment for the Honours degree of

    Bachelor of Engineering in

    Product Design and Development

    At the University of the West of Scotland

    School of Engineering,

    University of the West of Scotland, ___________________

    High Street, William Duncan

    Paisley, B00207244

    PA1 2BE 27th April 2015

  • i

    Acknowledgements

    I would firstly like to thank Dr James Thompson for his help and for supplying me with the

    materials required for this project despite his busy schedule.

    Secondly, Id like to thank Robert Boyce and the technicians of the School of Engineering for

    their unparalleled help and assistance throughout the year with this and my group project.

    Thirdly, thanks to Tom Caddell for his knowledge and guidance in all things technical

    whenever I was stuck.

    Next, to the online community who have supported not only my project but projects on a

    global scale on a daily basis; with expert knowledge and critical feedback.

    Lastly, to my wee maw, family, and the troops who have supported me throughout the past five

    years despite by bumpy journey.

  • ii

    Abstract

    Product Design is a significant part of technology; it is one of the key steps in many to create

    a brand new product. In its purest form; product design can be the answer to a flaw which

    requires redesigning, or it could just be an advanced idea that has the potential to either succeed

    or supersede its predecessor.

    Technology in general is innovating and expanding at an exponential rate. Our pockets are

    emptier, but the few items inside them can now do more than ever. Storage devices are

    significantly smaller, but they hold massive amounts of data. Current mobile phones on the

    market are no longer just phones anymore; they are portable computers which integrate media

    players, web browsers and instant messengers. Personal computers have evolved to laptops,

    which themselves have been innovated and developed into touch screen tablets, all within the

    past 15 years.

    This paper focuses on the design process of a new iteration of a product, a temperature sensor,

    with the incorporation of a 21st century innovation in technology the Raspberry Pi. Detailed

    accounts of the steps taken to configure the software, testing, hardware creation, and possible

    next steps will be identified and discussed throughout. The outcome of this dissertation is to

    construct a circuit, a suitable casing for the packaging of the device and screen, and then to

    prototype the design.

  • iii

    Copyright

    The copyright of this dissertation rests with the author. No quotation from it should be

    published without his prior written consent and information derived from it should be

    acknowledged.

  • iv

    Table of Contents

    Acknowledgements ..................................................................................................................... i

    Abstract ...................................................................................................................................... ii

    Copyright ................................................................................................................................. iii

    Table of Contents ...................................................................................................................... iv

    Nomenclature ......................................................................................................................... viii

    List of Figures ........................................................................................................................... ix

    List of Tables ............................................................................................................................ xi

    1. Introduction ............................................................................................................................ 1

    1.1 Background and Context.................................................................................................. 2

    1.2 Scope and Objectives ....................................................................................................... 3

    1.3 Achievements ................................................................................................................... 4

    1.4 Overview of Dissertation ................................................................................................. 4

    2. Literature Review and Similar Projects ................................................................................. 6

    2.1 What is the Raspberry Pi? ................................................................................................ 6

    2.1.1 History of the Raspberry Pi....................................................................................... 6

    2.1.2 Hardware and Specifications .................................................................................... 6

    2.1.2.1 GPIO .................................................................................................................. 7

    2.1.2.2 RAM, CPU and GPU ......................................................................................... 7

    2.1.2.3 Video Outputs .................................................................................................... 8

    2.1.2.4 Power ................................................................................................................. 8

    2.1.2.5 LEDs .................................................................................................................. 8

    2.1.2.6 USB and LAN .................................................................................................... 8

    2.1.2.7 SD Card .............................................................................................................. 9

    2.1.3 Operating System ...................................................................................................... 9

    2.2 Similar Projects .............................................................................................................. 10

    2.2.1 A Simple Temperature Sensor ................................................................................ 10

  • v

    2.2.2 Adafruit DHT Humidity Sensing ............................................................................ 11

    2.2.3 Raspberry Pi Temperature Sensor with LCD Display, Temperature Sensor and

    Receiver ........................................................................................................................... 12

    3. Methodology ........................................................................................................................ 14

    3.1 Planning ......................................................................................................................... 14

    3.2 Setting up the Raspberry Pi............................................................................................ 15

    3.2.1 Installation............................................................................................................... 15

    3.2.2 WiFi and VNC ........................................................................................................ 15

    3.3 Obtaining First Temperature Readings .......................................................................... 17

    3.3.1 DHT11 Sensor ........................................................................................................ 17

    3.3.2 Understanding the GPIO ......................................................................................... 18

    3.3.3 Code for First Temperature Reading ...................................................................... 19

    3.3.3.1 Relative Humidity ............................................................................................ 21

    3.3.3.2 Relative Temperature ....................................................................................... 22

    3.4 Display ........................................................................................................................... 22

    3.4.1 Display Size ............................................................................................................ 22

    3.4.2 MyPiFi LCD Add-on Board ................................................................................... 22

    3.4.3 Soldering ................................................................................................................. 23

    3.5 Temperature Sensor and Display Software.................................................................... 26

    3.5.1 DHT11 Temperature Sensor and Data Logging ..................................................... 26

    3.5.2 Display .................................................................................................................... 27

    3.5.3 Start-up Script ......................................................................................................... 28

    3.6 Online Data Logging...................................................................................................... 29

    3.6.1 PrivateEyePi ............................................................................................................ 29

    3.6.2 Twitter ..................................................................................................................... 32

    4. Testing.................................................................................................................................. 36

    4.1 Cooling Test ................................................................................................................... 36

  • vi

    4.2 Heating Test ................................................................................................................... 37

    5. Case Design ......................................................................................................................... 39

    5.1 Concept and Influence ................................................................................................... 39

    5.2 3D Modelling ................................................................................................................. 41

    5.3 Part Drawings................................................................................................................. 44

    5.4 Rapid Prototyping .......................................................................................................... 44

    5.4.1 Advantages of Rapid Prototyping ........................................................................... 44

    5.4.2 3D Printing .............................................................................................................. 45

    5.5 Case Revision 2.0........................................................................................................... 47

    5.6 Cost ................................................................................................................................ 48

    5.7 Manufacture ................................................................................................................... 49

    5. Reflection ............................................................................................................................. 51

    5.1 Programming and Testing .............................................................................................. 51

    5.2 Case Design ................................................................................................................... 53

    6. Conclusion ........................................................................................................................... 54

    6.1 Recommendations for Future Work............................................................................... 54

    6.1.1 Battery Power Source ............................................................................................. 54

    6.1.2 3G/4G WiFi Connection ......................................................................................... 55

    6.1.3 Possible Manufacture for Sale ................................................................................ 55

    6.1.4 Improving the Sensor Design.................................................................................. 55

    Bibliography ............................................................................................................................ 56

    Appendix 1 Code .................................................................................................................. 65

    dht11.c .................................................................................................................................. 65

    gpio_oi.c............................................................................................................................... 72

    Makefile ............................................................................................................................... 77

    minmax.awk ......................................................................................................................... 78

    savetemp.c ............................................................................................................................ 79

  • vii

    timed_wait.c ......................................................................................................................... 80

    tempsense ............................................................................................................................. 82

    displaytempsense.py ............................................................................................................ 83

    tweettempsense.py ............................................................................................................... 85

    Appendix 2 Test Data ........................................................................................................... 87

    Cooling Test ......................................................................................................................... 87

    Heating Test ......................................................................................................................... 88

    Appendix 3 Drawings ........................................................................................................... 89

  • viii

    Nomenclature

    GPIO = General Purpose Input / Output LAN = Ethernet

    LCD = Liquid Crystal Display OS = Operating System

    UK = United Kingdom PCB = Printed Circuit Board

    PHD = Doctorate of Philosophy TFT = Thin-film-transistor

    Pi = Raspberry Pi RF = Radio Frequency

    TV = Television MB/sec = Megabytes per second

    HD = High Definition GUI = Graphical User Interface

    = Pounds Sterling IP = Internet Protocol

    3D = Three-dimensional V = Volts

    USB = Universal Serial Bus % = Percentage

    Python = Python Programming

    Language mA = Milliamps

    C = C Programming Language Hz = Herts

    SD = Secure Digital Mm = Millimetre

    VNC = Virtual Network Computing K = Kilo

    Creo = PTC Creo GND = Ground

    CPU = Central Processing Unit VCC = Power Supply

    RAM = Random Access Memory C = Degrees Celsius

    SoC = System-on-chip UWS = The University of the West of

    Scotland

    MB = Megabyte Dr = Doctor

    GB = Gigabyte STL = Stereolithography

    RCA = Radio Corporation of America CAD = Computer Aided Design

    HDMI = High Definition Multimedia

    Interface CAM = Computer Aided Manufacture

    LED = Light Emitting Diode 3G/4G = 3rd/4th Generation

    API = Application Programming

    interface

  • ix

    List of Figures

    Figure 1 The BeetBox (Scott Garner, 2013) ........................................................................... 2

    Figure 2 Media Centre (Adam Shepherd, 2015) ..................................................................... 3

    Figure 3 Model B (vividvilla, 2013) ....................................................................................... 7

    Figure 4 Simple Temperature Sensor (Horan, 2013, p. 49 & 53) ......................................... 10

    Figure 5 Adafruit DHT Humidity Sensing (Ada, 2015, p. 5 & 6) ........................................ 11

    Figure 6 Pi, TFT, RF and Temperature Sensor (Williams, 2013) ........................................ 13

    Figure 7 Gantt Chart ............................................................................................................. 14

    Figure 8 8GB Micro-SD ....................................................................................................... 15

    Figure 9 Edimax WiFi Adapter............................................................................................. 16

    Figure 10 VNC in Action ...................................................................................................... 16

    Figure 11 DHT11 Sensor ...................................................................................................... 17

    Figure 12 GPIO Pin Layout (Ziegelwanger, 2013) .............................................................. 18

    Figure 13 DHT11 in GPIO ................................................................................................... 19

    Figure 14 DHTlib Example .................................................................................................. 21

    Figure 15 LCD Sizes ............................................................................................................. 22

    Figure 16 MyPiFi Board Kit (MyPiFi, 2014) ....................................................................... 23

    Figure 17 Soldering Kit (Google, 2015) ............................................................................... 24

    Figure 18 Soldering Snapshot ............................................................................................... 24

    Figure 19 Completed Soldering ............................................................................................ 25

    Figure 20 Soldering Check ................................................................................................... 25

    Figure 21 Working Display .................................................................................................. 29

    Figure 22 DHT22 Sensor ...................................................................................................... 29

    Figure 23 DHT22 Snapshot .................................................................................................. 31

    Figure 24 - PrivateEyePi .......................................................................................................... 32

    Figure 25 - @UWS_Pi Twitter ................................................................................................ 33

    Figure 26 Tweet Test ............................................................................................................ 34

    Figure 27 Twitter Temperature Tweets ................................................................................ 34

    Figure 28 Cooling Test ......................................................................................................... 36

    Figure 29 Cooling Graph ...................................................................................................... 37

    Figure 30 Heating Test.......................................................................................................... 37

    Figure 31 Heating Graph ...................................................................................................... 38

    Figure 32 Adafruit Case (Humpries, 2012) .......................................................................... 39

  • x

    Figure 33 Bramble LCD Case (bitcrafts, 2015) .................................................................... 40

    Figure 34 Conceptual Sketch ................................................................................................ 40

    Figure 35 Raspberry Pi Creo Model ..................................................................................... 41

    Figure 36 Component Modelling .......................................................................................... 42

    Figure 37 Component Assembly .......................................................................................... 42

    Figure 38 Reference Modelling ............................................................................................ 43

    Figure 39 Case Modelling ..................................................................................................... 43

    Figure 40 Case Component Assembly .................................................................................. 44

    Figure 41 SLT Part................................................................................................................ 45

    Figure 42 3D Printer ............................................................................................................. 46

    Figure 43 Printing Configuration .......................................................................................... 46

    Figure 44 Full Working Assembly ....................................................................................... 47

    Figure 45 Corrupt Display .................................................................................................... 51

    Figure 46 Case Bottom Drawing .......................................................................................... 89

    Figure 47 Case Top Drawing ................................................................................................ 90

    Figure 48 Case Side 1 Drawing ............................................................................................ 91

    Figure 49 Case Side 2 Drawing ............................................................................................ 92

    Figure 50 Case Side 3 Drawing ............................................................................................ 93

    Figure 51 Case Side 4 Drawing ............................................................................................ 94

    Figure 52 Component Assembly Drawing ........................................................................... 95

    Figure 53 Case Assembly Drawing ...................................................................................... 96

    Figure 54 Complete Assembly Drawing............................................................................... 97

    Figure 55 Case Bottom (Revision 2.0) Drawing .................................................................. 98

    Figure 56 Exploded Assembly .............................................................................................. 99

  • xi

    List of Tables

    Table 1 Cost of Prototype ..................................................................................................... 48

    Table 2 Cooling Test Data .................................................................................................... 87

    Table 3 Heating Test Data .................................................................................................... 88

  • 1

    1. Introduction

    The introduction provides the outline of scope and context of the project titled Raspberry Pi

    Based Temperature Sensor Design.

    Dr James Thompson, a senior lecturer within the School of Engineering, proposed this project.

    The successful development of this venture will enable a Raspberry Pi to control a temperature

    sensor with the inclusion of a screen display to highlight the surrounding temperature. The

    Raspberry Pi required various software packages and Python modules to be installed for the

    Raspbian Wheezy operating system to allow interactions with the GPIO utilised devices.

    Through a simplistic design, the project aims to develop the Raspberry Pi to a state which

    allows anyone to power up the Raspberry Pi with no commands or input required to generate

    a temperature reading. Ideally the final device will allow the user to record the temperature

    readings obtained either through an internal text log or transmission to an online source (if

    connected wirelessly to a network connection).

    Initially intended to be a group assignment, the project undertaken is to develop a temperature

    sensor using a new 21st century computing innovation, the Raspberry Pi microcomputer. With

    the model utilised in this project (Model B) having been released on the 5th September 2012

    (Raspberry Pi Foundation, 2012), research was conducted on: the device, supplied and required

    hardware (to ensure there were no compatibility issues), the operating system, the software

    available which would allow the device to interact with the sensor(s), and interaction with the

    GPIO (General Purpose Input / Output) pins.

    The GPIO on the Raspberry Pi is a collection of small pins which allows instruments and tools

    to be attached and controlled. The operating system can detect and be configured for either

    input or output; with this assignment making use of this to allow DHT temperature sensor(s)

    to provide data to the Pi whilst also employing a LCD display to present updated figures using

    the GPIO pins however there are many more devices and tools that exist.

  • 2

    1.1 Background and Context

    Since it was first announced; the Raspberry Pi has received a lot of attention, becoming

    the fastest-selling British computer (Raspberry Pi Foundation, 2015) with 5 million

    units sold worldwide as of February 2015.

    The concept of the Raspberry Pi was a brainchild of a UK based team from the

    University of Cambridges Computer Laboratory concerned with the decline in the

    number and skills of students applying for Computer Science degrees, during the course

    of their PHD (Eben Upton, 2014, pp. 1 - 3).

    Figure 1 The BeetBox (Scott Garner, 2013)

    Since its inception, a vast amount of people ranging from complete novices to

    technology enthusiasts have obtained Pis to program, control, and create various

    projects.

    These inventions span from wacky designs such as The BeetBox (an interactive drum

    kit made of vegetables via a capacitive touch sensor that connects to a Raspberry Pi,

    which sends signals to an amp inside a handmade wooden case as seen in Figure 1

    The BeetBox to practical ideas such as a Media Centre for a TV (which plays HD video

    content and streams online services such as Netflix highlighted in Figure 2 Media

    Centre .

  • 3

    Figure 2 Media Centre (Adam Shepherd, 2015)

    Basic temperature sensors with displays on the current market can cost between 10 to

    upwards of 100 (Ebay, 2015), with the inclusion of a data log increasing the cost of

    the unit to between 30 to 300 (LS Technology, 2015).

    This project makes use of the Raspberry Pi Model B retailing at 25 as of January

    2015 (Allied Electronics, 2015) and a small number of accessories which includes:

    temperature sensor(s), an LCD display (including a MyPiFi LCD board kit) and a USB

    Wi-Fi connection, all of which can be purchased for under 25 to turn the Raspberry Pi

    into a temperature sensor capable of reading and displaying the current temperature and

    recording the data obtained in real time. This design will be encased in a 3D printed

    rapidly prototyped suitable casing.

    In comparison to a typical digital temperature sensor; the Raspberry Pi has the option

    of using different types of sensors and connection methods. The Raspberry Pi also

    contains functionality to log data for future reference and performance of actions based

    on data readings. This could be useful for monitoring the temperature of a space, for

    example, a room filled with computers servers that may have to be observed for rises

    in temperature to prevent overheating and potential damage.

    1.2 Scope and Objectives

    Using the Raspberry Pi credit card sized microcomputer; the overall goal of this project

    was to develop a temperature sensor. The project included the research and

    development of software for the Raspberry Pi by employing the Python programming

    language and a variety of downloadable modules readily available for the Python

    program to allow interaction with the GPIO sensor(s) such as the temperature

    sensor(s) and the GPIO outputs (the LCD display).

  • 4

    This would allow the Raspberry Pi to detect and display the temperature within the

    location it was stored in whilst potentially recording the data obtained for reference.

    The planned program would automatically initiate from powering up the Raspberry Pi

    without the requirement of user input.

    The final planned project includes a working temperature sensor, consisting of a

    Raspberry Pi connected to a LCD display, with a 3D printed casing for the unit, sensor

    and display. The Raspberry Pi contains an SD card slot which holds an SD card

    containing the Raspbian Wheezy operating system and the project software. By

    powering up the unit, the required commands will be executed to run the developed

    software.

    1.3 Achievements

    Developments which have occurred throughout the duration of this project include:

    Appreciation for the importance of time management

    Learning about the Raspbian operating system, LXTerminal, and how to use it

    Knowledge of how to connect to the Raspberry Pi Remotely (using VCN)

    Understanding basic circuitry and learning how to solder at a fundamental level

    Interpretation of the Python and C programming language modules and

    packages required to interact with the GPIO pins and to obtain readings from

    the sensor(s), display the output, and connect to online sources

    Utilizing advanced functions in Creo to develop a practical case for the

    temperature sensor and generating a rapid prototype of the design

    The overall achievement from this project is a Raspberry Pi configured with suitable

    software and hardware to allow the recording and display of data using a temperature

    sensor encased within a rapidly prototyped container.

    1.4 Overview of Dissertation

    The paper contains seven different chapters which provide an explanation of the project,

    discussion of the development, testing of the product, rapid prototype development, and

    the potential future improvements.

    Chapter 1 acts as an introduction to the project, the background and what the project

    has provided, the goals and scope, and the overall achievements of the assignment.

  • 5

    Chapter 2 contains a description of the Raspberry Pi, review of projects in the same

    area and how they differ from this project, including a brief description of some of the

    hardware used by this and similar projects.

    Chapter 3 provides a description of: the planning of the project, software and hardware

    utilised to achieve the goal of creating a temperature sensor using the Raspberry Pi, and

    what each software package is used for.

    Chapter 4 includes the testing of the project software and analyses results obtained.

    Chapter 5 discusses the use of Creo and rapid prototyping to design the case.

    Chapter 6 reflects on the overall project and issues which occurred throughout.

    Chapter 7 supplies the conclusion and discusses potential future work for the project.

  • 6

    2. Literature Review and Similar Projects

    This chapter describes the Raspberry Pi, reviews similar projects which have implemented

    temperature sensors, how they differ, and the hardware used both within those and this

    enterprise.

    2.1 What is the Raspberry Pi?

    The Raspberry Pi series is a succession of small, credit-card sized microcomputers

    initially developed and released by the registered charity The Raspberry Pi Foundation

    in 2012. The single boarded computer was developed with the aim of teaching the

    basics of computer science and programming to school students worldwide (The

    Raspberry Pi Foundation, 2015).

    Although a microcontroller similar to that of the Arduino (Arduino, 2015) which is

    popular for prototyping projects the Raspberry Pi differs in that it acts more of a

    computer rather than just a microcontroller.

    2.1.1 History of the Raspberry Pi

    The development of the Raspberry Pi dates back to 2006. With a realization in

    the decline in both the skill and number of students applying for computer

    sciences; a team of university students from the University of Cambridge

    studying for their PHD (consisting primarily of Jack Lang, Eben Upton and

    Alan Mycroft) within the Computer Laboratory decided to develop and create a

    cheap, small, effective system. The planned system would allow for easy access

    for school students into the world of computing; leading to the aim of improved

    education in their field for students worldwide.

    With the initial concepts for the unit being prototyped between 2006 2008, the

    first low priced, credit-card sized microcomputer was released early 2012 the

    Raspberry Pi Model A (Eben Upton, 2014, pp. 3 - 8).

    2.1.2 Hardware and Specifications

    At the commencing of this project there were three revisions of the Raspberry

    Pi; Model A, Model B (released late 2012) and Model B+ (released early 2014).

    In February 2015, the Raspberry Pi 2 was announced (Lester Haines, 2015).

  • 7

    Each Raspberry Pi is similar in design, however, with each new revision comes

    various changes such as increased; CPU power, RAM size, GPIO pins, Ethernet

    ports, USB slots, and price.

    Figure 3 Model B (vividvilla, 2013)

    The Raspberry Pi supplied by Dr James Thompson and focused on in this

    enterprise is Model B. This revision of the Raspberry Pi is represented in Figure

    3 Model B . The features of this version are discussed in the following

    segments (Eben Upton, 2014, pp. 14 - 18).

    2.1.2.1 GPIO

    Located at the top left of the Pi are a series of pins which compose the

    general-purpose input-output (GPIO) header, which can be used to

    connect other hardware to the Raspberry Pi. Different devices and add-

    on boards can be connected to these pins.

    Great care must be taken when handling the Pi as to not damage the pins

    as the GPIO port is extremely powerful and, without these pins, certain

    elements of the Pi are redundant. The GPIO pins will be discussed

    further in later chapters.

    2.1.2.2 RAM, CPU and GPU

    In the centre of all Raspberry Pi boards lie integrated semiconductors

    (circuits or chips). This is the processor, a Broadcom BCM2835 SoC

    (system-on-chip) which embodies an ARM1176JZF-S CPU core.

  • 8

    This provides the Pi with its general purpose processing, graphical

    rendering and input / output capabilities. On top of the chip is another

    semiconductor which provides memory (512MB) for temporary storage

    of data while running programs this is also known as random access

    memory (RAM).

    2.1.2.3 Video Outputs

    Below and above the SoC are the video outputs. The RCA (Radio

    Corporation of America) video connector is a video port which is

    primarily used to connect to older generation televisions which may not

    have HDMI sockets. This provides low quality video and does not

    provide audio; hence why a 3.5mm audio jack is provided to the right of

    the RCA video output.

    The HDMI (High Definition Multimedia Interface) port is most

    commonly utilised, given that many of todays media sources employ

    this type of connection. When connected to a monitor or modern TV,

    the HDMI port allows for high-resolution video and digital audio.

    2.1.2.4 Power

    Unlike a laptop or desktop computer, the Pi does not have a power

    switch. At the bottom left of the unit is the Pis power supply a micro

    USB socket. This type of connection is typically found in the majority

    of modern tablets and smartphones. Upon connecting a micro USB cable

    with a suitable power adapter, the Raspberry Pi will start instantly when

    power is connected.

    2.1.2.5 LEDs

    In the top right hand corner of the Pi are a series of Light Emitting

    Diodes (LEDs), which are marked with different labels which provide

    activity (ACT) and power (PWR) notifications.

    2.1.2.6 USB and LAN

    On the right hand edge of the board are two USB (Universal Serial Bus)

    ports, which provide space for two hardware interfaces. This is the same

    type of port found on desktop and laptop computers and allows the Pi to

    be connected to any USB-compatible peripherals.

  • 9

    An Ethernet (LAN) port for connecting the Pi to a wired network is also

    present allowing the unit to access the internet and other devices on

    the same network to access the Pi. This can also be done wirelessly and

    will be discussed later.

    2.1.2.7 SD Card

    The underside of the board (left hand side) holds an SD (Secure Digital)

    card slot. This allows the insertion on an SD card which acts as the

    storage for the operating system, data, programs, and other files.

    2.1.3 Operating System

    The Raspberry Pi primarily uses Linux-kernel-based operating systems (OS).

    Unlike Windows and MAC OS; Linux based systems are assembled under the

    model of free and open-source software development and distribution (Linux,

    2009).

    The install manager for the Pi is NOOBS and can be obtained from The

    Raspberry Pi Foundations website (The Raspberry Pi Foundation, 2015).

    NOOBS contains different operating system packages (images) which can be

    installed to the Raspberry Pi.

    The OS installed in this project was Raspbian (Debian Wheezy) which supports

    both Pi versions 1 and 2. Raspbian is heavily based on Debian; Debian is a free

    operating system for your computer and includes the basic set of programs and

    utilities that make your computer run along with many thousands of other

    packages (Raspbian, 2015).

    Raspbian is the most common operating system used in conjunction with the

    Raspberry Pi due to being regarded as stable, high-quality, and scalable with an

    extensive online community for help and support.

  • 10

    2.2 Similar Projects

    The online community continuously share and modify different Raspberry Pi ventures

    every day; this section explores similar temperature sensor schemes, as well as the

    hardware and software developed within them.

    2.2.1 A Simple Temperature Sensor

    Projects similar to the work presented in this project include Brendan Horans

    A Simple Temperature Sensor (Horan, 2013, pp. 37 - 60). In this development

    the author connects the Raspberry Pi Model B to two different temperature

    sensors the DS18B20 and the DHT11 using the GPIO pins through a

    breadboard. Both configurations can be seen in Figure 4 Simple Temperature

    Sensor.

    Breadboards are solderless construction bases used for prototyping in

    electronics. This means that the GPIO pins of the Pi are plugged into the

    breadboard as opposed to connections being directly soldered to the pins. This

    allows for trial and error based scenarios and software or hardware testing.

    Figure 4 Simple Temperature Sensor (Horan, 2013, p. 49 & 53)

    Given that two temperature sensors can be used interchangeably by the

    Raspberry Pi highlights the flexibility in its design. As breadboards were used,

    other parts such as different resistors, jumper wires and hook-up wires were

    required. The DS18B20 temperature sensor circuit was setup using both a

    standard mode and a parasitic mode. The author makes use of various

    modules to obtain temperature values and sets up the program in order for the

    DS18B20 to be detected and operate from the start-up of the Raspberry Pi.

  • 11

    Horan does note that, despite not including it within his program at this point of

    testing, a simple script to monitor the sensor or log the values to a file could

    be implemented. A script such as the one described would allow for records or

    logs of recorded temperature values.

    Horan then goes on to implement the DHT11 temperature sensor. Unlike the

    DS18B20, the DHT11 sensor is also capable of recording the relative humidity.

    Software from the Adafruit website is used in this example and the source code

    from it is configured to suit the authors requirements. The author notes that,

    due to data time constraints in the DHT11, problems arise if requests for data

    from the DHT11 arrive between 0 and 2 seconds; meaning the DHT11 is time

    critical. The DHT11 temperature sensor was supplied by Dr James Thompson

    with the intention of being included in the project design and this will be

    discussed later.

    2.2.2 Adafruit DHT Humidity Sensing

    In the previous section it was highlighted that the Horan extracted software from

    a website named Adafruit. Adafruit was founded in 2005 by Limor Ladyada

    Fried; with the goal of creating the best place online for learning electronics

    and best designed products for makers of all ages and skill levels (Adafruit,

    2015). Adafruit have different experiments and developments for Arduino

    microcontrollers and Raspberry Pis. One development on the website focuses

    on the use of DHT temperature sensors realised on either a Raspberry Pi or a

    Beaglebone black a low-power, open-source hardware single-board computer

    similar to the Raspberry Pi (BeagleBoard, 2015).

    Figure 5 Adafruit DHT Humidity Sensing (Ada, 2015, p. 5 & 6)

  • 12

    In this example, titled DHT Humidity Sensing on Raspberry Pi or Beaglebone

    Black with GDocs Logging (Ada, 2015), the DHT11 and DHT22 temperature

    and humidity sensors are implemented using a breadboard coupled with an

    Adafruit Pi Cobbler (as can be viewed in Figure 5 Adafruit DHT Humidity

    Sensing ). The Adafruit Pi Cobbler is a breakout kit for the Raspberry Pi which

    allows the user to make use of a ribbon-type cable to connect the GPIO pins to

    the custom Adafruit PCB (Printed Circuit Board). This is used in conjunction

    with a breadboard allowing connection to specific GPIO pins and again is an

    alternative to soldering directly to the Pis pins. The software used allows for

    both temperature and humidity values to be displayed. Ada does note that

    similar to Horans results due to limitations in the sensors used and delays in

    data transmission, potential errors can occur, resulting in the program having to

    be ran until values are obtained.

    Differing from the Simple Temperature Sensor, Ada then proceeds to develop

    code which allows for the data attained from the DHT sensors to be transmitted

    to Google Docs. Google Docs is an online word processor that lets you create

    and format text documents and collaborate with other people in real time

    (Google, 2015). Using a Google email address and password, Ada produces a

    spreadsheet which is updated every 30 seconds directly online to Google Docs

    with measurements added in real-time.

    This type of data recording would be potentially useful if the user requirement

    was to monitor the temperature from a different location, such as monitoring

    the temperature in a computer server room out with working office hours from

    home. The DHT22 and data logging are features which are later explored by the

    author.

    2.2.3 Raspberry Pi Temperature Sensor with LCD Display,

    Temperature Sensor and Receiver

    The previously reviewed projects demonstrate using different temperature

    sensors with the Raspberry Pi, however, data output is either displayed on the

    monitor used to access the Pi or online not on an independent display.

  • 13

    The project self-titled Raspberry Pi 1.8 TFT, RF Receiver and Temperature

    Sensor provides an example of the temperature sensor coupled with an LCD

    (liquid-crystal-display) (Williams, 2013). Williams equips the Raspberry Pi

    with a small TMP102 digital temperature sensor and a TFT (Thin-Film-

    Transistor) LCD display using software adopted and altered from the Adafruit

    website. This can be observed in Figure 6 Pi, TFT, RF and Temperature

    Sensor .

    Figure 6 Pi, TFT, RF and Temperature Sensor (Williams, 2013)

    The software used allows the user to record and store a data log of up to 7 days

    worth of data, after which the user is prompted to delete records to prevent the

    memory of the SD card filling. The display indicates:

    The current date and time

    The last recorded temperature (polled every 5 minutes)

    Graphs of recorded temperature for the last 12 hours, 24 hours, and 7

    days

    Williams also applies an RF (Radio Frequency) receiver to the build which,

    upon pressing either buttons A, B, C or D, controls the display and the type of

    graphed data shown. Graphed recorded data is not a requirement for this

    enterprise, however, the inclusion of the data and time could be implemented.

    The use on an LCD display and the information shown will be discussed later.

  • 14

    3. Methodology

    This chapter provides insight into the planning of the project and a description of the process

    of utilising the software and hardware to create the temperature sensor using the Raspberry Pi.

    All python and C script coding used in this project can be found in Appendix 1 Code.

    3.1 Planning

    In order to complete a project successfully, a number of activities must be controlled to

    ensure they are completed on schedule. If deadlines are missed or tasks remain

    unfinished, there could potentially be knock-on effects on the rest of the project. In a

    working environment; this could result in late deliverables which may have

    consequential negative costs. As a result of being the leader of a group project, an

    individual dissertation, and having modules coursework and exams; the author opted at

    the beginning of this enterprise to implement a project Gantt chart. Gantt charts outline

    all of the tasks involved in a project, and their order, shown against a timescale (Mind

    Tools Ltd., 2015). An example of the Microsoft Excel Gantt chart used in this project

    can be viewed in Figure 7 Gantt .

    Figure 7 Gantt Chart

    The Gantt Chart allowed the segregation of class, group and individual dissertation

    work which allowed the author to plan objectives and monitor progress throughout the

    year. If at any point work was behind schedule, the Gantt chart was reworked to

    incorporate these changes to ensure that the overall workload remained constant as well

    as bringing any lagging tasks back on course.

    For this project in particular; the focus was firstly on obtaining temperature readings,

    second the display, third data logging, and lastly the case design.

  • 15

    3.2 Setting up the Raspberry Pi

    This section describes the steps taken to initially set up the Raspberry Pi.

    3.2.1 Installation

    The equipment supplied by Dr James Thompson included an 8GB SD card with

    an outdated version of the Raspbian Wheezy OS pre-installed. The author opted

    to remove this in place for an updated version of the Raspbian OS on a smaller

    8GB Micro-SD card (evident in Figure 8 8GB Micro-SD). This was achieved

    by formatting the SD card to remove all files associated with the old OS in place

    for a new installation. An updated image of the OS was obtained from the

    Raspberry Pi website (The Raspberry Pi Foundation, 2015) and copied to the

    SD card on a laptop.

    Figure 8 8GB Micro-SD

    The SD card was then inserted into the Pi. With a powered USB hub, keyboard,

    mouse, and TV screen connected through an HDMI cable in place; the

    installation of the OS began. At a rate on 0.5 MB/sec and a file size of 2349

    MB; the installation lasted for approximately an hour. Once installed, the

    system prompted for the insertion of a default username and password

    configured to pi and raspberry respectively. The author also changed the

    configuration of the Raspberry Pi start up to allow the GUI (Graphical User

    Interface) to automatically boot up.

    3.2.2 WiFi and VNC

    Using an Edimax WiFi Nano adapter (Figure 9 Edimax WiFi Adapter), a WiFi

    connection was formed to allow internet access to the Pi. This connection

    permits the Pi to download appropriate software and keep up to date.

  • 16

    Figure 9 Edimax WiFi Adapter

    Despite having a USB hub, keyboard, mouse and TV; to allow the author to

    work on the Pi through a laptop, a VNC (Virtual Network Computing)

    connection was programmed into the Pi. This permits any devices connected

    over the same network to link together. Following a tutorial through eLinix.org

    (eLinux.org, 2014) an online resource for developers using Linux embedded

    systems a VNC server was added to the Raspberry Pi. When prompted for an

    eight character password to secure the network connection, the author entered

    raspberr.

    On the authors laptop, software capable of connecting to the Raspberry Pi

    Real VNC Viewer (Real VNC, 2015) was then downloaded. By inserting the

    corresponding IP (Internet Protocol) address of the Pi into Real VNC Viewer; a

    connection between the authors laptop and the Pi was established. This

    provides the laptop full control of the Pi and also acted as a means for the author

    to screenshot work done on the Pi. The Pi GUI displayed on the laptop can be

    viewed in Figure 10 VNC in Action.

    Figure 10 VNC in Action

  • 17

    3.3 Obtaining First Temperature Readings

    The following explains the process of obtaining temperature readings using the DHT11

    sensor connected to the Raspberry Pi.

    3.3.1 DHT11 Sensor

    The DHT11 is a low cost temperature and humidity sensor consisting of a

    capacitive humidity sensor and a thermistor along with a basic chip which

    supplies an analog to digital signal output with the temperature and humidity.

    The specifications of the sensor are as follows (D-Robotics UK, 2010):

    Ultra low cost 1.79 from eBay (eBay.co.uk, 2014)

    3 to 5.5V power and O/I

    2.5mA max current use during conversion (while requesting data)

    Good for 20% - 90% humidity readings with 5% accuracy

    Good for 0 50C temperature readings 2C accuracy

    No more than 1Hz sampling rate (once every second)

    Body size 15.5mm x 12mm x 5.5mm

    4 pins with 0.1 spacing

    Typically, DHT11 sensors are connected to the Pi through the use of

    aforementioned breadboards, Adafruit Pi Cobblers, resistors, and jumper wires;

    however, the DHT11 sensor supplied by Dr James Thompson came on a PCB

    inclusive of a 10K resistor and three pins (as seen in Figure 11 DHT11

    Sensor).

    Figure 11 DHT11 Sensor

  • 18

    The first pin (GND) is the ground pin, second is the data pin, and third pin

    (VCC) is the power supply pin. This allowed the author to connect the DHT11

    sensor directly to the corresponding Pi GPIO pins using only female-to-male

    jumper wires.

    3.3.2 Understanding the GPIO

    As previously mentioned; the GPIO is used to connect hardware to the Pi in

    this case the DHT11 with each GPIO pin offering different input and outputs.

    Figure 12 GPIO Pin Layout (Ziegelwanger, 2013)

    The revision of the GPIO pins is dependent on the revision of the Raspberry Pi

    the layout for model B being revision 2.0. Figure 12 GPIO Pin Layout

    represents GPIO revision 2.0 and highlights each pin with a corresponding pin

    number and name. For the purposes of this section, the pins used are 1 (3V3), 7

    (GPIO 4), and 9 (GND) although other pins can be used.

  • 19

    Figure 13 DHT11 in GPIO

    GPIO pin 1 (3V3) provides a constant output voltage of 3.3V which is a

    sufficient minimum voltage for the operation of the DHT11 sensor using the

    VCC pin. Pin 7 (GPIO 4) is a general purpose input and output pin suitable for

    systems which are time sensitive (such as the DHT11) acting as an input as a

    result of data incoming from the DHT11 data pin. Pin 9 (GND) connects to the

    corresponding ground pin of the DHT11. This setup is represented in Figure 13

    DHT11 in GPIO.

    3.3.3 Code for First Temperature Reading

    Github.com is a web-based Git repository hosting service. Git is a free and

    open source distributed version control system designed to handle everything

    from small to very large projects with speed and efficiency (Github, 2014). Git

    is used by companies such as Google, Facebook, Microsoft and Twitter. Git

    allows users to acquire code for projects from online libraries. After searching

    Github, in order to obtain temperature readings, a suitable C library was

    obtained named DHTlib. C is a high-level and general purpose programming

    language that is ideal for developing firmware or portable applications

    (Janssen, 2015).

    DHTlib is a C library that can be used to read the DHT temperature and

    humidity sensors an Single Board Computers running Linux (Wisniewski,

    2014). DHTlib supports the DHT11 sensor as well as the DHT22, AM2302,

    and RHT03 and can automatically detect the sensor through the GPIO pins.

  • 20

    The DHTlib library was obtained by executing commands in the LXTerminal.

    LXTerminal is a terminal emulator for the Raspberry Pi GUI used for operations

    and commands. The commands used to install DHTlib and a description of

    their actions are as follows:

    git clone https://github.com/ondrej1024/foxg20 the git clone

    command copies the source code from Github within a specified

    repository

    cd dhtlib cd is used to change the current working directory to the

    one specified

    make make is used to determine automatically which pieces of a

    program need to be recompiled, issues commands to recompile them and

    builds the library

    sudo make install sudo allows a permitted user to execute a command

    as the superuser. A superuser has special privileges needed to administer

    and maintain a system. make install installs the library, executable

    commands and other required files created during the make step

    Once installed, the author again executed commands to build the appropriate

    program:

    cd dhtlib/example as previously mentioned

    make as previously mentioned

    Lastly, the program was run using:

    sudo ./dhtsensor DHT11 4 ./dhtsensor runs the desired program of

    the same name located within the working directory. DHT11 is used

    by the program to help and automatically identify the sensor using the

    GPIO pins and 4 tells the program which GPIO pin the data pin of the

    DHT11 is connected to in this case GPIO 4 (or pin 7)

    Figure 14 DHTlib Example highlights the aforementioned commands being

    entered to the LXTerminal and the results obtained.

    https://github.com/ondrej1024/foxg20

  • 21

    Figure 14 DHTlib Example

    The first two readings generate the output Error reading sensor: TIMEOUT.

    This was a result of the author accidently connecting the data pin of the DHT11

    to the GND GPIO header and the ground pin to GPIO 4 header.

    This error was corrected and the program run again which yielded a result of

    Rel. Humidity: 38.0% - Temperature: 21.0 C. This result was expected

    considering the room temperature environment. The DHT sensor series records

    both relative humidity and relative temperature.

    3.3.3.1 Relative Humidity

    Relative humidity is the ratio of the amount of water vapour in the air

    at a specific temperature to the maximum amount that the air could hold

    at that temperature, expressed as a percentage ( The Free Dictionary,

    2011).

    Humans are sensitive to humidity as the skin relies on air to get rid of

    moisture. If the relative humidity is 100%, sweat from human skin will

    not evaporate resulting in people feeling hotter than the actual

    temperature. On the contrary; if the relative humidity is low, people will

    feel cooler than the actual temperature.

  • 22

    3.3.3.2 Relative Temperature

    Relative temperature is a temperature scale consisting of both positive

    and negative values such as the Celsius and Fahrenheit scales. This

    project uses degrees Celsius.

    3.4 Display

    The section to follow discusses the actions taken to build and configure a working

    visual display for the Raspberry Pi based temperature sensor.

    3.4.1 Display Size

    As part of the kit provided with the Raspberry Pi at the beginning of this project;

    the author was initially supplied with a HD44780 20 x 4 character LCD display

    to use as part of the project. As can be seen in Figure 15 LCD Sizes, the 20 x

    4 LCD display (centre) is larger than the Raspberry Pi in dimensional size.

    Figure 15 LCD Sizes

    Given that the minimum the display would be showing would be the

    temperature and humidity values, and the maximum an inclusion of the date and

    time; the author opted to purchase a HD44780 16 x 2 LCD to keep the design

    as compact as possible. The 16 x 2 LCD is significantly smaller than the 20 x 4

    evident at the right of Figure 15 LCD Sizes.

    3.4.2 MyPiFi LCD Add-on Board

    While researching methods to connect the HD44780 16 x 2 LCD display to the

    Pi, a related Kickstarter project was noticed. Kickstarter is the worlds largest

    funding platform for creative projects (Kickstarter.com, 2015) and includes

    millions of projects covering art, gaming, hobbies, and technology.

  • 23

    The MyPifi LCD add-on board, as seen in Figure 16 MyPiFi Board Kit

    created by Paul Brown (Paul Brown, 2014), is an add-on board for the

    Raspberry Pi which supports both 20 x 4 and 16 x 2 HD44780 LCD displays.

    The idea was conceived by Brown as a result of using a fiddly breadboard

    where wires kept coming out on their own accord (MyPiFi, 2014).

    Figure 16 MyPiFi Board Kit (MyPiFi, 2014)

    The kit comes unassembled, requires soldering, and includes: the MyPiFi PCB,

    a GPIO pin header extension, 16 pin insert strip, and a variable resistor. The

    GPIO pin header extension allows access to the GPIO pins which are not in use

    for the LCD display to operate leaving adequate pins available for the

    operation of the DHT11 sensor. The variable resistor controls the brightness of

    the LCD display.

    3.4.3 Soldering

    With the purchase of the MyPiFi board, work began on soldering the

    components together. Following recommendations from the Adafruit Guide to

    Excellent Soldering (Bill Earl, 2014); the author purchased a soldering kit

    (Figure 17 Soldering Kit ) from eBay (eBay.com, 2014) which included:

    25W soldering iron with 1mm conical pointed tip

    Helping hands with magnifier

    Soldering iron stand with tip cleaning sponge

    De-soldering pump tool and de-solder braid

    Solder (tin 60% / lead 40%)

  • 24

    Figure 17 Soldering Kit (Google, 2015)

    Having never soldered before, the author used the Adafruit Guide to Excellent

    Soldering as a reference. No formal risk assessment was completed as all

    soldering work was completed at the authors residence, however, the author

    ensured that the area had sufficient ventilation and that a dust mask was worn.

    This was to prevent inhalation of any poisonous lead fumes from the solder

    during and after soldering.

    Figure 18 Soldering Snapshot

    Figure 18 Soldering Snapshot highlights the in-progress soldering of the

    MyPifi board clamped in to the Helping hands. Care was taken to ensure each

    solder met the standards outlined in the guide and that after each solder, the tip

    of the soldering iron was cleaned using a damn sponge to remove excess solder.

  • 25

    Given that this was a first attempt, mistakes occurred. Any mistakes were

    resolved by utilising the de-soldering pump which, when used, removed any

    excess solder from the soldering joint.

    Once the MyPifi add-on board was completed, a 16 pin header strip was

    soldered to the 16 x 2 LCD display. This allows the quick addition and removal

    of the display to the MyPiFi board without making it a permanent attachment.

    The total soldering process lasted approximately three and a half hours.

    Figure 19 Completed Soldering

    The fully soldered and assembled MyPiFi board with the LCD attached can be

    seen in Figure 19 Completed Soldering. The assembly was then plugged into

    the Pi GPIO pins and powered on. As a result of successful soldering work, the

    display worked evident in Figure 20 Soldering Check.

    Figure 20 Soldering Check

  • 26

    3.5 Temperature Sensor and Display Software

    This segment discusses the software modules used and developed for the DHT11 sensor

    and LCD display.

    3.5.1 DHT11 Temperature Sensor and Data Logging

    By searching Github.com for alternative DHT11 sensor programs; the author

    found another Git repository for the DHT11 sensor being used with the

    Raspberry Pi (Warren Gay, 2014). This source code is linked to the section

    DHT11 Sensor of the book Mastering the Raspberry Pi by Warren Gay (Gay,

    2014, pp. 263 - 273). This was obtained by entering the following commands

    into the LXTerminal:

    git clone https://github.com:ve3wwg/raspberry_pi/dht11.git

    make

    The source code consists of:

    dht11.c a C script providing direct GPIO access to read the DHT11

    humidity and temperature sensor

    gpio_oi.c a C script which configures the GPIO pins and is used within

    the dht11.c script

    makefile a C script which organises and provides superuser privileges

    to the scripts in the same directory to allow them to operate with the Pi

    timed_wait.c a C script which implements a precision timed wait

    allowing the time sensitive DHT11 sensor to operate properly

    Similar to the software utilised earlier, this library allows the user to obtain

    readings for the relative humidity and temperature. The difference is that the

    new library is built solely for use with the DHT11 sensor and does not require

    the sensor or pin number to be specified when executing the software to obtain

    readings. Readings are taken every 1 2 minutes.

    Next, attention turned to the logging of data readings obtained from the DHT11

    sensor. Stackoverflow.com is a question and answer site for professional and

    enthusiast programmers (Stack Exchange Inc., 2015) and questions previously

    asked and answered were used to help create and validate the appropriate C

    script.

    https://github.com:ve3wwg/raspberry_pi/dht11.git

  • 27

    The script logs the temperature and humidity to a current and local log file each

    time a value is recorded by the DHT11 (Stack Overflow, 2015) this was saved

    in the DHT11 directory and named savetemp.c.

    The C scripts in the DHT11 directory where then compiled into one executable

    file (Tips for Linux, 2015). This was achieved by executing the following

    commands in the LXTerminal:

    cd /home/pi/DHT11

    gcc o dht11 dht11.c gpio_oi.c timed_wait.c savetemp.c gcc merges

    and compiles all declared scripts into one executable object. dht11 was

    the name given to the executable object. dht11.c gpio_oi.c timed_wait.c

    savetemp.c are the declared C scripts the user wants to compile

    3.5.2 Display

    Software for the HD44780 16 x 2 LCD was then researched. PenguinTutor.com,

    a website of open source software tutorials (Watkiss, 2014), provides

    information on programming an LCD character display on the Raspberry Pi

    (Watkiss, 2014). The python script requires an additional module to be installed

    to the Pi, completed by entering into the LXTerminal:

    sudo pip install RPLCD pip is a tool for installing and managing

    Python packages in this case the installation of RPLCD

    The python script was created using the PenguinTutor.com tutorial. The LCD

    display first reads Visit @UWS_Pi on the first line and TEMP & HUMID

    on the second line for five seconds. @UWS_Pi was the intended twitter handle

    for a twitter account which was potentially going to be used to display updated

    temperature and humidity values through a series of tweets and is something

    which will be discussed later.

    Following this, the script shows the current date and time on the first line, and

    then pulls information from the updated log file and displays it on the LCD

    display on the second line temperature first and humidity second. The readings

    update in accordance with the current log file (1 2 minutes). This Python script

    was saved as displaytempsense.py and saved in the same directory as the

    dht11 executable file.

  • 28

    3.5.3 Start-up Script

    The author opted to start the DHT11, data logging, and display software in the

    background as a service and from the initial boot up of the Raspberry Pi. This

    was achieved by developing a shell script. A shell script is a text file that

    contains a sequence of commands for UNIX-based operating system(s)

    (Allsup, 2006). Shell scripts combine a sequence of commands into one file to

    prevent the user from having to repetitively execute individual commands in the

    LXTerminal.

    Using logic obtained from an online blog post (Philips, 2013); the author

    generated a shell script which calls for the dht11 executable file and

    displaytempsense.py Python script upon start-up of the Raspberry Pi this

    was saved as tempsense (temperature sensor). For the script to work, the

    permissions of dht11 and displaytempsense.py had to be changed to granted

    as executable by the LXTerminal. This was achieved by typing the commands:

    sudo chmod 755 dht11

    sudo chmod 755 displaytempsense.py

    Where chmod allows the permissions to be changed and 755 are the read,

    write, and execute permissions for the user, group and work.

    Once the appropriate permissions were in place; the shell script tempsense was

    then moved to the directory etc/init.d/ which is the directory in the Raspberry

    Pi for any start-up scripts by commanding:

    sudo cp tempsense.sh /etc/init.d cp being the command to copy to

    the specified directory and /etc/init.d being the intended directory

    To check the working script and activate it, the following command was entered

    into the LXTerminal:

    sudo /etc/init.d/tempsense.sh start start initiating the DHT11

    software and display Python script

    The successful result is highlighted in Figure 21 Working Display.

  • 29

    Figure 21 Working Display

    To get the shell script to start when the Raspberry Pi is powered up, a final

    command was entered:

    sudo update-rc.d tempsense.sh defaults update-rc.d links the shell

    script to the directory /etc/rc.x so that the script can run at the default

    times such as the boot up of the Pi.

    3.6 Online Data Logging

    Another means of recording and monitoring the temperature and humidity is online.

    With working hardware and software in place for the DHT11 sensor and LCD display;

    the author began researching methods of transmitting this data online.

    3.6.1 PrivateEyePi

    PrivateEyePi is a projects website aimed at the Raspberry enthusiast wanting

    to build home security/automation systems and at the same time learn

    programming and electronics (PrivateEyePi, 2015). PrivateEyePi provides

    downloadable source code and an online dashboard which allows the user the

    control, monitor, and trigger alerts for their Raspberry Pi based projects.

    Figure 22 DHT22 Sensor

  • 30

    Based on an online tutorial (PrivateEyePi, 2015); the author registered an email

    address and password at www.privateeyepi.com. This project makes use of the

    DHT22 temperature and humidity sensor. The DHT22 (visible in Figure 22

    DHT22 Sensor) has the same specifications at the DHT11, except for the

    following:

    Good for 0 100% humidity readings with 2 5% accuracy

    Good for -40 to 125C temperature readings 0.5C accuracy

    No more than 0.5Hz sampling rate (once every 2 seconds)

    Body size 15.1mm x 25mm x 7.7mm

    The DHT22 sensor was purchased by the author for 8.85 from eBay

    (eBay.com, 2015) which is a higher cost that the DHT11; however, the DHT22

    sensor is more accurate and has a larger temperature and humidity range

    compared to the DHT11. The DHT22 also came on a PCB with a resistor and

    was connected to the same pins that the DHT11 was connected to previously.

    The software for the DHT11, data logging and display at this point were stopped

    to allow the use of the GPIO pins using:

    sudo /etc/init.d/tempsense.sh stop

    and the MyPiFi add-on board, LCD display, and DHT11 removed to make

    way for the DHT22.

    The PrivateEyePi dashboard prompted the author to configure a GPIO pin

    number and choose which type of sensor was being set up in this case a

    temperature gauge was selected using GPIO 4 (pin 7). Next, the PrivateEyePi

    software was installed to the Raspberry Pi by commanding in the LXTerminal:

    cd /home

    sudo wget N www.privateeyepi.com/downloads/install.sh wget

    downloads internet files from the requested website

    sudo sh install.sh sh runs the shell script install specified

    http://www.privateeyepi.com/http://www.privateeyepi.com/downloads/install.sh

  • 31

    Once installed, the username and password created on the PrivateEyePi

    dashboard was linked to the Raspberry Pi by commanding:

    cd /home

    sudo nano globals.py nano allows the user to enter a text editor

    within the LXTerminal to edit the specified script

    This information was then saved. Following this, software for the DHT22 was

    downloaded from an Adafruit Git repository to the same directory:

    cd /home

    sudo git clone git://github.com/Adafruit/Adafruit-Raspberry-Pi-Python-

    Code.git

    Last, the PrivateEyePi and DHT22 software was started by commanding:

    sudo python dht22.py

    A snapshot of the software running in the LXTerminal providing temperature

    and humidity readings (every 1 2 minutes) can be seen in Figure 23 DHT22

    Snapshot.

    Figure 23 DHT22 Snapshot

  • 32

    The author started the software at 5.29pm and left the programming running

    overnight. Figure 24 - PrivateEyePi highlights the PrivateEyePi online

    dashboard which advises if the Raspberry Pi on online, what the current relative

    humidity, temperature, date and time is; as well as providing graphed data of

    the temperature vs time.

    Figure 24 - PrivateEyePi

    As can be seen in the graphed data, the curve takes a decline from midnight

    onwards. This is when the author turned the areas central heating off as a result

    of retiring to bed. This trend lasts up until 5.42am the following day when the

    authors internet connection unintentionally disconnected the Raspberry Pi from

    the internet. Excluding the internet disconnection; this was a successful method

    of monitoring the temperature online.

    3.6.2 Twitter

    Twitter is an information network made up of 140-character messages called

    Tweets (Twitter Inc., 2014) and is one of the main social media platforms used

    to date with 288 million monthly active users and 500 million tweets sent

    everyday (Twitter Inc., 2015).

  • 33

    Based on a YouTube tutorial by SparkFun Electronics (SparkFun Electronics,

    2014); the author created a Twitter account under the Twitter handle

    @UWS_Pi (Twitter Inc., 2015) as can be seen in Figure 25 - @UWS_Pi.

    Twitter allows programmers and developers to interact with its API

    (Application Programming Interface). API is a set of programming instructions

    and standards for accessing a Web-based software application(s) (Ross, 2015).

    Figure 25 - @UWS_Pi Twitter

    On Twitters Application Manager; new applications can be created which grant

    the user API keys and access tokens to allow any authorised, developed

    applications to interact with the Twitter account created. The author created an

    application named UWS_Pi to obtain the relative codes to link a Python script

    to the Twitter account @UWS_Pi.

    The SparkFun Electronics tutorial uses a HIH6130 SparkFun Humidity and

    Temperature Sensor Breakout board to generate temperature and relative

    humidity values. The author opted to remove the DHT22 sensor, stop the

    PrivateEyePi software, and reinsert the DHT11 with the MyPiFi add-on and

    LCD display. The Pi was rebooted to automatically start-up the appropriate

    scripts.

    Using a similar Python script to the tutorial, a Python script named

    tweettempsense.py was created by the author which instead of the HIH6130

    sensor values uses the same temperature and humidity data that the

    displaytempsense.py Python script uses.

  • 34

    To test the connection to the Twitter account, the author entered the message

    Testing, testing, 1, 2, 3. into the Python script and executed the command in

    LXTerminal using:

    sudo python tweetpython.py

    Figure 26 Tweet Test highlights the successful tweet being posted to Twitter.

    Figure 26 Tweet Test

    From here, the author changed the Python Script to accommodate the date, time,

    temperature and humidity and ran the script again using the same LXTerminal

    command. One of the first readings to the Twitter account can be viewed in

    Figure 27 Twitter Temperature Tweets. Twitter has a daily limit of 1,000

    tweets per day (Twitter Inc., 2014). The author configured the Python script to

    send an updated tweet every two minutes to the Twitter account; meaning that

    daily the script would send out only 720 tweets per day.

    Figure 27 Twitter Temperature Tweets

    Similar to PrivateEyePi, the Twitter account can be accessed to obtain

    temperature and humidity readings on any device such as a laptop of mobile

    phone. By the author adding the Twitter handle @wullbertduncan the

    authors own Twitter account notifications are received every time the script

    sends a tweet to Twitter.

  • 35

    The incorporation of Twitter to the project also allowed for updated online data

    transmission. One key difference is that PrivateEyePi is only accessible to the

    owner of the configured dashboard; whereas information posted to Twitter is

    accessible to anyone.

    For example; this would prove useful for a technical department with multiple

    employees looking to monitor the temperature and humidity of a server room to

    ensure the temperature was suitable for computing operations

  • 36

    4. Testing

    This chapter analyses the performance of the temperature sensor against changes in

    temperature and humidity and analyses results obtained. All data can be viewed in Appendix 2

    Test Data.

    4.1 Cooling Test

    The purpose of this test was to analyse how the temperature and humidity sensor reacted

    to extreme reductions in temperature. The temperature and humidity were analysed

    over a period of time. The expectation was that the temperature would decrease with

    time and the humidity would potentially rise over time.

    Figure 28 Cooling Test

    The temperature and humidity were altered by using a bag of frozen ice wrapped in a

    towel placed over the DHT11 sensor; this is shown in Figure 28 Cooling Test. The

    frozen ice remained on the sensor for approximately ten minutes and then removed

    again. The log file on the Pi was then transferred to Microsoft Excel and the temperature

    and humidity values were plotted against time.

    Figure 29 Cooling Graph displays the trend for the temperature and humidity during

    the testing period. The graph provided highlights the temperature (blue curve)

    decreasing from room temperature (25C) to 1C over the course of the ten minute

    period.

    The humidity (red curve) during this time also changes at approximately the same rate

    but increases with time. As the bag of ice is removed, the temperature increases at the

    same rate until it reaches room temperature again; the humidity dropping at a similar

    but opposite rate also. This was the intended outcome of the test.

  • 37

    Figure 29 Cooling Graph

    4.2 Heating Test

    The purpose of this test was to analyse how the temperature and humidity sensor reacted

    to an extreme increase in temperature. The temperature and humidity was analysed over

    a period of time. The expectation was that the temperature would increase with time

    and the humidity would potentially decrease over time.

    Figure 30 Heating Test

    The temperature and humidity were altered by using a hairdryer set to the highest

    temperature setting blown directly to the DHT11 sensor; this is shown in Figure 30

    Heating Test. The hairdryer remained on the sensor for approximately five minutes and

    then removed again.

  • 38

    The log file on the Pi was then transferred to Excel and the temperature and humidity

    values were plotted against time. Figure 31 Heating Graph displays the trend for the

    temperature and humidity during the testing period.

    Figure 31 Heating Graph

    The graph provided highlights the temperature (blue curve) increases from room

    temperature (25C) to 60C over the course of the five minute period. Despite the range

    of the DHT11 being 0 50C it still detected temperatures above this range.

    The humidity (red curve) during this time also changes at approximately the same rate

    but decreases with time. As the hairdryer is removed, the temperature decreases at the

    same rate until it reaches room temperature again; the humidity increasing at a similar

    but opposite rate also. Excluding the reading above 50C; this was the intended

    outcome of the test.

  • 39

    5. Case Design

    The following chapter discusses the process of creating and rapid prototyping the case. The

    case was designed using Creo and then rapid prototyped using a 3D printer.

    5.1 Concept and Influence

    Research was conducted on existing cases for Raspberry Pis to generate ideas and

    concepts for a suitable case for the temperature sensor. Many cases come as part of a

    kit which are then assembled by the user. Cases such as the Adafruit transparent case

    (Figure 32 Adafruit Case ) and the Bramble case (Figure 33 Bramble LCD Case )

    proved preferable due to multiple parts with ease of assembly.

    These cases are advantageous for a device such as the Raspberry Pi as it provides quick

    and easy access into the GPIO pins and ports.

    Individual parts of the case could also potentially be changed and modified to

    incorporate new projects without having to design a completely new case.

    Figure 32 Adafruit Case (Humpries, 2012)

  • 40

    Figure 33 Bramble LCD Case (bitcrafts, 2015)

    Figure 34 Conceptual Sketch highlights a conceptual sketch of the intended case. The

    conceptual case features holes for the HDMI, audio and visual, Ethernet, and USB ports

    as well as a slot for the DHT11 sensor and LCD display. Each side of the case features

    both slots and protrusions which allow the case to merge and lock into place, similar to

    the Bramble case. The base of the conceptual unit also features holes for either screws,

    hooks, or suction cups to allow the case to be placed vertically on a wall or surface.

    Figure 34 Conceptual Sketch

  • 41

    5.2 3D Modelling

    Creo is a commercial CAD (Computer Aided Design) software package used

    extensively throughout the manufacturing and design industry. Product designers and

    manufacturers use CAD software for designing and rapid prototyping (such as 3D

    printing) to create physical scale models of products which can be used for analysis and

    production tooling.

    Figure 35 Raspberry Pi Creo Model

    Creo was used to realise a 3D model of the conceptual design. To create an accurate

    case design; the author obtained official 3D part modelling files online

    (Stackexchange.com, 2013) for the Raspberry Pi model B and uploaded them to Creo.

    The part files came preassembled on Creo but were unreferenced (Figure 35

    Raspberry Pi Creo Model).

    Next, the author measured each main component being added to the Raspberry Pi.

    These parts were:

    DHT11 temperature and humidity sensor

    GPIO pin extension

    MyPiFi add-on board

    16-pin header strip

    HD44780 16 x 2 LCD display

  • 42

    Figure 36 Component Modelling

    In the assembly mode of Creo; each measured component was then 3D modelled using

    the obtained Raspberry Pi model as a reference (an in progress snapshot evident in

    Figure 36 Component Modelling)).

    Figure 37 Component Assembly

    The complete assembly of all modelled components can be viewed in Figure 37

    Component Assembly. With all required electrical components in place, work began

    on the case design. Again, using reference modelling (an example of which visible in

    Figure 38 Reference Modelling) each part was constructed in relation to pre-existing

    geometry.

  • 43

    Figure 38 Reference Modelling

    Reference modelling allowed the author to construct the case while creating offset

    sketches of features such as the HDMI and USB ports allowing adequate space in

    the case design for the insertion of plugs and cables. An in-progress snapshot of the

    construction of the case can be seen in Figure 39 Case Modelling.

    Figure 39 Case Modelling

    The author opted to include holes at the base of the unit for four 20mm suction cups in

    the design which would allow the case to be stuck to non-porous surfaces. The UWS

    University of the West of Scotland logo was also extruded on the case using a palette

    sketch. Shelves were included in the design to support the MyPiFi add-on board and

    LCD display.

    The complete, assembled 3D model of the case, including the main electrical

    components, can be viewed in Figure 40 Case Component Assembly.

  • 44

    Figure 40 Case Component Assembly

    5.3 Part Drawings

    Dimensional, assembly, and exploded drawings of each part and can be viewed in

    Appendix 3 Drawings. All drawings were produced using key functions within Creo.

    5.4 Rapid Prototyping

    Additive Layer manufacturing (3D printing) works by laying down thin layers of

    heated material onto a platform. Either the (printing) head or platform will continuously

    be moving to deposit more material on top of each other to form the 3D object

    (University of Exeter, 2015). 3D printing is a modelling technique which can improve

    and speed up new product development.

    5.4.1 Advantages of Rapid Prototyping

    Conventional prototyping typically requires production of prototype tooling and

    physical components of exact tolerances; whereas rapid prototyping eliminates

    this and allows for the incorporation of complex shapes and surfaces typically

    proving either difficult or impossible to recreate by conventional prototyping.

    Conventional prototyping tends to involve subtractive processes such as

    milling, turning, and drilling. This means that waste occurs through cut-off

    materials or chippings as the tools used create the finished model resulting in

    higher costs due to tooling and material waste. 3D printing helps reduce costs

    of product development as it is an additive technique.

    The only machine used each time is a 3D printer and CAD software such as

    Creo there is no need to develop special tools for each new product.

  • 45

    5.4.2 3D Printing

    3D printing uses SLT (stereolithography) files constructed from 3D CAD

    software such as Creo. The 3D modelled part files for the case were individually

    exported as SLT files. STL files change the 3D modelled files and break the

    reference shape into thousands of triangles which replicate the reference model.

    The parts submitted were named:

    Top Top of the case featuring the UWS logo and space for the LCD

    display

    Bottom Bottom of the case featuring holes for suction cups

    Side 1 Featuring a hole for the HDMI port

    Side 2 Featuring holes for the USB, Ethernet ports and a shelf for the

    LCD Display

    Side 3 Featuring a hole for the micro-use power cable and shelves for

    the MyPiFi board and LCD display

    Side 4 Featuring holes for the audio and visual ports and the DHT11

    sensor

    Upon exporting; the author was prompted to choose the Chord Height and

    Angle Control which determines the shape of the


Recommended