Raspberry Pi as Internet of Things(IoT)

The Internet of Things (IoT) philosophy may be viewed as a highly dynamic and radically dispersed networked system comprised of a huge number of identifiable smart devices. These objects may communicate and interact with one another, as well as with end-users and other network entities. As the Internet of Things era begins, the usage of small, inexpensive, and flexible computer hardware that allows end-user programming becomes more prevalent. The Raspberry Pi, a fully configurable and programmable tiny computer board, is one of them discussed in this article. Although there are certain limitations, the Raspberry Pi remains a low-cost computer that has been used effectively in a wide range of IoT vision research applications despite its few shortcomings.

Introduction:

Introductory Notes The Internet of Things - IoT – may be viewed as a highly dynamic and widely dispersed networked system. For example, it is a network of linked smart objects that may communicate and interact with one another, as well as with end-users or other network entities, such as users or other entities in the network. Safety, security, comfort, convenience, and energy savings are maximised when smart devices can perceive physical phenomena and transform them into data streams, as well as when smart devices can trigger actions. These systems should:

  • allow new applications to be built on existing systems,
  • allow new systems to be deployed in parallel with existing systems,
  • allow an adequate level of interoperability so that innovative and competitive cross-domain systems and applications can be developed.
  • The IoT systems will be designed, managed, and used by multiple stakeholders, each with its own business model.
  • The above figure shows Raspberry Pi Model A (left) and Model B (right) board:
  • The Raspberry Pi’s core components are shown in the above figure.

While internet access can be achieved through an Ethernet/LAN cable or a USB dongle (WiFi connectivity), a USB connector is required [5, 6]. Figure 1 shows an example of a formalised formalised formalised formal Model A (left) and Model B (right) Raspberry Pi boards Figure 2: The Raspberry Pi's essential components The Raspberry Pi, like any other computer, is powered by an operating system. Raspbian is a fantastic Linux alternative for Raspberry Pi since it is free and open-source, keeping the platform's price cheap and making it more hackable. There are a few non-Linux OS alternatives available as well [5]. The Raspberry Pi offers a wide range of applications, which is one of its best features. The remainder of the article will discuss what allows it, as well as the performance and limits of the Raspberry Pi. The performance of the Raspberry Pi will be compared against the following IoT prototype platforms (Fig. 3): Arduino is an open-source physical computing platform that is built on a basic microcontroller board and includes a programming environment for creating software for the board (Fig. 3 a). It can accept information from a number of sensors and operate lights, motors, and other actuators to influence its environment. The Arduino programming language and the Arduino Integrated Development Environment may be used to programme the microcontroller on the hardware board (IDE). Arduino has two operating modes: stand-alone and linked to a computer via USB cable [3]. BeagleBone Black Is a single-board computer based on low-power Texas Instruments processors and the ARM architecture.

TABLE I

  • COMPARISON OF PLATFORMS’ SIZE, WEIGHT AND COST

B. Strength and Memory The suggested platforms' major objective is low power consumption in order to fulfil the multi-year application requirements. Only by combining low-power hardware components and low-duty-cycle operating approaches can ultra-low-power operation be accomplished.

As previously indicated, the Raspberry Pi requires up to 700mA to operate. The Raspberry Pi device may be powered by a variety of power sources (provided they can deliver adequate current 700mA), such as a computer USB port or powered USB hub (depending on power output), special wall warts with USB ports, mobile phone backup battery (depending on power output), cell phone solar charger, alkaline batteries (six rechargeable AA batteries and a voltage regulator). The Raspberry Pi's main power supply constraint is that no external device should use more than 100mA from any of its USB ports.

In terms of storage, the gadget should have enough memory to store the gathered data. In addition to storage capacity, programme memory should be sufficient to execute simple computations and send just the necessary data and routing information if the device is connected to a network. It is crucial to understand that the Raspberry Pi does not have a hard drive and that everything is saved on a Secure Digital (SD) Card. The minimum needed SD card capacity is 2 GB, however larger SD cards with capacities of 32 GB, 64 GB, or more are available but frequently prohibitively costly. This storage may be increased by employing devices that supply an extra hard drive through USB ports. These are referred to as USB Mass Storage (UMS) devices and can be traditional hard drives, solid-state drives (SSDs), or even tiny pocket-sized flash drives. Table II provides a comparative study of platform CPU, memory, and power.

TABLE II

  • COMPARISON OF PLATFORMS’ CPU, MEMORY AND POWER

C. Adaptability To be useful in a wide range of applications, the architecture must be adaptable and versatile. Furthermore, for economic considerations, it must make it simple to build precisely the correct mix of software and hardware components. As a result, these devices need an extraordinary level of hardware and software flexibility while being efficient [10]. The adaptability and universality of any gadget, on the other hand, are its strengths. One of the best things about the Raspberry Pi is its versatility; there is no one way to utilise it. It can, for example, be used for: broad purpose computing, capable of interfacing with other electronic boards and communicating with other computing devices using a range of various protocols such as Serial Peripheral Interface (SPI) and Inter-Integrated Circuit (I2C): o I2C – low-speed interface – Inter-Integrated Circuit (I2C) is a serial bus interface that can communicate with numerous devices using only two wires. It operates at relatively modest speeds. o Serial Peripheral Interface Bus (SPI) – Serial Peripheral Interaction Bus (SPI) is a synchronous full-duplex (two-way) serial connection. The Raspberry Pi Model B Rev 2 features an enhanced variety of connections in addition to the usual GPIO port [13]. P5 header has 8 pins (+3.3 V, +5 V, two ground pins, and four GPIO pins that can offer the second I2C protocol) and P6 header has two pins — their short-circuiting enables soft reset of BCM2835. Table III examines the expansion connections used by the Raspberry Pi and other platforms to connect to a broad range of external devices.

TABLE III

  • COMPARISON OF PLATFORMS’ EXPANSION CONNECTORS

The Ethernet connector on the Raspberry Pi serves as the primary interface for communicating with other devices. It is auto-sensing, so it may be linked to a router or directly to another computer (without the use of a crossover connection) [5, 6]. Model B features a conventional RJ45 Ethernet connector, but model A lacks one but may be linked to a wired network using a USB Ethernet adapter. The USB Ethernet adapter offers two speeds: 10 Mb/s and 100 Mb/s (Table IV). When you attach a cable to the Raspberry Pi, it will immediately get the information it needs to connect to the Internet when it loads its operating system through the Dynamic Host Configuration Protocol (DHCP). This gives the Raspberry Pi an Internet Protocol (IP) address and informs it which gateway to use to connect to the Internet (typically the IP address of router or modem). The Raspberry Pi's drawback is the absence of an inbuilt WiFi module, however, this functionality may be added via USB dongles. As a result, the Raspberry Pi may be used to create ad-hoc networks or to connect to a variety of wireless networks, including those that utilise the newest 802.11n high-speed standard [11]. Raspberry Pi can serve static webpages, but it can also produce dynamic content by utilising databases and web apps. It can also offer access to its GPIO ports via web technologies. In addition, Raspberry Pi may be used as a Sensor Web node by connecting it to a network and making it accessible to other computers.

Emerging user programming trends enable non-professional end-users to customise products to meet their unique demands. There are hundreds of products available now that allow end-user programming. Using affordable hardware and open-source software, it is feasible to programmatically manage numerous devices in such a manner that the own solution satisfies user demands. Furthermore, giving end-users with skills and the ability to mould goods to their requirements benefits both users and product creators. One of the prototype systems that allows end-user programming will be explored in this work. The Raspberry Pi computer board will be highlighted, including a comparison of its performance and limitations with current popular prototyping platforms [2]. The primary objective of this research is to identify and explain the benefits and drawbacks of the Raspberry Pi, as well as the capabilities of its use in the construction of the future generation of IoT. The remainder of this paper is arranged as follows. Section 2 contains an overview of the Raspberry Pi, its main components, and a detailed comparison with other existing IoT systems. The final section includes closing thoughts that summarise Raspberry Pi's merits and drawbacks as IoT hardware.

II. COMPARISON OF THE RASPBERRY PI WITH OTHER IoT

HARDWARE PLATFORMS

Smart items are key to the Internet of Things vision. These things, which are equipped with information and communication technology, can preserve their context, are networked together, can access Internet services, and communicate with one another and with humans [3]. Raspberry Pi is a tiny, powerful, inexpensive, hackable, and educational computer board that was released in 2012. (Fig. 1). It functions similarly to a normal PC, needing a keyboard for command entry, a display unit, and a power source. This credit card-sized computer with numerous capabilities and a price range of $25-35$ is an ideal platform for interacting with a variety of devices. The overwhelming bulk of the system's components, including its central and graphics processing units, audio and communications gear, and a 256 MB (Model A) – 512 MB (Model B) memory chip, are integrated into a single component. The Raspberry Pi board seen in Figures 1 and 2 comprises both necessary (CPU, the graphics chip, programme memory - RAM) and optional components (various interfaces and connectors for peripherals). The SD Flash memory acts as a hard drive for the Raspberry Pi CPU. The tiny Cortex-A8 core powers the device (Fig. 3 b). It is a tiny computer the size of a credit card that can run an operating system such as Linux/Android 4.0. The primary distinction between it and Arduino is that it can run a tiny operating system, thereby transforming it into a minicomputer capable of running applications on various operating systems. BeagleBone is intended to operate at a much higher level and has far greater computing capability than Arduino.

Phidgets are a collection of “plug and play” building pieces for bridging the physical and virtual worlds using low-cost USB sensing and control from a PC. Phidgets contain USB-based hardware boards for input (temperature, movement, light intensity, RFID tags, switches, and so on) and output actuators (servo motors, LED indicators, LCD text displays, and so on) (Fig. 3 d). Because of its design and API, programmers can discover, observe, and control all Phidgets linked to a single computer. All of the needed software components are packaged as an ActiveX COM Component. Each Phidget component necessitates the usage of a corresponding visual component, which provides a visual on-screen interface for interactive end-user control. The system includes a broad API library and may be used with a wide range of applications, including other toolkits in some situations. Using Phidgets, programmers may quickly create physical interfaces without requiring an extensive understanding of electrical design difficulties.

Udoo is a small PC with an integrated Arduino-compatible board that can run both Android and Linux. It is an extremely capable prototype board for software development and design. Udoo incorporates a microcomputer with the most popular communication interfaces (Ethernet, WiFi, USB, HDMI, SATA, digital and analogue input/output) as well as a microcontroller with a standard pinout for rapid prototyping applications. As a result, Udoo is open hardware, low-cost platform outfitted with an ARM i.MX6 Freescale CPU and an Arduino Due compatible portion based on the ATMEL SAM3X ARM processor. The creators of Udoo say that the board will have the processing power of four Raspberry Pis. Udoo's retail lineup consists of three versions, all of which share the majority of features and differ mainly in connection and the i.MX6 CPU utilised [9]: Udoo Quad, Udoo Dual, and Udoo Dual Basic.

 Introduction to C++

Hello friends, I hope you all are doing great. In today's tutorial, I am going to give you a detailed introduction to the C++ Programming language. In cross-platform programming languages, C++ is the most popular that can be used to work on low and high-level applications. Bjarne Stroustrup was the founder of C++. He modified C language to develop C++ language. Control over system resources and memory can be attained by using C++. In 2011, 2014, and 2017 it was modified to C++11, C++14, and C++17. C++ is a middle-level language. It is advantageous to both programming languages low-level (drivers, kernels) and higher-level applications (games, GUI, desktop apps etc.).

Uses of C++

C++ is one of the world's most famous programming languages. It is used in today's OS, embedded systems and GUIs. It provides a clear structure to programs, permits codes to be reused and lowering development costs as its an object-oriented language. Since it is portable and can be used to create applications that can be used on multiple platforms. It is very easy to learn. As it is close to C# and Java, so switching to C++ or vice versa is very simple.

It is used in

  • Operating systems e.g. Linux-based OS 
  • Browsers like UC browser, chrome, opera and firefox.
  • Games and graphics e.g. Photoshop
  • Clouds like Dropbox
  • Database engines like reedit

Features of C++

Rich library support:

  • It is a simple language as programs can be split into logical units and parts. It has rich library support and many data types.

Platform Dependent and Machine Independent:

  •  It is machine-independent but platform-dependent. It does not run on windows but is executable on Linux.

Middle-level language:

  • It is a middle-level language as we can do both low-level programmings(drivers, kernels, networking etc.) and build large-scale user applications (Media Players, Photoshop, Game Engines etc.) as a high-level language.

3rd party libraries:

  • C++ has rich library support as well as 3rd party libraries (e.g. Boost libraries) for easy, smart and rapid development.

Fast execution:

  • For C++ speed of execution is very fast because it is compiled and highly procedural language.
  • Garbage-collection, dynamic typing etc. slow the execution of the program overall. Since there is no additional processing in C++ so it is fast than others.

Provides direct Memory-Access:

  • It provides pointer support to manipulate storage addresses. This helps in low-level programming ( indirect control over memory addresses).

Object-Oriented language:

  • It is better than C with respect to object orientation that helps it to maintain extensible programs so large-scale applications can be built easily.
  • Its friends and virtual features violate some important rules rendering it a completely object-oriented language.

Amazing facts of C++:

Some interesting facts about C++ are listed below

  • C++ name tells us that C language modified with ++ incremental operator is C++ language
  • The most famous language C ++ is used in commercial software.
  • Four primary features of OOP are supported by C++
    1. Inheritance
    2. Encapsulation
    3. Abstraction, and
    4. Polymorphism
  • From Simula67 Programming language C++ gained the features of OOP.
  • For a C++ program to execute(at least main() function) , a function is the least requirement.

Basic concepts of C++ :

Basic concepts like syntax, variables, loop type etc will be discussed here.

Syntax of C++:

Here is the C++ basic program

#include <iostream.h> using namespace std; int main() { cout << "Hi this is C++"; }
  • iostream is a header file and provides us with input & output streams.
  • namesspace std tells the compiler to use standard namespace. It can be used in 2 ways.
  • the return type of main () is int.
  • count << is used to print anything on the screen.

Comments in C++:

  • // is used to add single comment. For multiple comments /*multiple comments*/ is used

Data types in C++:

There are built-in as well as user-defined data types in C++.

  • In C++, classes are user-defined data types.
  • Built-in data types are int, float, double etc.
  • Derived data types are Array, function, pointer and reference.

C++ Program to get a sum of 3 numbers

//Program to receive three integer numbers and display their sum #include <iostream> using namespace std; int main() {       int num1, num2, num3, Sum;       //variables num1, num2, num3 and sum are declared as integers cout << "\n Enter Number 1: "; cin >> num1; cout << "\n Enter Number 2: "; cin >> num2; cout)<< “\n Enter Number 3: “; cin>>num3; Sum = num1 + num2 + num3; cout << "\n The sum of " << num1 << num2 “ and " << num3 << " is " << Sum; }

Modifiers in C++

In C++, special words(called modifiers) are used to modify built-in data types. There are four main data type modifiers in C++, they are:

  • Long
  • Short
  • Signed    and
  • unsigned

These modifiers are with built-in data types to make them more precise and for expanding their range.

  • long and short modify the maximum and minimum values that a data type can hold.
  • Signed types include both +ive and _ive numbers as is the default type.
  • Unsigned, numbers do not have any sign, so they are always positive.

Variables in C++ :

  • Variable is used in C++ to store any value, which can be changed in the program.
  • Variable is declared in many ways each with different memory location and functioning.
  • It is the name of the memory location allocated by the compiler to the variable.

Variables are divided into two main types,

  • Global Variables
  • Local variables

Global variables

Global variables are those which declared only a single time and used again and again. They are declared outside the main() function. If only declared then assigned different values at different times in program lifetime. But when they are declared and initialized at the same time then they can be assigned any value at any point in the program.

For example: Only declared, not initialized

include <iostream> using namespace std; int x;                // Global variable declared int main() { y=10;                 // Initialized once cout <<"first value of y = "<< y; y=20;                 // Initialized again cout <<"Initialized again with value = "<< y; }

Local Variables

  • Local variables exist only between the curly braces, in which they are declared.
  • Outside the curly braces, they are unavailable and lead to a compile-time error.
Example :
include <iostream> using namespace std; int main() { int j=10; if(j<20)        // if condition scope starts { int m=100;   // Local variable declared and initialized }              // if condition scope ends cout << m;      // Compile time error, m not available here }

C++ Program to find the curved surface area of a cylinder (CSA) (CSA = 2 pi r * h)

#include <iostream> using namespace std; int main() { float pi = 3.14, Radius, Height, CSA; cout << "\n Curved Surface Area of a cylinder"; cout << "\n Enter radius (in cm): "; cin >> Radius; cout << "\n Enter height (in cm): "; cin >> Height; CSA = (2*pi*Radius)*Height;       system("cls"); cout << "\n radius: " << Radius <<"cm"; cout << "\n height: " << Height << "cm"; cout << "\n Curved Surface Area of a Cylinder is " << CSA <<" sq. cm."; }

Output:

  • Curved Surface Area of a cylinder
  • Enter radius (in cm): 7
  • Enter height (in cm): 20
  • radius: 7cm
  • height: 20cm
  • The curved Surface Area of a Cylinder is 879.2 sq. cm.

Operators in C++ :

  • Operators take one or more arguments and generate a new value.
  • For example : addition (+), subtraction (-), multiplication (*) etc, are all operators.
  • These are used to perform different operations on variables and constants.

Errors in C++:

There are three types of errors that occur in C++ programming

Syntax Error:

  • The syntax is a set of grammatical rules to make a program. Every programming language has unique grammatical rules.
  • when grammatical rules of C++ are violated Syntax Errors occur.
  • For example: if you type as follows, C++ will throw an error.

 cout << “Hi welcome to C++”

  • As per the grammatical rules of C++, there should be a semicolon at the end of the statement. But, this statement does not end with a semicolon so Syntax Error occurs.

Logical Error:

It may be happened by the wrong use of variable or operator or order of execution etc. This means that the program is grammatically correct, but it contains some logical errors. So, “Logic Error” is also called Semantic error.

Run time error:

  • During the execution of the program when some illegal action takes place, run time error occurs
  • For example, if a program tries to open a file that does not exist then it will result in a run-time error.

Control Statements in C++:

  • The sequence of flow of instructions is changed by the use of control Statements.

Selection statement

  • Statements can run sequentially, selectively or iteratively in a program. Sequence, selection and iteration processes are handled by every programming language.
  • If the statements are executed sequentially then the flow is called a sequential flow. In some situations, if the statements alter the flow of execution then this flow is called a control flow.

Sequence statement

  • The sequential statement is executed one after the another only once from top to bottom.
  • These statements do not alter the flow of execution and are called sequential flow statements. These statements always end with a semicolon (;).

Selection statement

  • When a condition is provided then selection statements are used.
  • In case when the condition is true then a true block (a set of statements) is executed otherwise a false block is commanded to execute.
  • This is also called a decision statement because it helps in making decisions for the set of statements to be executed.
  • Selection statements are if, if-else and nested if statements.

if statement

  • The general syntax of the if statement is:
if (expression) true-block; statement-x;
  • and flow chart for if statement is

 if-else statement

  • The syntax of the if-else statement is given below:
if ( expression) {       True-block; } else {       False-block; }
  • And the flow chart for if-else statement is:

C++ program to find either number is Even or Odd

#include <iostream> using namespace std; int main() { int Num, rem; cout<< "\n enter a number: "; cin>>Num; rem = Num % 2; if (rem==0) cout<< "\n The given number" <<Num<< " is Even"; else cout<< "\n The given number "<<Num<< " is Odd"; return 0; }

Output

  • Enter number: 12
  • The given number 12 is Even

Nested if

It has three forms
  • If nested inside if part
  • If nested inside else part
  • If nested inside both if part and else part

Iteration statement

  • The iteration statement is a set of statements that are executed again and again depends upon conditions.
  • If a condition evaluates to true, the set of statements (only true) is executed again and again.
  • As soon as the condition seems to be false, the repetition stops. This is also known as looping statement 
  • The set of statements that are executed repeatedly is called the body of the loop.
  • The condition on which exits from the loop is called exit-condition or test-condition.
  • There are 3 kinds of loops in C++
    1. For loop
    2. While loop
    3. Do while loop

for loop

  • The for loop is the easiest loop which allows code to be executed again and again.
  • The general syntax is:
for (initialization(s); test expression; update expression(s)) {      statement 1;         statement 2;       …………. }

C++ program to sum from 1 to 5 using for loop

#include <iostream> using namespace std; int main () { int i,Sum=0; for(i=1; i<=5;i++) { sum=sum+i; } cout<<"The sum of 1 to 5 is "<<Sum; return 0; }

Output

  • The sum of 1 to 5 is 15

While loop

  • It allows the loop statements to be executed as long as the condition is true.
  • The while loop syntax is:
while ( test expression ) {       body of the loop; }
  • Flow chart for while loop is given below

 C++ program to sum from 1 to 6 using while loop

#include <iostream> using namespace std; int main () { int i=1,SUM=0; while(i<=6) { SUM=SUM+i; i++; } cout<<"The sum of 1 to 6 is "<<SUM; return 0; }

Output

  • The sum of 1 to 6 is 21

do-while loop

  • The do-while loop is used as an exit-controlled loop. In a do-while loop, after executing the body of the loop, the condition is evaluated.
  • The do-while loop syntax is:
do {       body of the loop; } while(condition);
  • The flow chart of the do-while loop is shown below

 Examples of C++ programs:

1. C++ Program to find the Total marks of three subjects

#include <iostream> using namespace std; int main() { Int n1, n2 , n3, Sum; cout << "\n Enter Mark 1: "; cin >> n1; cout << "\n Enter Mark 2: "; cin >> n2; cout << "\n Enter Mark 3: "; cin >> n3; Sum = n1 + n2 + n3; cout << "\n The sum = " << Sum; }

2. C++ program to find the Area of a Circle

#include <iostream> using namespace std; int main() { int Radius; float Area; cout << "\n Enter Radius: "; cin >> Radius; Area = 3.14 * Radius * Radius; cout << "\n The area of circle = " << Area; }
So, that was all for today. In the next tutorial, we are going to discuss the Data Types in C++ in detail. If you have any questions regarding this tutorial, ask in the comments. Thanks for reading !!!
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir